Skip to content

Commit

Permalink
GitHub Action: 新增开发版 main.user.js 每周一凌晨自动更新版本号
Browse files Browse the repository at this point in the history
注: 不自动打标签, 仅当更新`GreasyFork 托管【发布版】`人工打标签
  • Loading branch information
maboloshi committed Nov 25, 2023
1 parent f55e409 commit f0f557d
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/main.user.js_version_update.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: main.user.js version update
on:
schedule:
- cron: "0 0 * * 1"
workflow_dispatch:

jobs:
update_version:
if: not 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 }}

0 comments on commit f0f557d

Please sign in to comment.