11name : Rust
2-
32on :
43 push :
54 branches : [master]
65 workflow_dispatch :
7-
86env :
97 CARGO_TERM_COLOR : always
10-
118jobs :
129 Setup :
1310 runs-on : ubuntu-latest
@@ -20,13 +17,11 @@ jobs:
2017 uses : actions/checkout@v4
2118 with :
2219 fetch-depth : 0
23-
2420 - name : Install Rust Toolchain
2521 uses : dtolnay/rust-toolchain@stable
2622 with :
2723 toolchain : stable
2824 components : rustfmt, clippy
29-
3025 - name : Cache Dependencies
3126 uses : actions/cache@v3
3227 with :
@@ -35,16 +30,13 @@ jobs:
3530 ~/.cargo/git
3631 target
3732 key : ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
38-
3933 - name : Install Toml Cli
4034 run : cargo install toml-cli
41-
4235 - name : Cache Toml Cli
4336 uses : actions/cache@v3
4437 with :
4538 path : ~/.cargo/bin/toml
4639 key : toml-cli-${{ runner.os }}
47-
4840 - name : Read Cargo Metadata
4941 id : read
5042 run : |
@@ -65,13 +57,11 @@ jobs:
6557 steps :
6658 - name : Checkout
6759 uses : actions/checkout@v4
68-
6960 - name : Setup Rust
7061 uses : dtolnay/rust-toolchain@stable
7162 with :
7263 toolchain : stable
7364 components : rustfmt
74-
7565 - name : Format Check
7666 run : cargo fmt -- --check
7767
@@ -81,12 +71,10 @@ jobs:
8171 steps :
8272 - name : Checkout
8373 uses : actions/checkout@v4
84-
8574 - name : Prepare Environment
8675 uses : dtolnay/rust-toolchain@stable
8776 with :
8877 toolchain : stable
89-
9078 - name : Run Tests
9179 run : cargo test --all-features -- --nocapture
9280
@@ -96,13 +84,11 @@ jobs:
9684 steps :
9785 - name : Checkout
9886 uses : actions/checkout@v4
99-
10087 - name : Load Clippy
10188 uses : dtolnay/rust-toolchain@stable
10289 with :
10390 toolchain : stable
10491 components : clippy
105-
10692 - name : Run Clippy
10793 run : cargo clippy --all-features -- -A warnings
10894
@@ -112,12 +98,10 @@ jobs:
11298 steps :
11399 - name : Checkout
114100 uses : actions/checkout@v4
115-
116101 - name : Setup Build
117102 uses : dtolnay/rust-toolchain@stable
118103 with :
119104 toolchain : stable
120-
121105 - name : Build Release
122106 run : cargo check --release --all-features
123107
@@ -130,7 +114,11 @@ jobs:
130114 steps :
131115 - name : Checkout
132116 uses : actions/checkout@v4
133-
117+ - name : Restore toml-cli
118+ uses : actions/cache@v3
119+ with :
120+ path : ~/.cargo/bin/toml
121+ key : toml-cli-${{ runner.os }}
134122 - name : Publish To Crates.io
135123 id : publish
136124 env :
@@ -139,9 +127,14 @@ jobs:
139127 set -e
140128 echo "published=false" >> $GITHUB_OUTPUT
141129 echo "${{ secrets.CARGO_REGISTRY_TOKEN }}" | cargo login
130+ PACKAGE_NAME=$(toml get Cargo.toml package.name --raw)
131+ VERSION=${{ needs.Setup.outputs.version }}
142132 if cargo publish --allow-dirty; then
143133 echo "published=true" >> $GITHUB_OUTPUT
144- echo "✅ Successfully published ${{ needs.Setup.outputs.package_name }} v${{ needs.Setup.outputs.version }} to crates.io"
134+ echo "🎉🎉🎉 PUBLISH SUCCESSFUL 🎉🎉🎉"
135+ echo "✅ Successfully published $PACKAGE_NAME v$VERSION to crates.io"
136+ echo "📦 Crates.io: [https://crates.io/crates/$PACKAGE_NAME/$VERSION](https://crates.io/crates/$PACKAGE_NAME/$VERSION)"
137+ echo "📚 Docs.rs: [https://docs.rs/$PACKAGE_NAME/$VERSION](https://docs.rs/$PACKAGE_NAME/$VERSION)"
145138 else
146139 echo "❌ Publish failed"
147140 exit 1
@@ -161,21 +154,19 @@ jobs:
161154 uses : actions/checkout@v4
162155 with :
163156 fetch-depth : 0
164-
165157 - name : Get Package Name
166158 id : package_info
167159 run : |
168160 echo "package_name=${{ needs.Setup.outputs.package_name }}" >> $GITHUB_OUTPUT
169-
170161 - name : Check Tag Status
171162 id : check_tag
172163 run : |
173164 if git tag -l | grep -q "^${{ needs.Setup.outputs.tag }}$"; then
174165 echo "tag_exists=true" >> $GITHUB_OUTPUT
175- echo "🏷️ Tag ${{ needs.Setup.outputs.tag }} exists locally"
166+ echo "🏷️ Tag ${{ needs.Setup.outputs.tag }} exists locally"
176167 else
177168 echo "tag_exists=false" >> $GITHUB_OUTPUT
178- echo "🏷️ Tag ${{ needs.Setup.outputs.tag }} does not exist locally"
169+ echo "🏷️ Tag ${{ needs.Setup.outputs.tag }} does not exist locally"
179170 fi
180171 if git ls-remote --tags origin | grep -q "refs/tags/${{ needs.Setup.outputs.tag }}$"; then
181172 echo "remote_tag_exists=true" >> $GITHUB_OUTPUT
@@ -184,7 +175,6 @@ jobs:
184175 echo "remote_tag_exists=false" >> $GITHUB_OUTPUT
185176 echo "🌐 Tag ${{ needs.Setup.outputs.tag }} does not exist on remote"
186177 fi
187-
188178 - name : Check Release Status
189179 id : check_release
190180 run : |
@@ -197,67 +187,57 @@ jobs:
197187 fi
198188 env :
199189 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
200-
201190 - name : Create Or Update Release
202191 id : create_release
203192 run : |
204193 set -e
205194 echo "released=false" >> $GITHUB_OUTPUT
206-
207195 PACKAGE_NAME="${{ steps.package_info.outputs.package_name }}"
208196 VERSION="${{ needs.Setup.outputs.version }}"
209197 TAG="${{ needs.Setup.outputs.tag }}"
210-
211198 echo "📦 Building source archives..."
212199 git archive --format=zip --prefix="${PACKAGE_NAME}-${VERSION}/" HEAD > "${PACKAGE_NAME}-${VERSION}.zip"
213200 git archive --format=tar.gz --prefix="${PACKAGE_NAME}-${VERSION}/" HEAD > "${PACKAGE_NAME}-${VERSION}.tar.gz"
214-
215201 if [ "${{ steps.check_release.outputs.release_exists }}" = "true" ]; then
216202 echo "🔄 Updating existing release: $TAG"
217- # 删除旧资源
218203 gh release view "$TAG" --json assets --jq '.assets[].name' | while read asset; do
219204 if [ -n "$asset" ]; then
220- echo "🗑️ Deleting asset: $asset"
205+ echo "🗑️ Deleting asset: $asset"
221206 gh release delete-asset "$TAG" "$asset" --yes || true
222207 fi
223208 done
224-
225209 if gh release edit "$TAG" \
226210 --title "$TAG (Updated $(date '+%Y-%m-%d %H:%M:%S'))" \
227211 --notes "Release $TAG - Updated at $(date '+%Y-%m-%d %H:%M:%S UTC')
228212 ## Changes
229- - Automated update from CI/CD
230213 - Version: $VERSION
231214 - Package: $PACKAGE_NAME
232-
233215 ## Links
234216 📦 [Crate on crates.io](https://crates.io/crates/$PACKAGE_NAME/$VERSION)
235217 📚 [Documentation on docs.rs](https://docs.rs/$PACKAGE_NAME/$VERSION)
236218 📋 [Commit History](https://github.com/${{ github.repository }}/commits/$TAG)" && \
237219 gh release upload "$TAG" "${PACKAGE_NAME}-${VERSION}.zip" "${PACKAGE_NAME}-${VERSION}.tar.gz" --clobber; then
238220 echo "released=true" >> $GITHUB_OUTPUT
239221 echo "✅ Updated release $TAG"
222+ echo "🔖 Tag: $TAG"
223+ echo "🚀 Release: [GitHub Release](${{ github.server_url }}/${{ github.repository }}/releases/tag/$TAG)"
240224 else
241225 echo "❌ Failed to update release"
242226 exit 1
243227 fi
244-
245228 else
246229 if [ "${{ steps.check_tag.outputs.remote_tag_exists }}" = "false" ]; then
247- echo "🏷️ Creating and pushing tag: $TAG"
230+ echo "🏷️ Creating and pushing tag: $TAG"
248231 git tag "$TAG"
249232 git push origin "$TAG"
250233 fi
251-
252234 echo "🆕 Creating new release: $TAG"
253235 if gh release create "$TAG" \
254236 --title "$TAG (Created $(date '+%Y-%m-%d %H:%M:%S'))" \
255237 --notes "Release $TAG - First published at $(date '+%Y-%m-%d %H:%M:%S UTC')
256238 ## Changes
257- - Initial release
258239 - Version: $VERSION
259240 - Package: $PACKAGE_NAME
260-
261241 ## Links
262242 📦 [Crate on crates.io](https://crates.io/crates/$PACKAGE_NAME/$VERSION)
263243 📚 [Documentation on docs.rs](https://docs.rs/$PACKAGE_NAME/$VERSION)
@@ -266,37 +246,12 @@ jobs:
266246 gh release upload "$TAG" "${PACKAGE_NAME}-${VERSION}.zip" "${PACKAGE_NAME}-${VERSION}.tar.gz"; then
267247 echo "released=true" >> $GITHUB_OUTPUT
268248 echo "✅ Created release $TAG"
249+ echo "🔖 Tag: $TAG"
250+ echo "🚀 Release: [GitHub Release](${{ github.server_url }}/${{ github.repository }}/releases/tag/$TAG)"
269251 else
270252 echo "❌ Failed to create release"
271253 exit 1
272254 fi
273255 fi
274-
275- if [ "${{ steps.create_release.outputs.released }}" = "true" ]; then
276- echo "🏷️ Tag: $TAG"
277- echo "🚀 Release: ${{ github.server_url }}/${{ github.repository }}/releases/tag/$TAG"
278- fi
279256 env :
280257 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
281-
282- Notice :
283- needs : [Setup, Publish, Release]
284- if : needs.Publish.outputs.published == 'true'
285- runs-on : ubuntu-latest
286- steps :
287- - name : Restore toml-cli
288- uses : actions/cache@v3
289- with :
290- path : ~/.cargo/bin/toml
291- key : toml-cli-${{ runner.os }}
292-
293- - name : Show Release Summary
294- run : |
295- PACKAGE_NAME=$(toml get Cargo.toml package.name --raw)
296- echo "🎉🎉🎉 PUBLISH SUCCESSFUL 🎉🎉🎉"
297- echo "✅ Version: ${{ needs.Setup.outputs.version }}"
298- echo "📦 Crate: [https://crates.io/crates/$PACKAGE_NAME](${{ github.server_url }}/crates/$PACKAGE_NAME)"
299- echo "📦 Crates.io: [https://crates.io/crates/$PACKAGE_NAME/${{ needs.Setup.outputs.version }}](https://crates.io/crates/$PACKAGE_NAME/${{ needs.Setup.outputs.version }})"
300- echo "📚 Docs.rs: [https://docs.rs/$PACKAGE_NAME/${{ needs.Setup.outputs.version }}](https://docs.rs/$PACKAGE_NAME/${{ needs.Setup.outputs.version }})"
301- echo "🔖 Tag: ${{ needs.Setup.outputs.tag }}"
302- echo "🚀 Release: [GitHub Release](${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ needs.Setup.outputs.tag }})"
0 commit comments