name: Publish
on:
release:
types: [created]
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: "-D warnings"
jobs:
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Check package version
if: github.event_name == 'release'
run: |
VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)
TAG=${GITHUB_REF#refs/tags/}
if [ "v$VERSION" != "$TAG" ]; then
echo "Package version ($VERSION) does not match release tag ($TAG)"
exit 1
fi
- name: Verify Cargo.toml
run: |
if ! grep -q 'license = "MIT"' Cargo.toml; then
echo "License must be specified in Cargo.toml"
exit 1
fi
if ! grep -q 'description = ' Cargo.toml; then
echo "Description must be specified in Cargo.toml"
exit 1
fi
if ! grep -q 'repository = ' Cargo.toml; then
echo "Repository must be specified in Cargo.toml"
exit 1
fi
- name: Run tests
run: nix develop --command cargo test --features full
- name: Run doc tests
run: nix develop --command cargo test --doc
- name: Check formatting
run: nix develop --command cargo fmt --all -- --check
- name: Run clippy
run: nix develop --command cargo clippy --features full -- -D warnings
- name: Publish dry run
run: nix develop --command cargo publish --dry-run
- name: Publish to crates.io
run: nix develop --command cargo publish --no-verify
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}