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
name: Release
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+*"
permissions:
contents: write
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Extract version from tag
id: version
run: echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
- name: Verify tag matches Cargo.toml version
run: |
crate_version=$(grep -m1 '^version' Cargo.toml | cut -d'"' -f2)
if [ "$crate_version" != "${{ steps.version.outputs.version }}" ]; then
echo "Tag ${{ steps.version.outputs.version }} != Cargo.toml $crate_version" >&2
exit 1
fi
- name: Extract changelog section
id: changelog
run: |
# Extract the section for this version from CHANGELOG.md
section=$(awk '/^## \['"${{ steps.version.outputs.version }}"'\]/{found=1; next} /^## \[/{if(found) exit} found{print}' CHANGELOG.md)
{
echo "notes<<EOF"
echo "$section"
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Create GitHub Release
run: |
gh release create "$GITHUB_REF_NAME" \
--title "$GITHUB_REF_NAME" \
--notes "$RELEASE_NOTES"
env:
GH_TOKEN: ${{ github.token }}
RELEASE_NOTES: ${{ steps.changelog.outputs.notes }}
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Publish to crates.io
run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}