1+ name : Publish Crate
2+
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+ jobs :
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 }}
0 commit comments