Skip to content

Commit ea2fc0e

Browse files
authored
ci: 自动更新版本号
2 parents 2ba8870 + 1de8ba3 commit ea2fc0e

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Update Version
2+
3+
on:
4+
repository_dispatch:
5+
types: [update-version]
6+
workflow_dispatch:
7+
permissions:
8+
contents: write
9+
actions: read
10+
11+
jobs:
12+
update-version:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v5
17+
with:
18+
fetch-depth: 1
19+
20+
- name: Fetch version
21+
id: fetch_versions
22+
env:
23+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24+
REPO: "Class-Widgets/Class-Widgets"
25+
run: |
26+
VERSION_RELEASE=$(gh release list --repo "${{ env.REPO }}" --json tagName,isPrerelease --jq '[.[] | select(.isPrerelease == false)][0].tagName // empty')
27+
if [ -z "$VERSION_RELEASE" ] || [ "$VERSION_RELEASE" = "null" ]; then
28+
echo "[DEBUG] 未找到正式版本"
29+
VERSION_RELEASE=$(gh release list --repo "${{ env.REPO }}" --json tagName --jq '.[0].tagName // empty')
30+
if [ -z "$VERSION_RELEASE" ] || [ "$VERSION_RELEASE" = "null" ]; then
31+
echo "[ERROR] 无法获取任何版本信息"
32+
exit 1
33+
fi
34+
fi
35+
VERSION_BETA=$(gh release list --repo "${{ env.REPO }}" --json tagName,isPrerelease --jq '[.[] | select(.isPrerelease == true)][0].tagName // empty')
36+
if [ -z "$VERSION_BETA" ]; then
37+
VERSION_BETA="$VERSION_RELEASE"
38+
fi
39+
echo "[INFO] 最新 release 版本: $VERSION_RELEASE"
40+
echo "[INFO] 最新 beta / Nightly 版本: $VERSION_BETA"
41+
42+
jq -n \
43+
--arg release "$VERSION_RELEASE" \
44+
--arg beta "$VERSION_BETA" \
45+
'{"version_release": $release, "version_beta": $beta}' > public/version.json
46+
echo "VERSION_RELEASE=$VERSION_RELEASE" >> $GITHUB_OUTPUT
47+
echo "VERSION_BETA=$VERSION_BETA" >> $GITHUB_OUTPUT
48+
49+
- name: Import GPG key
50+
id: import-gpg
51+
uses: crazy-max/ghaction-import-gpg@v6
52+
continue-on-error: true
53+
with:
54+
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
55+
passphrase: ${{ secrets.GPG_PASSPHRASE }}
56+
git_user_signingkey: true
57+
git_commit_gpgsign: true
58+
59+
- name: Commit changes
60+
uses: stefanzweifel/git-auto-commit-action@v6
61+
with:
62+
commit_message: |
63+
chore(version): 更新版本号
64+
65+
* 正式版: ${{ steps.fetch_versions.outputs.VERSION_RELEASE }}
66+
* Beta / Nightly 版: ${{ steps.fetch_versions.outputs.VERSION_BETA }}
67+
file_pattern: 'public/version.json'
68+
commit_user_name: 'ChimeYao-bot'
69+
commit_user_email: 'ChimeYao@outlook.jp'
70+
commit_author: 'ChimeYao-bot <ChimeYao@outlook.jp>'

0 commit comments

Comments
 (0)