Skip to content

Commit fddbe6f

Browse files
committed
fix(dev): harden gh-retag with crates.io check and robust tag handling
# ── git-warden policy guide ── # Write the commit message in English # AI co-author trailers will be removed before commit
1 parent 773f941 commit fddbe6f

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

justfile

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,29 @@ gh-publish:
3131
gh release edit $(git describe --tags --abbrev=0) --draft=false
3232

3333
# Delete existing draft release + tag, re-tag HEAD, push to re-trigger CI
34-
# Refuses to run if the release is already published (non-draft)
34+
# Refuses to run if the release is already published (non-draft) or on crates.io
3535
gh-retag:
3636
#!/usr/bin/env bash
3737
set -euo pipefail
38-
TAG=$(git describe --tags --abbrev=0)
39-
IS_DRAFT=$(gh release view "${TAG}" --json isDraft -q '.isDraft' 2>/dev/null || echo "false")
40-
if [[ "${IS_DRAFT}" != "true" ]]; then
38+
VERSION=$(grep -m1 '^version = ' Cargo.toml | grep -oP '(?<=")[^"]+')
39+
TAG="v${VERSION}"
40+
CRATE="gitversion-rs"
41+
STATUS=$(curl -s -o /dev/null -w "%{http_code}" -A "gh-retag/1.0" \
42+
"https://crates.io/api/v1/crates/${CRATE}/${VERSION}")
43+
if [[ "${STATUS}" == "200" ]]; then
44+
echo "Error: ${CRATE} v${VERSION} is already published to crates.io. Refusing to retag."
45+
exit 1
46+
fi
47+
IS_DRAFT=$(gh release view "${TAG}" --json isDraft -q '.isDraft' 2>/dev/null || echo "none")
48+
if [[ "${IS_DRAFT}" == "false" ]]; then
4149
echo "Error: ${TAG} is not a draft release. Refusing to retag."
4250
exit 1
4351
fi
4452
echo "Re-tagging ${TAG} at HEAD"
45-
gh release delete "${TAG}" --yes --cleanup-tag
46-
git tag -d "${TAG}"
53+
if [[ "${IS_DRAFT}" == "true" ]]; then
54+
gh release delete "${TAG}" --yes --cleanup-tag
55+
fi
56+
git tag -d "${TAG}" 2>/dev/null || true
57+
git push origin --delete "${TAG}" 2>/dev/null || true
4758
git tag -a "${TAG}" -m "release: ${TAG#v}"
4859
git push origin "${TAG}"

0 commit comments

Comments
 (0)