# Release. Pushing a v* tag from clean master publishes the crate to crates.io.
# The token lives in the `production`
# environment secret CRATES_API_TOKEN, scoped to this workflow only.
name: Release
on:
push:
tags:
jobs:
publish:
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
# Guard: the tag must match the crate version (v1.2.3 == version = "1.2.3").
- name: Verify tag matches Cargo.toml version
run: |
CRATE_VERSION="$(grep -m1 '^version = ' Cargo.toml | sed -E 's/.*"([^"]+)".*/\1/')"
TAG_VERSION="${GITHUB_REF_NAME#v}"
if [ "$CRATE_VERSION" != "$TAG_VERSION" ]; then
echo "tag $GITHUB_REF_NAME != Cargo.toml version $CRATE_VERSION" >&2
exit 1
fi
- name: Publish to crates.io
run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_API_TOKEN }}