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
59
60
61
62
63
64
65
66
67
# Auto-publish to crates.io via Trusted Publishing (OIDC) when a tag matching
# `v*` is pushed. No CARGO_REGISTRY_TOKEN required.
#
# To release:
# 1. Bump `version` in Cargo.toml, update CHANGELOG.md, commit, push to main.
# 2. Tag and push:
# git tag v0.1.0 -m "0.1.0"
# git push origin v0.1.0
# 3. This workflow verifies the tag, tests, publishes, and cuts a Release.
#
# One-time crates.io Trusted Publishing setup:
# 1. Publish 0.1.0 once manually (crates.io requires the crate to exist before
# a Trusted Publisher can be attached), OR reserve the name, then:
# 2. crates.io -> the `invoance` crate -> Settings -> Trusted Publishing -> add:
# Repository owner: Invoance
# Repository name: invoance-rust
# Workflow: release.yml
# Environment: (leave blank, or `crates-io` if you create one)
name: Release to crates.io
on:
push:
tags:
- "v*"
permissions:
contents: write # to create the GitHub Release
id-token: write # required for crates.io Trusted Publishing OIDC
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Verify tag matches Cargo.toml version
run: |
TAG="${GITHUB_REF_NAME#v}"
PKG=$(grep -m1 '^version' Cargo.toml | sed -E 's/.*"(.*)".*/\1/')
if [ "$TAG" != "$PKG" ]; then
echo "ERROR: tag $GITHUB_REF_NAME does not match Cargo.toml version $PKG" >&2
exit 1
fi
echo "Tag $GITHUB_REF_NAME matches Cargo.toml version $PKG"
- run: cargo test --all-targets
- run: cargo publish --dry-run
- name: Authenticate to crates.io via OIDC
uses: rust-lang/crates-io-auth-action@v1
id: auth
- run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
name: ${{ github.ref_name }}
generate_release_notes: true
body: |
See [CHANGELOG](CHANGELOG.md) for details.
Published to https://crates.io/crates/invoance — add with `cargo add invoance`.