Skip to content

Commit 1185450

Browse files
fix: make cargo publish idempotent in release workflow
When the release workflow is re-run (e.g. after fixing a Docker build failure), cargo publish fails because the version is already on crates.io. Now checks if the version is already published and skips with a warning instead of failing the entire workflow. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 46925ce commit 1185450

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

.github/workflows/release.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ jobs:
1616
- uses: Swatinem/rust-cache@v2
1717
- run: cargo test --all
1818
- name: Publish to crates.io
19-
run: cargo publish
19+
run: |
20+
cargo publish 2>&1 || {
21+
if cargo search initium --limit 1 | grep -q "$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/')"; then
22+
echo "::warning::Version already published to crates.io — skipping"
23+
else
24+
echo "::error::cargo publish failed"
25+
exit 1
26+
fi
27+
}
2028
env:
2129
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
2230
- uses: docker/setup-qemu-action@v3

0 commit comments

Comments
 (0)