Skip to content

Update Version(cw1)

Update Version(cw1) #3

name: Update Version
on:
repository_dispatch:
types: [update-version]
workflow_dispatch:
permissions:
contents: write
actions: read
pull-requests: write
jobs:
update-version:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: 1
- name: Fetch version
id: fetch_versions
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: "Class-Widgets/Class-Widgets"
run: |
VERSION_RELEASE=$(gh release list --repo "${{ env.REPO }}" --json tagName,isPrerelease --jq '[.[] | select(.isPrerelease == false)][0].tagName // empty')
if [ -z "$VERSION_RELEASE" ] || [ "$VERSION_RELEASE" = "null" ]; then
echo "[DEBUG] 未找到正式版本"
VERSION_RELEASE=$(gh release list --repo "${{ env.REPO }}" --json tagName --jq '.[0].tagName // empty')
if [ -z "$VERSION_RELEASE" ] || [ "$VERSION_RELEASE" = "null" ]; then
echo "[ERROR] 无法获取任何版本信息"
exit 1
fi
fi
VERSION_BETA=$(gh release list --repo "${{ env.REPO }}" --json tagName,isPrerelease --jq '[.[] | select(.isPrerelease == true)][0].tagName // empty')
if [ -z "$VERSION_BETA" ]; then
VERSION_BETA="$VERSION_RELEASE"
fi
echo "[INFO] 最新 release 版本: $VERSION_RELEASE"
echo "[INFO] 最新 beta / Nightly 版本: $VERSION_BETA"
jq -n \
--arg release "$VERSION_RELEASE" \
--arg beta "$VERSION_BETA" \
'{"version_release": $release, "version_beta": $beta}' > public/version.json
echo "VERSION_RELEASE=$VERSION_RELEASE" >> $GITHUB_OUTPUT
echo "VERSION_BETA=$VERSION_BETA" >> $GITHUB_OUTPUT
- name: Import GPG key
id: import-gpg
uses: crazy-max/ghaction-import-gpg@v6
continue-on-error: true
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: |
chore(version): 更新版本号
* 正式版: ${{ steps.fetch_versions.outputs.VERSION_RELEASE }}
* Beta / Nightly 版: ${{ steps.fetch_versions.outputs.VERSION_BETA }}
title: 'chore(version): 更新版本号'
body: |
## 版本更新
- **正式版**: ${{ steps.fetch_versions.outputs.VERSION_RELEASE }}
- **Beta / Nightly 版**: ${{ steps.fetch_versions.outputs.VERSION_BETA }}
branch: update/version-${{ github.run_id }}
delete-branch: true
committer: ChimeYao-bot <[email protected]>
author: ChimeYao-bot <[email protected]>