-
Notifications
You must be signed in to change notification settings - Fork 370
65 lines (57 loc) · 2.74 KB
/
locals(greasyfork).js_update.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
name: main(greasyfork).user.js and locals(greasyfork).js update
on:
schedule:
# 每周四的UTC时间16点(北京时间周五凌晨0点)
- cron: "0 16 * * 4"
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:
fetch-depth: 0
- name: Sync update locals(greasyfork).js
run: |
# 获得最近以`main.user.js Update to version`开头的提交的引用
ref=$(git log --grep="^main.user.js Update to" -n 1 --pretty=format:"%H")
# 获取该提交中`locals.js`的文件时间, 并设置环境变量
locals_js_time=$(git log -1 --format=%at $ref -- locals.js)
echo "locals_js_time=$locals_js_time" >> $GITHUB_ENV
# 从该提交中提取文件`locals.js`并覆写到本地文件`locals(greasyfork).js`
git show $ref:locals.js > "locals(greasyfork).js"
git diff --quiet --exit-code "locals(greasyfork).js" || \
echo "LOCALS_JS_IS_CHANGED=true" >> $GITHUB_ENV
- name: Update version in main(greasyfork).user.js
if: |
${{ env.LOCALS_JS_IS_CHANGED == 'true' }}
run: |
# 使用`locals.js`的文件日期为词库版本号
locals_js_date=$(TZ='Asia/Shanghai' date -d "@${{ env.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/" "main(greasyfork).user.js"
sed -i -E "s/(@require.+435207-github-.+.js\?v[0-9]+\.[0-9]+\.[0-9]+)(-[0-9]{4}-[0-9]{2}-[0-9]{2})?/\1-$locals_js_date/" "main(greasyfork).user.js"
git diff --quiet --exit-code "main(greasyfork).user.js" || \
echo "MAIN_USER_JS_IS_CHANGED=true" >> $GITHUB_ENV
- name: Commit and push locals(greasyfork).js and main(greasyfork).user.js
if: ${{ env.LOCALS_JS_IS_CHANGED == 'true' &&
env.MAIN_USER_JS_IS_CHANGED == 'true' }}
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' "main(greasyfork).user.js")
bash script/ci_commit_with_signature.sh \
-R "${{ github.repository }}" \
-B "${{ github.ref_name }}" \
-P "${{ github.sha }}" \
-F "locals(greasyfork).js, main(greasyfork).user.js" \
-h "main(greasyfork).user.js Update to $version"