Skip to content

Commit d0f3388

Browse files
wflixuclaude
andcommitted
fix: properly handle already exists error in publish workflow
- Use grep to detect "already exists" error from cargo publish --dry-run - Skip publishing when package version already exists on crates.io - Continue workflow even when one package is already published - This fixes the issue where existing packages block the entire release 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 3e58167 commit d0f3388

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

.github/workflows/release.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,31 +80,39 @@ jobs:
8080
env:
8181
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
8282
run: |
83-
if cargo publish --dry-run -p mdz-rs; then
83+
echo "Checking if mdz-rs ${{ steps.version.outputs.VERSION }} exists..."
84+
if cargo publish --dry-run -p mdz-rs 2>&1 | grep -q "already exists"; then
85+
echo "mdz-rs ${{ steps.version.outputs.VERSION }} already exists, skipping publish"
86+
elif cargo publish --dry-run -p mdz-rs; then
8487
echo "Publishing mdz-rs to crates.io..."
8588
cargo publish -p mdz-rs
8689
else
87-
echo "mdz-rs ${{ steps.version.outputs.VERSION }} already exists, skipping publish"
90+
echo "Failed to check mdz-rs publish status"
91+
exit 1
8892
fi
8993
9094
- name: Wait for mdz-rs to be available
9195
run: |
92-
if cargo publish --dry-run -p mdz-rs >/dev/null 2>&1; then
96+
if cargo publish --dry-run -p mdz-rs 2>&1 | grep -q "already exists"; then
97+
echo "mdz-rs version already exists, no need to wait"
98+
else
9399
echo "New mdz-rs version published, waiting..."
94100
sleep 30
95-
else
96-
echo "mdz-rs version already exists, no need to wait"
97101
fi
98102
99103
- name: Publish mdz to crates.io
100104
env:
101105
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
102106
run: |
103-
if cargo publish --dry-run -p mdz; then
107+
echo "Checking if mdz ${{ steps.version.outputs.VERSION }} exists..."
108+
if cargo publish --dry-run -p mdz 2>&1 | grep -q "already exists"; then
109+
echo "mdz ${{ steps.version.outputs.VERSION }} already exists, skipping publish"
110+
elif cargo publish --dry-run -p mdz; then
104111
echo "Publishing mdz to crates.io..."
105112
cargo publish -p mdz
106113
else
107-
echo "mdz ${{ steps.version.outputs.VERSION }} already exists, skipping publish"
114+
echo "Failed to check mdz publish status"
115+
exit 1
108116
fi
109117
110118
# 构建 GitHub Releases

0 commit comments

Comments
 (0)