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
name: Publish to crates.io
on:
release:
types:
# Manual trigger for the one-time bootstrap publish of a brand-new crate, which cannot
# use Trusted Publishing (that must be configured on an already-published crate). Uses
# the CARGO_TOKEN_FOR_NEW_CRATES_ONLY secret. Every subsequent release publishes via
# OIDC and needs no token.
workflow_dispatch:
jobs:
publish:
name: Publish
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Checkout the code
uses: actions/checkout@v6
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Rust cache
uses: Swatinem/rust-cache@v2
- name: Set version from tag
if: github.event_name == 'release'
run: |
VERSION="${GITHUB_REF_NAME#v}"
sed -i "s/^version = .*/version = \"${VERSION}\"/" Cargo.toml
- name: Authenticate via Trusted Publishing (OIDC)
if: github.event_name == 'release'
uses: rust-lang/crates-io-auth-action@v1
id: auth
- name: Publish jsonfg
run: cargo publish --allow-dirty
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token || secrets.CARGO_TOKEN_FOR_NEW_CRATES_ONLY }}