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
name: Publish to crates.io
on:
push:
tags:
- "v*.*.*"
jobs:
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache Cargo registry
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
key: cargo-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
cargo-${{ runner.os }}-
- name: Verify crate version matches tag
run: |
VERSION_IN_CARGO_TOML=$(grep '^version =' Cargo.toml | cut -d '"' -f 2)
VERSION_IN_TAG=${GITHUB_REF#refs/tags/v}
if [ "$VERSION_IN_CARGO_TOML" != "$VERSION_IN_TAG" ]; then
echo "Version in Cargo.toml ($VERSION_IN_CARGO_TOML) does not match tag ($VERSION_IN_TAG)"
exit 1
fi
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
run: cargo publish --allow-dirty