diff --git a/.github/workflows/alpha.yml b/.github/workflows/alpha.yml index 87646179..1bf6f1fd 100644 --- a/.github/workflows/alpha.yml +++ b/.github/workflows/alpha.yml @@ -6,6 +6,10 @@ on: # 应当通过 git tag 来触发构建 # workflow_dispatch: push: + # 应当限制在 dev 分支上触发发布。 + branches: + - dev + # 应当限制 v*.*.*-alpha* 的 tag 来触发发布。 tags: - "v*.*.*-alpha*" permissions: write-all @@ -18,8 +22,37 @@ concurrency: group: "${{ github.workflow }} - ${{ github.head_ref || github.ref }}" jobs: + check_alpha_tag: + name: Check Alpha Tag package.json Version Consistency + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Check tag and package.json version + id: check_tag + run: | + TAG_REF="${GITHUB_REF##*/}" + echo "Current tag: $TAG_REF" + if [[ ! "$TAG_REF" =~ -alpha ]]; then + echo "Current tag is not an alpha tag." + exit 1 + fi + PKG_VERSION=$(jq -r .version package.json) + echo "package.json version: $PKG_VERSION" + if [[ "$PKG_VERSION" != *alpha* ]]; then + echo "package.json version is not an alpha version." + exit 1 + fi + if [[ "$TAG_REF" != "v$PKG_VERSION" ]]; then + echo "Tag ($TAG_REF) does not match package.json version (v$PKG_VERSION)." + exit 1 + fi + echo "Alpha tag and package.json version are consistent." + delete_old_assets: name: Delete Old Alpha Release Assets and Tags + needs: check_alpha_tag runs-on: ubuntu-latest steps: - name: Delete Old Alpha Tags Except Latest diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8372eeee..1ad8f4d9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,9 +5,10 @@ on: # ! 不再使用 workflow_dispatch 触发。 # workflow_dispatch: push: - # ? 应当限制在 main 分支上触发发布。 - # branches: - # - main + # 应当限制在 main 分支上触发发布。 + branches: + - main + # 应当限制 v*.*.* 的 tag 触发发布。 tags: - "v*.*.*" permissions: write-all @@ -20,8 +21,28 @@ concurrency: cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} jobs: + check_tag_version: + name: Check Release Tag and package.json Version Consistency + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Check tag and package.json version + run: | + TAG_REF="${GITHUB_REF##*/}" + echo "Current tag: $TAG_REF" + PKG_VERSION=$(jq -r .version package.json) + echo "package.json version: $PKG_VERSION" + if [[ "$TAG_REF" != "v$PKG_VERSION" ]]; then + echo "Tag ($TAG_REF) does not match package.json version (v$PKG_VERSION)." + exit 1 + fi + echo "Tag and package.json version are consistent." + release: name: Release Build + needs: check_tag_version strategy: fail-fast: false matrix: diff --git a/package.json b/package.json index 0aec33ce..6472e732 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "clash-verge", - "version": "2.3.0-alpha", + "version": "2.3.0", "license": "GPL-3.0-only", "scripts": { "dev": "cross-env RUST_BACKTRACE=1 tauri dev -f verge-dev", @@ -112,4 +112,4 @@ }, "type": "module", "packageManager": "pnpm@9.13.2" -} \ No newline at end of file +} diff --git a/scripts/publish-version.mjs b/scripts/publish-version.mjs index 617e38bf..e105e4b7 100644 --- a/scripts/publish-version.mjs +++ b/scripts/publish-version.mjs @@ -29,7 +29,7 @@ const runRelease = () => // 2. 判断是否需要打 tag function isSemver(version) { - return /^v?\d+\.\d+\.\d+(-alpha)?$/.test(version); + return /^v?\d+\.\d+\.\d+(-[0-9A-Za-z-.]+)?$/.test(version); } async function run() {