Skip to content

Commit 2cfaf96

Browse files
cdeckerclaude
andcommitted
ci: Make crates.io publish step idempotent
Check if the version is already published before attempting cargo publish, so re-running the workflow after a partial failure (e.g., GitHub Release 403) doesn't fail on the already-published crate. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 34fec68 commit 2cfaf96

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

.github/workflows/release.yml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -447,15 +447,18 @@ jobs:
447447
- name: Publish to crates.io
448448
if: steps.parse.outputs.dry_run == 'false'
449449
run: |
450-
echo "🚀 Publishing ${{ steps.parse.outputs.crate }} v${{ steps.parse.outputs.version }} to crates.io..."
451-
452-
# -p flag: Publish only this specific crate from the workspace
453-
# CARGO_REGISTRY_TOKEN: Authenticates with crates.io
454-
# This token should be added to GitHub Secrets as CRATES_IO_TOKEN
455-
cargo publish -p ${{ steps.parse.outputs.crate }}
450+
CRATE="${{ steps.parse.outputs.crate }}"
451+
VERSION="${{ steps.parse.outputs.version }}"
452+
echo "🚀 Publishing $CRATE v$VERSION to crates.io..."
456453
457-
echo "✅ Successfully published to crates.io!"
458-
echo "🔗 https://crates.io/crates/${{ steps.parse.outputs.crate }}"
454+
# Check if this version is already published (idempotent retries)
455+
if cargo search "$CRATE" --limit 1 | grep -q "^$CRATE = \"$VERSION\""; then
456+
echo "✅ $CRATE v$VERSION is already published on crates.io — skipping"
457+
else
458+
cargo publish -p "$CRATE"
459+
echo "✅ Successfully published to crates.io!"
460+
fi
461+
echo "🔗 https://crates.io/crates/$CRATE"
459462
env:
460463
# The token is stored in GitHub Secrets for security
461464
# To create one: https://crates.io/settings/tokens

0 commit comments

Comments
 (0)