Skip to content

Commit 94d3e9e

Browse files
drernieclaude
andcommitted
Address PR review: tighten tag-release.sh
- Scope existence check to refs/tags/ to avoid matching branches - Escape dots in version for awk regex - Use tr -d '[:space:]' to catch tabs/newlines in notes guard - Roll back tag if gh release create fails Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 4d18ba5 commit 94d3e9e

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

wf/tag-release.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,20 @@ if [[ "$BRANCH" != "main" || "$HEAD_SHA" != "$MAIN_SHA" ]]; then
2626
echo "(dry-run: continuing anyway)" >&2
2727
fi
2828

29-
if git rev-parse "$VERSION" >/dev/null 2>&1; then
29+
if git rev-parse "refs/tags/$VERSION" >/dev/null 2>&1; then
3030
echo "Tag $VERSION already exists" >&2
3131
[[ $DRY_RUN -eq 1 ]] || exit 1
3232
fi
3333

34-
NOTES="$(awk -v v="$VERSION" '
34+
# Escape dots so awk treats the version literally (1.0.1 must not match 1X0Y1).
35+
ESCAPED_VERSION="${VERSION//./\\.}"
36+
NOTES="$(awk -v v="$ESCAPED_VERSION" '
3537
$0 ~ "^## \\[" v "\\]" { found=1; next }
3638
found && /^## \[/ { exit }
3739
found { print }
3840
' CHANGELOG.md)"
3941

40-
if [[ -z "${NOTES// }" ]]; then
42+
if [[ -z "$(printf %s "$NOTES" | tr -d '[:space:]')" ]]; then
4143
echo "No CHANGELOG section found for [$VERSION]" >&2
4244
exit 1
4345
fi
@@ -57,5 +59,12 @@ fi
5759

5860
git tag -a "$VERSION" -m "Release $VERSION"
5961
git push origin "$VERSION"
60-
gh release create "$VERSION" --title "Version $VERSION" --notes "$NOTES"
62+
63+
# Roll back the tag if release creation fails so we don't leave a half-released state.
64+
if ! gh release create "$VERSION" --title "Version $VERSION" --notes "$NOTES"; then
65+
echo "gh release create failed; rolling back tag $VERSION" >&2
66+
git push origin --delete "$VERSION" || true
67+
git tag -d "$VERSION" || true
68+
exit 1
69+
fi
6170
echo "Tagged and released $VERSION"

0 commit comments

Comments
 (0)