name: Publish
on:
push:
tags: ['v*']
jobs:
publish:
runs-on: ubuntu-latest
environment: crates
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo test
- name: Fail if the tag and Cargo.toml disagree
run: |
TAG="${GITHUB_REF_NAME#v}"
PKG=$(grep -m1 '^version' Cargo.toml | cut -d'"' -f2)
[ "$TAG" = "$PKG" ] || { echo "tag $TAG != Cargo.toml $PKG"; exit 1; }
- uses: rust-lang/crates-io-auth-action@v1
id: auth
- run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}