-
Notifications
You must be signed in to change notification settings - Fork 372
49 lines (42 loc) · 1.77 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
name: main.user.js version update
on:
schedule:
- cron: "0 0 * * 1"
workflow_dispatch:
jobs:
update_version:
if: ${{ !startsWith(github.event.client_payload.head_commit.message, 'main.user.js: Update to version') }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get latest tag commit SHA
id: latest_tag_commit_sha
run: echo "::set-output name=sha::$(git rev-list --tags --max-count=1)"
- name: Get current commit SHA
id: current_commit_sha
run: echo "::set-output name=sha::$(git rev-parse HEAD)"
- name: Check if commit is ahead of latest tag
id: check_commit_ahead
run: |
latest_tag_commit_sha=${{ steps.latest_tag_commit_sha.outputs.sha }}
current_commit_sha=${{ steps.current_commit_sha.outputs.sha }}
if [ "$current_commit_sha" != "$latest_tag_commit_sha" ]; then
echo "::set-output name=ahead::true"
else
echo "::set-output name=ahead::false"
fi
- name: Update version in main.user.js
if: steps.check_commit_ahead.outputs.ahead == 'true'
run: |
sed -i "s/@version\s*[^\\s]*/@version $(TZ='Asia/Shanghai' date +'%Y-%m-%d')/" main.user.js
- name: Commit and push changes
if: steps.check_commit_ahead.outputs.ahead == 'true'
env:
GITHUB_TOKEN: ${{ secrets.CI_GITHUB_TOKEN }}
run: |
git config --local user.name "github-actions[bot]"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git add main.user.js
git commit -m "main.user.js: Update to version $(TZ='Asia/Shanghai' date +'%Y-%m-%d')"
git push origin HEAD:${{ github.ref }}