11name : Publish Crate
22
3- on :
4- push :
5- tags :
6- - ' v[0-9]+.[0-9]+.[0-9]+*' # Trigger on tags like v0.1.0, v1.0.0-alpha
7-
3+ # on:
4+ # push:
5+ # tags:
6+ # - 'v[0-9]+.[0-9]+.[0-9]+*' # Trigger on tags like v0.1.0, v1.0.0-alpha
7+
8+ on :
9+ release :
10+ types : [published] # Trigger on release publication
811jobs :
9- publish :
10- name : Build and publish crate
11- runs-on : ubuntu-latest
12- steps :
13- - name : Checkout sources
14- uses : actions/checkout@v4
15-
16- - name : Install Rust toolchain
17- uses : dtolnay/rust-toolchain@stable
18- with :
19- components : clippy, rustfmt
20-
21- - name : Cache dependencies
22- uses : Swatinem/rust-cache@v2
23- with :
24- key : ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
25-
26- - name : Run linters
27- run : cargo fmt --all && cargo clippy --fix
28-
29- - name : Run tests
30- run : cargo test --all-features --verbose
31-
32- - name : Build in release mode
33- run : cargo build --release --all-features
34-
35- - name : Publish to crates.io
36- if : startsWith(github.ref, 'refs/tags/v') # Only publish on version tags
37- env :
38- CARGO_REGISTRY_TOKEN : ${{ secrets.CARGO_TOKEN }}
39- run : cargo publish
40-
41- # Optional: Create a GitHub Release
42- - name : Create GitHub Release
43- if : startsWith(github.ref, 'refs/tags/v')
44- uses : softprops/action-gh-release@v2
45- with :
46- files : |
47- target/release/<your_crate_name_here> # Adjust if you have specific binaries to attach
48- # Add other assets like README.md, LICENSE, etc.
49- # You can customize the release notes, name, etc.
50- # See https://github.com/softprops/action-gh-release for more options
51- env :
52- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
12+ build :
13+ name : Test, Lint, and Build Rust Project
14+ runs-on : ubuntu-latest
15+ steps :
16+ - uses : actions/checkout@v4
17+ - name : lint
18+ run : cargo clippy --fix
19+ - name : format
20+ run : cargo fmt --all
21+ - name : Build
22+ run : cargo build
23+ - name : Run tests
24+ run : cargo test
25+ publish :
26+ name : Build and publish crate
27+ needs : build
28+ runs-on : ubuntu-latest
29+ steps :
30+ - name : Checkout sources
31+ uses : actions/checkout@v4
32+ - name : Build in release mode
33+ run : cargo build --release --all-features
34+ - name : Publish to crates.io
35+ env :
36+ CARGO_REGISTRY_TOKEN : ${{ secrets.CARGO_TOKEN }}
37+ run : cargo publish
0 commit comments