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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
name: Release
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
- 'v[0-9]+.[0-9]+.[0-9]+-*'
workflow_dispatch:
inputs:
dry_run:
description: 'Dry run (do not actually publish)'
type: boolean
default: true
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
jobs:
verify:
name: Verify before publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Install Rust toolchain (from rust-toolchain.toml)
run: rustup show
- uses: Swatinem/rust-cache@v2
- name: Format
run: cargo fmt --all --check
- name: Clippy
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Test
run: cargo test
- name: Test (no default features)
run: cargo test --no-default-features
- name: WASM build
run: cargo build --target wasm32-unknown-unknown --release
- name: no_std build
run: cargo build --target thumbv7em-none-eabi --no-default-features
publish:
name: Publish to crates.io
needs: verify
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Install Rust toolchain (from rust-toolchain.toml)
run: rustup show
- uses: Swatinem/rust-cache@v2
# cargo reads CARGO_REGISTRY_TOKEN from the environment automatically,
# so --token is not needed and the secret never appears on the command
# line. DRY_RUN is passed via env (not ${{ }} interpolation in shell)
# to avoid template injection.
- name: Publish regit-identifiers
env:
DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && inputs.dry_run }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
if [ "$DRY_RUN" = "true" ]; then
cargo publish --dry-run --allow-dirty
else
cargo publish
fi
github_release:
name: GitHub Release
needs: publish
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Extract changelog section for this tag
id: changelog
run: |
TAG="${GITHUB_REF#refs/tags/}"
VERSION="${TAG#v}"
# Extract the section between [VERSION] and the next ## heading
awk -v ver="$VERSION" '
/^## \[/{ if (found) exit; if ($0 ~ "\\[" ver "\\]") found=1; next }
found
' CHANGELOG.md > release_notes.md
echo "Extracted release notes for v$VERSION:"
cat release_notes.md
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
body_path: release_notes.md
draft: false
prerelease: ${{ contains(github.ref, '-') }}