name: Publish to crates.io
on:
push:
tags:
- 'v[0-9]*'
concurrency:
group: crates-publish-${{ github.ref_name }}
cancel-in-progress: false
permissions:
contents: read
id-token: write
jobs:
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
environment:
name: crates-io
url: https://crates.io/crates/hotdata
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
- uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 with:
toolchain: stable
- name: Verify tag matches Cargo.toml version
run: |
set -euo pipefail
if [[ ! "$GITHUB_REF_NAME" =~ ^v[0-9] ]]; then
echo "Release tag '$GITHUB_REF_NAME' must start with 'v' followed by a digit (e.g. v1.0.0)" >&2
exit 1
fi
tag="${GITHUB_REF_NAME#v}"
pkg_version=$(cargo metadata --no-deps --format-version 1 \
| jq -r '.packages[] | select(.name=="hotdata") | .version')
if [ "$tag" != "$pkg_version" ]; then
echo "Release tag ($tag) does not match Cargo.toml version ($pkg_version)" >&2
exit 1
fi
- name: Verify package builds (dry run)
run: cargo publish --dry-run --all-features
- name: Authenticate to crates.io (Trusted Publishing)
id: auth
uses: rust-lang/crates-io-auth-action@bbd81622f20ce9e2dd9622e3218b975523e45bbe
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
run: cargo publish --all-features