name: Publish to crates.io
on:
push:
tags:
- "v*"
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
RUSTDOCFLAGS: -D warnings
jobs:
publish:
runs-on: ubuntu-latest
environment: crates-io
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 - uses: dtolnay/rust-toolchain@fa04a1451ff1842e2626ccb99004d0195b455a88 with:
toolchain: stable
components: rustfmt, clippy
- name: Verify tag matches Cargo.toml version
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 "::error::Tag ${GITHUB_REF_NAME} (${tag_version}) does not match Cargo.toml version ${crate_version}"
exit 1
fi
- name: Format
run: cargo fmt --all -- --check
- name: Lint
run: |
cargo clippy --locked --all-targets -- -D warnings
cargo clippy --locked --no-default-features --all-targets -- -D warnings
- name: Test
run: |
cargo test --locked
cargo test --locked --no-default-features
- name: Docs
run: cargo doc --locked --no-deps
- name: Read MSRV from Cargo.toml
id: msrv
run: echo "msrv=$(grep -m1 '^rust-version' Cargo.toml | cut -d'"' -f2)" >> "$GITHUB_OUTPUT"
- uses: dtolnay/rust-toolchain@fa04a1451ff1842e2626ccb99004d0195b455a88 with:
toolchain: ${{ steps.msrv.outputs.msrv }}
- name: Check on MSRV
run: |
cargo +${{ steps.msrv.outputs.msrv }} check --locked --all-features
cargo +${{ steps.msrv.outputs.msrv }} check --locked --no-default-features
- name: Publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_API_TOKEN }}
run: cargo +stable publish --locked