Sync Rime Dictionaries #106
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Sync Rime Dictionaries | |
| on: | |
| schedule: | |
| # 每天凌晨 21:00 UTC (北京时间 05:00) | |
| - cron: '0 21 * * *' | |
| workflow_dispatch: # 允许手动触发 | |
| permissions: | |
| contents: write | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout this repo | |
| uses: actions/checkout@v4 | |
| - name: Set date | |
| id: date | |
| run: echo "DATE=$(date +%Y%m%d)" >> $GITHUB_ENV | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.x' | |
| - name: Clone rime-ice | |
| run: | | |
| git clone --depth 1 https://github.com/iDvel/rime-ice.git upstream/rime-ice | |
| - name: Download wanxiang grammar | |
| run: | | |
| mkdir -p upstream/wanxiang | |
| curl -L -o upstream/wanxiang/wanxiang-lts-zh-hans.gram \ | |
| "https://github.com/amzxyz/RIME-LMDG/releases/download/LTS/wanxiang-lts-zh-hans.gram" | |
| curl -s "https://api.github.com/repos/amzxyz/RIME-LMDG/releases/tags/LTS" | \ | |
| python3 -c "import sys,json; data=json.load(sys.stdin); \ | |
| assets=[a for a in data['assets'] if a['name']=='wanxiang-lts-zh-hans.gram']; \ | |
| print(assets[0]['updated_at'].split('T')[0].replace('-','') if assets else '')" \ | |
| > upstream/wanxiang/version.txt | |
| - name: Download extra dictionaries | |
| run: | | |
| python3 scripts/update_dicts.py | |
| - name: Merge files | |
| run: | | |
| chmod +x scripts/merge.sh | |
| bash scripts/merge.sh | |
| - name: Create release package | |
| run: | | |
| cd output | |
| zip -r ../fuyaorime-${{ env.DATE }}.zip . | |
| - name: Generate release notes | |
| run: | | |
| echo "自动同步的 Rime 配置包" > release_notes.md | |
| echo "" >> release_notes.md | |
| HAS_CHANGES=false | |
| RIME_ICE_HASH_FILE="scripts/.rime_ice_hash" | |
| WANXIANG_HASH_FILE="scripts/.wanxiang_hash" | |
| echo "## 上游更新" >> release_notes.md | |
| echo "" >> release_notes.md | |
| # 雾凇拼音对比 | |
| echo "### 雾凇拼音 (rime-ice)" >> release_notes.md | |
| cd upstream/rime-ice | |
| CURRENT_HASH=$(git rev-parse --short HEAD) | |
| cd ../.. | |
| if [ -f "$RIME_ICE_HASH_FILE" ]; then | |
| PREV_HASH=$(cat "$RIME_ICE_HASH_FILE") | |
| if [ "$CURRENT_HASH" != "$PREV_HASH" ]; then | |
| CHANGES=$(cd upstream/rime-ice && git log -1 --format="- [%h](https://github.com/iDvel/rime-ice/commit/%H) %s (%cd)" --date=short 2>/dev/null) | |
| echo "$CHANGES" >> release_notes.md | |
| HAS_CHANGES=true | |
| else | |
| echo "- 无更新" >> release_notes.md | |
| fi | |
| fi | |
| echo "$CURRENT_HASH" > "$RIME_ICE_HASH_FILE" | |
| # 语言模型版本 | |
| echo "### 语言模型" >> release_notes.md | |
| if [ -f upstream/wanxiang/version.txt ]; then | |
| gram_version=$(cat upstream/wanxiang/version.txt) | |
| echo "- 万象语言模型版本: $gram_version" >> release_notes.md | |
| fi | |
| echo "" >> release_notes.md | |
| # 获取自定义词库更新信息 | |
| echo "## 自定义词库更新" >> release_notes.md | |
| echo "" >> release_notes.md | |
| # 检查各个自定义词库是否有更新 | |
| CUSTOM_DICTS=("zhwiki" "web-slang" "zhwikisource" "zhwiktionary" "moegirl" "cn_places" "popular_new_words") | |
| for dict_name in "${CUSTOM_DICTS[@]}"; do | |
| dict_file="custom_dicts/${dict_name}.dict.yaml" | |
| if [ -f "$dict_file" ]; then | |
| version=$(grep -oP 'version:\s*"?\K[^"\s]+' "$dict_file" 2>/dev/null || echo "未知") | |
| echo "- ${dict_name} (版本: ${version})" >> release_notes.md | |
| HAS_CHANGES=true | |
| fi | |
| done | |
| echo "" >> release_notes.md | |
| # 如果没有任何更新,显示例行更新 | |
| if [ "$HAS_CHANGES" = false ]; then | |
| echo "## 更新说明" >> release_notes.md | |
| echo "" >> release_notes.md | |
| echo "- 例行更新,上游无变更" >> release_notes.md | |
| echo "" >> release_notes.md | |
| fi | |
| # 包含内容说明 | |
| echo "## 包含内容" >> release_notes.md | |
| echo "- 雾凇拼音最新词库" >> release_notes.md | |
| echo "- 万象拼音语言模型" >> release_notes.md | |
| echo "- 自定义词库(维基百科、萌娘百科等)" >> release_notes.md | |
| echo "- 自定义皮肤和配置" >> release_notes.md | |
| echo "" >> release_notes.md | |
| # 使用方法 | |
| echo "## 使用方法" >> release_notes.md | |
| echo "1. 下载 \`fuyaorime-*.zip\`" >> release_notes.md | |
| echo "2. 解压到 Rime 配置目录" >> release_notes.md | |
| echo "3. 重新部署" >> release_notes.md | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| if: github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/main' | |
| with: | |
| tag_name: v${{ env.DATE }} | |
| name: FuyaoRime ${{ env.DATE }} | |
| body_path: release_notes.md | |
| files: fuyaorime-${{ env.DATE }}.zip | |
| draft: false | |
| prerelease: false | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Update hash files | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add scripts/.rime_ice_hash | |
| git diff --cached --quiet || git commit -m "chore: 更新上游仓库 hash 记录" | |
| git push |