Skip to content

Commit

Permalink
release脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
gaboolic committed Jul 20, 2024
1 parent c167709 commit 4d2d9dd
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 63 deletions.
85 changes: 23 additions & 62 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,69 +1,30 @@
name: Pack and Release
name: release

on:
push:
branches:
- main
tags:
- '[0-9]+.*'
paths:
- '**/**'
- '!**.md'
- '!**.gitignore'
- '!others/**'
- '!.github/**'
workflow_dispatch:
release:
types: [published]

jobs:
Release:
generate-txt:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Pack dicts
run: |
mkdir dist
echo "Pack all ..."
find . -maxdepth 1 -name "*.lua" -o -name "*.yaml" -o -name "*.txt" | zip dist/full.zip -@
zip -r dist/full.zip cn_dicts en_dicts lua opencc LICENSE
echo "Pack dicts ..."
zip -r dist/all_dicts.zip cn_dicts en_dicts opencc radical_pinyin.dict.yaml
echo "Pack cn_dicts ..."
zip -r dist/cn_dicts.zip cn_dicts
echo "Pack en_dicts ..."
zip -r dist/en_dicts.zip en_dicts
echo "Pack opencc ..."
zip -r dist/opencc.zip opencc
- name: Create nightly release
if: ${{ github.ref == 'refs/heads/main' }}
uses: 'softprops/action-gh-release@v2'
with:
body: |
## 说明
这里是每次提交后自动打包的版本,包含最新的功能和词库
- `full.zip` : 包含所有词典和方案文件
- `cn_dicts.zip`:中文词库
- `en_dicts.zip`:英文词库
- `opencc.zip`:opencc 词库(emoji 等)
- `all_dicts.zip`:以上三个词库的整合
tag_name: nightly
name: "nightly build"
make_latest: true
files: |
dist/*
- name: Create stable release
if: startsWith(github.ref, 'refs/tags/')
uses: 'softprops/action-gh-release@v2'
with:
body_path: ${{ github.workspace }}/others/CHANGELOG.md
draft: true
make_latest: true
files: |
dist/*
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10' # 你可以根据需要选择 Python 版本

- name: Generate dict_for_fcitx5.txt from YAML
run: |
python others/program/release/generate_dict_for_fcitx5.py # 运行你的 Python 脚本
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
with:
asset_path: ./dict_for_fcitx5.txt
asset_name: dict_for_fcitx5.txt
asset_content_type: text/plain
release_id: ${{ github.event.release.id }}
5 changes: 4 additions & 1 deletion others/program/pinyin/test_pinyin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@
print(pinyin('禁着点',heteronym=True))


print(pinyin('鸂鶒',heteronym=True))
print(pinyin('鸂鶒',heteronym=True))
print(pinyin('寻思',heteronym=True))
print(lazy_pinyin('寻思'))
print(pinyin('寻'))
60 changes: 60 additions & 0 deletions others/program/release/generate_dict_for_fcitx5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import os
import string


word_map = {}
file_list = ['8105.dict.yaml','41448.dict.yaml','base.dict.yaml','ext.dict.yaml']
for file in file_list:
file_name = os.path.join('cn_dicts', file)
with open(file_name, 'r') as file:
# 逐行读取文件内容
for line in file:
# 去除行尾的换行符
line = line.rstrip()
if line.startswith('#') or '\t' not in line:
continue
params = line.split("\t")
word = params[0]
pinyin = params[1]
pinyin = pinyin.replace(" ","'")
if len(params) == 3:
freq = params[2]
else:
continue

key = word +" " + pinyin
if key in word_map:
continue

word_map[key] = freq

# 使用 os 模块中的 listdir 函数列出指定文件夹中的所有文件和子目录
file_list = os.listdir("cn_dicts_cell")
for file in file_list:
file_name = os.path.join('cn_dicts_cell', file)
with open(file_name, 'r') as file:
# 逐行读取文件内容
for line in file:
# 去除行尾的换行符
line = line.rstrip()
if line.startswith('#') or '\t' not in line:
continue
params = line.split("\t")
word = params[0]
pinyin = params[1]
pinyin = pinyin.replace(" ","'")
if len(params) == 3:
freq = params[2]
else:
continue

key = word +" " + pinyin
if key in word_map:
continue

word_map[key] = freq

write_file_name = os.path.join('', "dict_for_fcitx5.txt")
write_file = open(write_file_name, 'w')
for word in word_map:
write_file.write(word+" "+word_map[word]+"\n")

0 comments on commit 4d2d9dd

Please sign in to comment.