7676 # ========================================
7777 # Publish Rust Crates to crates.io
7878 # ========================================
79- # 由 changesets 管理版本号,如果 crates.io 已存在同版本则跳过
79+ # 由 changesets 管理版本号,始终使用新版本发布
80+ # 如果版本已存在,cargo publish 会报错,我们忽略错误继续
8081
8182 - name : Get versions from package.json
8283 id : versions
@@ -85,102 +86,41 @@ jobs:
8586 echo "qrcode_rust=$(node -p "require('./packages/qrcode-rust/package.json').version")" >> $GITHUB_OUTPUT
8687 echo "qrcode_fast=$(node -p "require('./packages/qrcode-fast/package.json').version")" >> $GITHUB_OUTPUT
8788
88- # 使用 crates.io API 检测版本是否存在(比 cargo search 更可靠)
89- - name : Check if qrcode-rust-shared exists on crates.io
90- id : check-shared
91- run : |
92- VERSION="${{ steps.versions.outputs.qrcode_rust_shared }}"
93- EXISTS=$(curl -s "https://crates.io/api/v1/crates/qrcode-rust-shared" | grep -o "\"newest_version\":\"$VERSION\"" || echo "")
94- if [ -n "$EXISTS" ]; then
95- echo "exists=true" >> $GITHUB_OUTPUT
96- else
97- echo "exists=false" >> $GITHUB_OUTPUT
98- fi
99-
89+ # 发布 qrcode-rust-shared,如果版本已存在则忽略
10090 - name : Publish qrcode-rust-shared to crates.io
101- if : steps.check-shared.outputs.exists == 'false'
91+ continue-on-error : true
10292 env :
10393 CARGO_REGISTRY_TOKEN : ${{ secrets.CARGO_REGISTRY_TOKEN }}
10494 run : |
105- VERSION="${{ steps.versions.outputs.qrcode_rust_shared }}"
106- echo "📦 Publishing qrcode-rust-shared v$VERSION..."
107- cargo publish -p qrcode-rust-shared --token "$CARGO_REGISTRY_TOKEN" --registry crates-io
108- echo "✅ qrcode-rust-shared published"
109-
110- - name : Skip qrcode-rust-shared (already exists)
111- if : steps.check-shared.outputs.exists == 'true'
112- run : echo "✅ qrcode-rust-shared v${{ steps.versions.outputs.qrcode_rust_shared }} already exists, skipping"
95+ echo "📦 Publishing qrcode-rust-shared v${{ steps.versions.outputs.qrcode_rust_shared }}..."
96+ cargo publish -p qrcode-rust-shared --token "$CARGO_REGISTRY_TOKEN" --registry crates-io 2>&1 || {
97+ echo "⚠️ May already exist, continuing..."
98+ }
11399
114100 - name : Wait for crates.io index
115101 run : sleep 30
116102
117- - name : Check if qrcode-rust exists on crates.io
118- id : check-rust
119- run : |
120- VERSION="${{ steps.versions.outputs.qrcode_rust }}"
121- EXISTS=$(curl -s "https://crates.io/api/v1/crates/qrcode-rust" | grep -o "\"newest_version\":\"$VERSION\"" || echo "")
122- if [ -n "$EXISTS" ]; then
123- echo "exists=true" >> $GITHUB_OUTPUT
124- else
125- echo "exists=false" >> $GITHUB_OUTPUT
126- fi
127-
103+ # 发布 qrcode-rust,如果版本已存在则忽略
128104 - name : Publish qrcode-rust to crates.io
129- if : steps.check-rust.outputs.exists == 'false'
105+ continue-on-error : true
130106 env :
131107 CARGO_REGISTRY_TOKEN : ${{ secrets.CARGO_REGISTRY_TOKEN }}
132- continue-on-error : true
133- run : |
134- VERSION="${{ steps.versions.outputs.qrcode_rust }}"
135- echo "📦 Publishing qrcode-rust v$VERSION..."
136- for i in 1 2 3; do
137- if cargo publish -p qrcode-rust --token "$CARGO_REGISTRY_TOKEN" --registry crates-io 2>&1; then
138- echo "✅ qrcode-rust published"
139- exit 0
140- fi
141- echo "⚠️ Attempt $i failed, retrying in 30s..."
142- sleep 30
143- done
144- echo "❌ Failed to publish qrcode-rust"
145- exit 1
146-
147- - name : Skip qrcode-rust (already exists)
148- if : steps.check-rust.outputs.exists == 'true'
149- run : echo "✅ qrcode-rust v${{ steps.versions.outputs.qrcode_rust }} already exists, skipping"
150-
151- - name : Check if qrcode-fast exists on crates.io
152- id : check-fast
153108 run : |
154- VERSION="${{ steps.versions.outputs.qrcode_fast }}"
155- EXISTS=$(curl -s "https://crates.io/api/v1/crates/qrcode-fast" | grep -o "\"newest_version\":\"$VERSION\"" || echo "")
156- if [ -n "$EXISTS" ]; then
157- echo "exists=true" >> $GITHUB_OUTPUT
158- else
159- echo "exists=false" >> $GITHUB_OUTPUT
160- fi
109+ echo "📦 Publishing qrcode-rust v${{ steps.versions.outputs.qrcode_rust }}..."
110+ cargo publish -p qrcode-rust --token "$CARGO_REGISTRY_TOKEN" --registry crates-io 2>&1 || {
111+ echo "⚠️ May already exist, continuing..."
112+ }
161113
114+ # 发布 qrcode-fast,如果版本已存在则忽略
162115 - name : Publish qrcode-fast to crates.io
163- if : steps.check-fast.outputs.exists == 'false'
116+ continue-on-error : true
164117 env :
165118 CARGO_REGISTRY_TOKEN : ${{ secrets.CARGO_REGISTRY_TOKEN }}
166- continue-on-error : true
167119 run : |
168- VERSION="${{ steps.versions.outputs.qrcode_fast }}"
169- echo "📦 Publishing qrcode-fast v$VERSION..."
170- for i in 1 2 3; do
171- if cargo publish -p qrcode-fast --token "$CARGO_REGISTRY_TOKEN" --registry crates-io 2>&1; then
172- echo "✅ qrcode-fast published"
173- exit 0
174- fi
175- echo "⚠️ Attempt $i failed, retrying in 30s..."
176- sleep 30
177- done
178- echo "❌ Failed to publish qrcode-fast"
179- exit 1
180-
181- - name : Skip qrcode-fast (already exists)
182- if : steps.check-fast.outputs.exists == 'true'
183- run : echo "✅ qrcode-fast v${{ steps.versions.outputs.qrcode_fast }} already exists, skipping"
120+ echo "📦 Publishing qrcode-fast v${{ steps.versions.outputs.qrcode_fast }}..."
121+ cargo publish -p qrcode-fast --token "$CARGO_REGISTRY_TOKEN" --registry crates-io 2>&1 || {
122+ echo "⚠️ May already exist, continuing..."
123+ }
184124
185125 - name : Create Release Pull Request or Publish
186126 uses : changesets/action@v1
0 commit comments