Skip to content

Commit f14d00e

Browse files
committed
refactor: simplify crates.io publish logic
- Remove verbose comments and extra output - Keep simple check: if version exists on crates.io, skip publishing - Versions are managed by changesets, crates.io just avoids duplicates
1 parent e9c7749 commit f14d00e

1 file changed

Lines changed: 12 additions & 30 deletions

File tree

.github/workflows/release.yml

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -76,90 +76,72 @@ jobs:
7676
# ========================================
7777
# Publish Rust Crates to crates.io
7878
# ========================================
79-
# 检测当前版本号,如果已存在则跳过,避免版本冲突错误
79+
# 由 changesets 管理版本号,如果 crates.io 已存在同版本则跳过
8080

81-
# Step 1: 获取当前 package.json 中的版本号
82-
- name: Get current versions
81+
- name: Get versions from package.json
8382
id: versions
8483
run: |
8584
echo "qrcode_rust_shared=$(node -p "require('./packages/qrcode-rust-shared/package.json').version")" >> $GITHUB_OUTPUT
8685
echo "qrcode_rust=$(node -p "require('./packages/qrcode-rust/package.json').version")" >> $GITHUB_OUTPUT
8786
echo "qrcode_fast=$(node -p "require('./packages/qrcode-fast/package.json').version")" >> $GITHUB_OUTPUT
8887
89-
# Step 2: 检查并发布 qrcode-rust-shared
9088
- name: Publish qrcode-rust-shared to crates.io
9189
env:
9290
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
9391
run: |
9492
VERSION="${{ steps.versions.outputs.qrcode_rust_shared }}"
95-
echo "📦 Checking qrcode-rust-shared v$VERSION on crates.io..."
96-
97-
# 检查是否已存在
98-
EXISTING=$(cargo search qrcode-rust-shared --limit 1 2>/dev/null | grep "qrcode-rust-shared =" || echo "")
99-
if echo "$EXISTING" | grep -q "=\"$VERSION\""; then
93+
if cargo search qrcode-rust-shared --limit 1 2>/dev/null | grep -q "qrcode-rust-shared = \"$VERSION\""; then
10094
echo "✅ qrcode-rust-shared v$VERSION already exists, skipping"
10195
else
10296
echo "📦 Publishing qrcode-rust-shared v$VERSION..."
103-
if cargo publish -p qrcode-rust-shared --token "$CARGO_REGISTRY_TOKEN" 2>&1; then
104-
echo "✅ qrcode-rust-shared v$VERSION published successfully"
105-
else
106-
echo "⚠️ Publish failed (may already exist), skipping"
107-
fi
97+
cargo publish -p qrcode-rust-shared --token "$CARGO_REGISTRY_TOKEN"
98+
echo "✅ qrcode-rust-shared published"
10899
fi
109100
110-
# Step 3: 等待 crates.io 索引更新
111-
- name: Wait for crates.io index update
101+
- name: Wait for crates.io index
112102
run: sleep 30
113103

114-
# Step 4: 检查并发布 qrcode-rust
115104
- name: Publish qrcode-rust to crates.io
116105
env:
117106
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
118107
continue-on-error: true
119108
run: |
120109
VERSION="${{ steps.versions.outputs.qrcode_rust }}"
121-
echo "📦 Checking qrcode-rust v$VERSION on crates.io..."
122-
123-
EXISTING=$(cargo search qrcode-rust --limit 1 2>/dev/null | grep "^qrcode-rust =" || echo "")
124-
if echo "$EXISTING" | grep -q "=\"$VERSION\""; then
110+
if cargo search qrcode-rust --limit 1 2>/dev/null | grep -q "qrcode-rust = \"$VERSION\""; then
125111
echo "✅ qrcode-rust v$VERSION already exists, skipping"
126112
else
127113
echo "📦 Publishing qrcode-rust v$VERSION..."
128114
for i in 1 2 3; do
129115
if cargo publish -p qrcode-rust --token "$CARGO_REGISTRY_TOKEN" 2>&1; then
130-
echo "✅ qrcode-rust v$VERSION published successfully"
116+
echo "✅ qrcode-rust published"
131117
exit 0
132118
fi
133119
echo "⚠️ Attempt $i failed, retrying in 30s..."
134120
sleep 30
135121
done
136-
echo "❌ Failed to publish qrcode-rust after 3 attempts"
122+
echo "❌ Failed to publish qrcode-rust"
137123
exit 1
138124
fi
139125
140-
# Step 5: 检查并发布 qrcode-fast
141126
- name: Publish qrcode-fast to crates.io
142127
env:
143128
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
144129
continue-on-error: true
145130
run: |
146131
VERSION="${{ steps.versions.outputs.qrcode_fast }}"
147-
echo "📦 Checking qrcode-fast v$VERSION on crates.io..."
148-
149-
EXISTING=$(cargo search qrcode-fast --limit 1 2>/dev/null | grep "^qrcode-fast =" || echo "")
150-
if echo "$EXISTING" | grep -q "=\"$VERSION\""; then
132+
if cargo search qrcode-fast --limit 1 2>/dev/null | grep -q "qrcode-fast = \"$VERSION\""; then
151133
echo "✅ qrcode-fast v$VERSION already exists, skipping"
152134
else
153135
echo "📦 Publishing qrcode-fast v$VERSION..."
154136
for i in 1 2 3; do
155137
if cargo publish -p qrcode-fast --token "$CARGO_REGISTRY_TOKEN" 2>&1; then
156-
echo "✅ qrcode-fast v$VERSION published successfully"
138+
echo "✅ qrcode-fast published"
157139
exit 0
158140
fi
159141
echo "⚠️ Attempt $i failed, retrying in 30s..."
160142
sleep 30
161143
done
162-
echo "❌ Failed to publish qrcode-fast after 3 attempts"
144+
echo "❌ Failed to publish qrcode-fast"
163145
exit 1
164146
fi
165147

0 commit comments

Comments
 (0)