name: Release
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
inputs:
publish:
description: "Publish to crates.io"
required: true
default: "false"
type: choice
options:
- "false"
- "true"
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: -Dwarnings
jobs:
publish:
name: Publish crate
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.88.0
components: rustfmt, clippy
- name: Cache cargo
uses: Swatinem/rust-cache@v2
- name: Check version matches tag
if: startsWith(github.ref, 'refs/tags/v')
shell: bash
run: |
crate_version="$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')"
tag_version="${GITHUB_REF_NAME#v}"
if [ "$crate_version" != "$tag_version" ]; then
echo "Cargo.toml version $crate_version does not match tag $GITHUB_REF_NAME"
exit 1
fi
- name: Check formatting
run: cargo fmt --all -- --check
- name: Clippy
run: cargo clippy --locked --all-targets -- -D warnings
- name: Test
run: cargo test --locked --all-targets
- name: Package dry run
run: cargo publish --locked --dry-run
- name: Publish
if: startsWith(github.ref, 'refs/tags/v') || github.event.inputs.publish == 'true'
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish --locked