From ca59e79568a1523ac05ddf921a4081c7d8511bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E5=87=AF90331?= <90331@sangfor.com> Date: Thu, 14 May 2026 18:12:31 +0800 Subject: [PATCH] fix(ci): recreate tag if it points to old commit Add verification output after syncing package.json and defines.ts so the logs clearly show whether the version bump succeeded. Also replace 'Create tag if missing' with 'Create or recreate tag' that deletes and recreates the tag when it points to a stale commit, preventing checkout of outdated code from previous failed runs. Co-authored-by: CoStrict --- .github/workflows/publish-npm.yml | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish-npm.yml b/.github/workflows/publish-npm.yml index f79b87a7d..7e382251b 100644 --- a/.github/workflows/publish-npm.yml +++ b/.github/workflows/publish-npm.yml @@ -43,6 +43,9 @@ jobs: jq --arg v "$VERSION" '.version = $v' package.json > package.json.tmp && mv package.json.tmp package.json # Update scripts/defines.ts sed -i "s/\"MACRO.VERSION\": JSON.stringify(\"[^\"]*\")/\"MACRO.VERSION\": JSON.stringify(\"$VERSION\")/" scripts/defines.ts + # Verify + echo "package.json version: $(jq -r '.version' package.json)" + grep "MACRO.VERSION" scripts/defines.ts # Commit and push version bump git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" @@ -50,13 +53,25 @@ jobs: git commit -m "chore(release): bump version to ${VERSION}" git push origin HEAD - - name: Create tag if missing + - name: Create or recreate tag if: ${{ github.event_name == 'workflow_dispatch' }} run: | TAG="${{ steps.version.outputs.tag }}" - if ! git rev-parse "${TAG}" >/dev/null 2>&1; then - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" + HEAD_COMMIT=$(git rev-parse HEAD) + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + if git rev-parse "${TAG}" >/dev/null 2>&1; then + TAG_COMMIT=$(git rev-parse "${TAG}^{commit}") + if [ "${TAG_COMMIT}" != "${HEAD_COMMIT}" ]; then + echo "Tag ${TAG} exists but points to old commit ${TAG_COMMIT}, recreating on ${HEAD_COMMIT}" + git push --delete origin "${TAG}" || true + git tag -d "${TAG}" || true + git tag "${TAG}" + git push origin "${TAG}" + else + echo "Tag ${TAG} already points to current HEAD" + fi + else git tag "${TAG}" git push origin "${TAG}" fi