name: CI
on:
push:
branches: [main]
tags: ['v*']
pull_request:
branches: [main]
env:
CARGO_TERM_COLOR: always
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: rustup show
- uses: Swatinem/rust-cache@v2
- run: cargo fmt --check
- run: cargo clippy -- -D warnings
- run: cargo test
- name: Install cargo-audit
run: cargo install cargo-audit
- name: Security audit
run: cargo audit
- run: cargo build --release
build-macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- run: rustup show
- uses: Swatinem/rust-cache@v2
- run: cargo build --release
publish:
needs: [check, build-macos]
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_TOKEN }}
steps:
- uses: actions/checkout@v4
- run: rustup show
- uses: Swatinem/rust-cache@v2
- run: cargo publish --allow-dirty
release:
needs: [check, build-macos, publish]
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Extract changelog for this version
id: changelog
run: |
TAG="${GITHUB_REF#refs/tags/}"
# Extract the section between this version header and the next one
awk "/^## \\[${TAG#v}\\]/{found=1; next} /^## \\[/{if(found) exit} found{print}" CHANGELOG.md > release_notes.md
# Fallback if no matching section found
if [ ! -s release_notes.md ]; then
echo "No changelog entry found for ${TAG}" > release_notes.md
fi
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
body_path: release_notes.md
generate_release_notes: false