Skip to content

main.user.js version update & sync zh-TW #6

main.user.js version update & sync zh-TW

main.user.js version update & sync zh-TW #6

name: main.user.js version update & sync zh-TW
on:
schedule:
# 每周日的UTC时间16点(北京时间周一凌晨0点)
- cron: "0 16 * * 0"
workflow_dispatch:
jobs:
update_version:
runs-on: ubuntu-latest
environment: github-pages
steps:
- name: Generate a token
id: generate_token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: Test-Sync-zh-TW
- name: Checkout 'zh-TW' branch
uses: actions/checkout@v4
with:
ref: zh-TW
path: zh-TW
- name: Install OpenCC
run: sudo apt-get install -y opencc
- name: Sync zh-TW/locals.js
run: |
opencc -i locals.js -o zh-TW/locals.js -c s2tw.json
cat zh-TW/locals.js
- name: Update version in zh-TW/main.user.js
run: |
# locals_js_date=${{ env.LOCALS_JS_DATE }}
# 获取最后一次提交中`locals.js`的文件时间
locals_js_time=$(git log -1 --format=%at -- locals.js)
# 使用`locals.js`的文件日期为词库版本号
locals_js_date=$(TZ='Asia/Shanghai' date -d "@$locals_js_time" +'%Y-%m-%d')
sed -i -E "s/(@version\s*[0-9]+\.[0-9]+\.[0-9]+)(-[0-9]{4}-[0-9]{2}-[0-9]{2})?/\
\1-$locals_js_date/" zh-TW/main.user.js
sed -i -E "s/(@require.+locals.js\?v[0-9]+\.[0-9]+\.[0-9]+)(-[0-9]{4}-[0-9]{2}-[0-9]{2})?/\1-$locals_js_date/" zh-TW/main.user.js
- name: Commit and push zh-TW/main.user.js, zh-TW/locals.js
env:
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
APP_SLUG: ${{ steps.generate_token.outputs.app-slug }}
run: |
version=$(sed -n -E 's/^\/\/ @version\s+(.+)/\1/p' zh-TW/main.user.js)
sha=$(git rev-parse zh-TW)
echo "Ref SHA: $sha"
bash script/ci_commit_with_signature.sh \
-R "${{ github.repository }}" \
-B "zh-TW" \
-P "$sha" \
-F "zh-TW/main.user.js", "zh-TW/locals.js" \
-h "zh-TW Sync to $version"