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
46
47
48
49
50
51
52
53
54
55
56
57
58
name: Publish
on:
push:
tags:
- "v*"
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
jobs:
publish:
name: Validate and publish
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Check out source
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.88.0
components: rustfmt, clippy
- name: Validate release tag
if: github.ref_type == 'tag'
shell: bash
run: |
set -euo pipefail
version="$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')"
tag_version="${GITHUB_REF_NAME#v}"
[[ "$tag_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || {
echo "Tag $GITHUB_REF_NAME is not a semantic version tag" >&2
exit 1
}
test "$version" = "$tag_version" || {
echo "Tag $GITHUB_REF_NAME does not match Cargo.toml version $version" >&2
exit 1
}
- name: Check formatting
run: cargo fmt --all -- --check
- name: Run tests
run: cargo test --locked
- name: Run Clippy
run: cargo clippy --all-targets --locked -- -D warnings
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish --locked