name: Release
on:
push:
tags:
- "v*.*.*"
branches: [ main ]
pull_request:
branches: [ main ]
env:
CARGO_TERM_COLOR: always
jobs:
build:
name: Build & test (${{ matrix.os }})
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Build
run: cargo build --release --verbose -j 2
- name: Test
run: cargo test --verbose
release:
name: Create GitHub Release
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Create release
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
publish:
name: Publish to crates.io
needs: build
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- name: Verify Cargo.toml version matches tag
shell: bash
run: |
TAG_VERSION="${GITHUB_REF_NAME#v}"
CRATE_VERSION=$(grep -m1 '^version' Cargo.toml | sed -E 's/version = "(.*)"/\1/')
echo "Tag version: $TAG_VERSION / Crate version: $CRATE_VERSION"
if [ "$TAG_VERSION" != "$CRATE_VERSION" ]; then
echo "::error::Tag ($TAG_VERSION) and Cargo.toml version ($CRATE_VERSION) do not match"
exit 1
fi
- name: cargo publish (dry run)
run: cargo publish --dry-run
- name: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish