-
Notifications
You must be signed in to change notification settings - Fork 412
59 lines (52 loc) · 2.3 KB
/
main.user.js_version_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
name: main.user.js version update
on:
schedule:
# 每周一的UTC时间16点(北京时间凌晨0点)
- cron: "0 16 * * 0"
workflow_dispatch:
jobs:
update_version:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Test if locals.js has changed since the last release
run: |
# 最近提交是否存在tag
if [ ! "$(git tag --contains ${{ github.sha }})" ]; then
# 获得最近以`main.user.js Update to version`开头的提交的sha和时间戳
release_commit_sha=$(git log --grep="^main.user.js Update to version" -n 1 --pretty=format:"%H")
release_commit_timestamp=$(git show -s --format=%ct $release_commit_sha)
# 最近的tag对应提交的sha和时间戳
latest_tag_commit_sha=$(git rev-list --tags --max-count=1)
latest_tag_commit_timestamp=$(git show -s --format=%ct $latest_tag_commit_sha)
if [ $release_commit_timestamp -gt $latest_tag_commit_timestamp ]; then
ref=$release_commit_sha
else
ref=$latest_tag_commit_sha
fi
git diff --quiet --exit-code $ref locals.js || \
echo "LOCALS_JS_IS_CHANGED=true" >> $GITHUB_ENV
fi
- name: Update version in main.user.js
if: |
${{ env.LOCALS_JS_IS_CHANGED == 'true' }}
run: |
sed -i -E "s/(@version\s*[0-9]+\.[0-9]+\.[0-9]+)(-[0-9]{4}-[0-9]{2}-[0-9]{2})?/\
\1-$(TZ='Asia/Shanghai' date +'%Y-%m-%d')/" main.user.js
git diff --quiet --exit-code main.user.js || \
echo "MAIN_USER_JS_IS_CHANGED=true" >> $GITHUB_ENV
- name: Commit and push main.user.js
if: ${{ env.LOCALS_JS_IS_CHANGED == 'true' &&
env.MAIN_USER_JS_IS_CHANGED == 'true' }}
run: |
bash script/ci_commit_with_signature.sh \
-T "${{ secrets.CI_GITHUB_TOKEN }}" \
-R "${{ github.repository }}" \
-B "${{ github.ref_name }}" \
-P "${{ github.sha }}" \
-F "main.user.js" \
-h "main.user.js Update to version $(TZ='Asia/Shanghai' date +'%Y-%m-%d')" \
-b "Signed-off-by: 沙漠之子 <[email protected]>"