name: Publish to crates.io and GitHub
on:
push:
tags:
- "v*"
jobs:
publish:
name: Publish crate
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Run tests
run: cargo test --all-features --verbose
- name: Check formatting
run: cargo fmt --all -- --check
- name: Run clippy
run: cargo clippy --all-targets --all-features -- -D warnings
- name: Extract version from tag
id: get_version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Extracted version: $VERSION"
- name: Verify version matches Cargo.toml
run: |
CARGO_VERSION=$(grep '^version = ' Cargo.toml | cut -d'"' -f2)
TAG_VERSION="${{ steps.get_version.outputs.version }}"
if [ "$CARGO_VERSION" != "$TAG_VERSION" ]; then
echo "Error: Cargo.toml version ($CARGO_VERSION) does not match tag version ($TAG_VERSION)"
exit 1
fi
echo "Version verified: $CARGO_VERSION"
- name: Package crate
run: cargo package --allow-dirty
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
run: |
cargo publish --token $CARGO_REGISTRY_TOKEN
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.ref }}
name: "northroot-proof-engine v${{ steps.get_version.outputs.version }}"
body: |
Release of northroot-proof-engine v${{ steps.get_version.outputs.version }}
See [CHANGELOG.md](CHANGELOG.md) for details.
files: |
target/package/northroot-proof-engine-*.crate
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}