name: Release
on:
push:
tags:
- "v*.*.*"
permissions:
contents: write
jobs:
publish:
name: Publish ${{ github.ref_name }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Install Rust toolchain (stable)
uses: dtolnay/rust-toolchain@stable
- name: Install LLVM (rocksdb dev-dep needs llvm-config)
run: sudo apt-get update && sudo apt-get install -y clang libclang-dev
- uses: Swatinem/rust-cache@v2
- name: Run the full test suite
run: cargo test --workspace --all-targets --locked
- name: Verify the tag matches Cargo.toml's version
run: |
TAG="${GITHUB_REF_NAME#v}"
PKG_VERSION=$(cargo metadata --no-deps --format-version 1 \
| python3 -c "import sys, json; print(json.load(sys.stdin)['packages'][0]['version'])")
if [ "$TAG" != "$PKG_VERSION" ]; then
echo "Tag v$TAG does not match Cargo.toml version $PKG_VERSION" >&2
exit 1
fi
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish --locked
- name: Build release notes from CHANGELOG slice
id: changelog
run: |
VERSION="${GITHUB_REF_NAME#v}"
# Pull everything between `## [VERSION]` and the next
# top-level `## [` header out of CHANGELOG.md. `awk` is
# more portable here than `sed` ranges across BSD / GNU.
awk -v v="$VERSION" '
$0 ~ "^## \\[" v "\\]" { p = 1; next }
p && $0 ~ "^## \\[" { exit }
p { print }
' CHANGELOG.md > release_notes.md
echo "notes_path=release_notes.md" >> "$GITHUB_OUTPUT"
- name: Create GitHub Release
uses: softprops/action-gh-release@v3
with:
name: ${{ github.ref_name }}
body_path: ${{ steps.changelog.outputs.notes_path }}
draft: false
prerelease: ${{ contains(github.ref_name, '-') }}