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 <zgsm@sangfor.com.cn>
This commit is contained in:
林凯90331 2026-05-14 18:12:31 +08:00
parent 59269f381d
commit ca59e79568

View File

@ -43,6 +43,9 @@ jobs:
jq --arg v "$VERSION" '.version = $v' package.json > package.json.tmp && mv package.json.tmp package.json jq --arg v "$VERSION" '.version = $v' package.json > package.json.tmp && mv package.json.tmp package.json
# Update scripts/defines.ts # Update scripts/defines.ts
sed -i "s/\"MACRO.VERSION\": JSON.stringify(\"[^\"]*\")/\"MACRO.VERSION\": JSON.stringify(\"$VERSION\")/" 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 # Commit and push version bump
git config user.name "github-actions[bot]" git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com" 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 commit -m "chore(release): bump version to ${VERSION}"
git push origin HEAD git push origin HEAD
- name: Create tag if missing - name: Create or recreate tag
if: ${{ github.event_name == 'workflow_dispatch' }} if: ${{ github.event_name == 'workflow_dispatch' }}
run: | run: |
TAG="${{ steps.version.outputs.tag }}" TAG="${{ steps.version.outputs.tag }}"
if ! git rev-parse "${TAG}" >/dev/null 2>&1; then HEAD_COMMIT=$(git rev-parse HEAD)
git config user.name "github-actions[bot]" git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com" 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 tag "${TAG}"
git push origin "${TAG}" git push origin "${TAG}"
fi fi