Skip to content

Commit ac4a4fd

Browse files
committed
fix(ci): harden release workflow tag check and prev-tag filtering
1. Use refs/tags/ for tag existence check to avoid matching branches 2. Compare tag SHA to current commit — fail loudly if tag exists on a different commit instead of silently skipping the release 3. Use grep -xv for exact-match exclusion so v0.2.3 doesn't filter out v0.2.30 when finding the previous tag for release notes
1 parent 98a3b2f commit ac4a4fd

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

.github/workflows/release.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,17 @@ jobs:
3939
- name: Check if tag already exists
4040
id: check
4141
run: |
42-
if git rev-parse "v${{ steps.version.outputs.version }}" >/dev/null 2>&1; then
43-
echo "exists=true" >> "$GITHUB_OUTPUT"
44-
echo "⚠️ Tag v${{ steps.version.outputs.version }} already exists — skipping"
42+
TAG="${{ steps.version.outputs.tag }}"
43+
CURRENT_SHA=$(git rev-parse HEAD)
44+
if git rev-parse "refs/tags/${TAG}" >/dev/null 2>&1; then
45+
TAG_SHA=$(git rev-parse "refs/tags/${TAG}^{commit}")
46+
if [ "$TAG_SHA" = "$CURRENT_SHA" ]; then
47+
echo "exists=true" >> "$GITHUB_OUTPUT"
48+
echo "✅ Tag ${TAG} already exists on this commit — skipping tag creation"
49+
else
50+
echo "::error::Tag ${TAG} exists but points to ${TAG_SHA}, not current commit ${CURRENT_SHA}. Delete the stale tag or bump VERSION."
51+
exit 1
52+
fi
4553
else
4654
echo "exists=false" >> "$GITHUB_OUTPUT"
4755
fi
@@ -59,7 +67,7 @@ jobs:
5967
id: notes
6068
run: |
6169
# Get the previous tag
62-
PREV_TAG=$(git tag --sort=-version:refname | grep -v "${{ steps.version.outputs.tag }}" | head -1)
70+
PREV_TAG=$(git tag --sort=-version:refname | grep -xv "${{ steps.version.outputs.tag }}" | head -1)
6371
echo "Previous tag: ${PREV_TAG:-none}"
6472
6573
if [ -n "$PREV_TAG" ]; then

0 commit comments

Comments
 (0)