1- name : Auto I18N
1+ name : Auto I18N Weekly
22
33env :
44 TRANSLATION_API_KEY : ${{ secrets.TRANSLATE_API_KEY }}
77 TRANSLATION_BASE_LOCALE : ${{ vars.AUTO_I18N_BASE_LOCALE || 'en-us'}}
88
99on :
10- pull_request :
11- types : [opened, synchronize, reopened]
10+ schedule :
11+ # Runs at 00:00 UTC every Sunday.
12+ # This corresponds to 08:00 AM UTC+8 (Beijing time) every Sunday.
13+ - cron : " 0 0 * * 0"
1214 workflow_dispatch :
1315
1416jobs :
1517 auto-i18n :
1618 runs-on : ubuntu-latest
17- if : github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.full_name == 'CherryHQ/cherry-studio'
1819 name : Auto I18N
1920 permissions :
2021 contents : write
@@ -24,45 +25,69 @@ jobs:
2425 - name : 🐈⬛ Checkout
2526 uses : actions/checkout@v5
2627 with :
27- ref : ${{ github.event.pull_request.head.ref }}
28+ fetch-depth : 0
2829
2930 - name : 📦 Setting Node.js
30- uses : actions/setup-node@v5
31+ uses : actions/setup-node@v6
3132 with :
32- node-version : 20
33- package-manager-cache : false
33+ node-version : 22
3434
35- - name : 📦 Install dependencies in isolated directory
36- run : |
37- # 在临时目录安装依赖
38- mkdir -p /tmp/translation-deps
39- cd /tmp/translation-deps
40- echo '{"dependencies": {"@cherrystudio/openai": "^6.5.0", "cli-progress": "^3.12.0", "tsx": "^4.20.3", "@biomejs/biome": "2.2.4"}}' > package.json
41- npm install --no-package-lock
35+ - name : 📦 Install corepack
36+ run :
corepack enable && corepack prepare [email protected] --activate 37+
38+ - name : 📂 Get yarn cache directory path
39+ id : yarn-cache-dir-path
40+ run : echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
4241
43- # 设置 NODE_PATH 让项目能找到这些依赖
44- echo "NODE_PATH=/tmp/translation-deps/node_modules" >> $GITHUB_ENV
42+ - name : 💾 Cache yarn dependencies
43+ uses : actions/cache@v4
44+ with :
45+ path : |
46+ ${{ steps.yarn-cache-dir-path.outputs.dir }}
47+ node_modules
48+ key : ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
49+ restore-keys : |
50+ ${{ runner.os }}-yarn-
51+
52+ - name : 📦 Install dependencies
53+ run : |
54+ yarn install
4555
4656 - name : 🏃♀️ Translate
47- run : npx tsx scripts/ sync- i18n.ts && npx tsx scripts/ auto-translate- i18n.ts
57+ run : yarn sync: i18n && yarn auto: i18n
4858
4959 - name : 🔍 Format
50- run : cd /tmp/translation-deps && npx biome format --config-path /home/runner/work/cherry-studio/cherry-studio/biome.jsonc --write /home/runner/work/cherry-studio/cherry-studio/src/renderer/src/i18n/
60+ run : yarn format
5161
52- - name : 🔄 Commit changes
62+ - name : 🔍 Check for changes
63+ id : git_status
5364 run : |
54- git config --local user.email "[email protected] " 55- git config --local user.name "GitHub Action"
56- git add .
65+ # Check if there are any uncommitted changes
5766 git reset -- package.json yarn.lock # 不提交 package.json 和 yarn.lock 的更改
58- if git diff --cached --quiet; then
59- echo "No changes to commit"
60- else
61- git commit -m "fix(i18n): Auto update translations for PR #${{ github.event.pull_request.number }}"
62- fi
63-
64- - name : 🚀 Push changes
65- uses : ad-m/github-push-action@master
67+ git diff --exit-code --quiet || echo "::set-output name=has_changes::true"
68+ git status --porcelain
69+
70+ - name : 📅 Set current date for PR title
71+ id : set_date
72+ run : echo "CURRENT_DATE=$(date +'%b %d, %Y')" >> $GITHUB_ENV # e.g., "Jun 06, 2024"
73+
74+ - name : 🚀 Create Pull Request if changes exist
75+ if : steps.git_status.outputs.has_changes == 'true'
76+ uses : peter-evans/create-pull-request@v6
6677 with :
67- github_token : ${{ secrets.GITHUB_TOKEN }}
68- branch : ${{ github.event.pull_request.head.ref }}
78+ token : ${{ secrets.GITHUB_TOKEN }} # Use the built-in GITHUB_TOKEN for bot actions
79+ commit-message : " feat(bot): Weekly automated script run"
80+ title : " 🤖 Weekly Automated Update: ${{ env.CURRENT_DATE }}"
81+ body : |
82+ This PR includes changes generated by the weekly auto i18n.
83+ Review the changes before merging.
84+
85+ ---
86+ _Generated by the automated weekly workflow_
87+ branch : " auto-i18n-weekly-${{ github.run_id }}" # Unique branch name
88+ base : " main" # Or 'develop', set your base branch
89+ delete-branch : true # Delete the branch after merging or closing the PR
90+
91+ - name : 📢 Notify if no changes
92+ if : steps.git_status.outputs.has_changes != 'true'
93+ run : echo "Bot script ran, but no changes were detected. No PR created."
0 commit comments