name: Publish
on:
push:
tags:
- "v*"
jobs:
publish:
runs-on: ubuntu-latest
environment: crates-io
permissions:
contents: read
id-token: write
steps:
- name: Check out repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 with:
toolchain: stable
components: rustfmt, clippy
- name: Cache Rust build artifacts
uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4
- name: Check formatting
run: cargo fmt --check
- name: Run Clippy
run: cargo clippy --locked --all-targets -- -D warnings
- name: Run tests
run: cargo test --locked
- name: Verify tag matches crate version
run: |
version="$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')"
tag="${GITHUB_REF_NAME#v}"
if [ "$version" != "$tag" ]; then
echo "Tag v$tag does not match crate version $version"
exit 1
fi
- name: Package crate
run: cargo package --locked
- name: Authenticate with crates.io
id: auth
uses: rust-lang/crates-io-auth-action@b7e9a28eded4986ec6b1fa40eeee8f8f165559ec
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
run: cargo publish --locked