1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
name: Release
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
env:
CARGO_TERM_COLOR: always
jobs:
preflight:
name: Pre-flight checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2
- run: cargo fmt --all --check
- run: cargo clippy --all-targets --all-features -- -D warnings
- run: cargo test --all-features
publish:
name: Publish to crates.io
needs: preflight
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Verify version matches tag
run: |
TAG="${GITHUB_REF_NAME#v}"
CRATE_VER=$(cargo metadata --no-deps --format-version 1 \
| python3 -c "import sys,json; print(json.load(sys.stdin)['packages'][0]['version'])")
if [ "$TAG" != "$CRATE_VER" ]; then
echo "Tag $TAG does not match Cargo.toml version $CRATE_VER" >&2
exit 1
fi
- name: Publish
run: cargo publish --no-verify
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}