northroot-proof-engine 0.3.2

Core proof computation and validation library for PoSH (Proof of Shape) and PoX (Proof of Execution)
Documentation
name: Rust Publish

on:
  workflow_call:
    inputs:
      crate_name:
        description: 'Name of the crate (for release title)'
        required: true
        type: string
      features:
        description: 'Cargo features to use'
        required: false
        type: string
        default: '--all-features'
      toolchain:
        description: 'Rust toolchain version'
        required: false
        type: string
        default: 'stable'
    secrets:
      CRATES_IO_TOKEN:
        required: true
      # GITHUB_TOKEN is automatically available, no need to pass it

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@master
        with:
          toolchain: ${{ inputs.toolchain }}

      - 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 ${{ inputs.features }} --verbose

      - name: Check formatting
        run: cargo fmt --all -- --check

      - name: Run clippy
        run: cargo clippy --all-targets ${{ inputs.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: |
          if [ -z "$CARGO_REGISTRY_TOKEN" ]; then
            echo "❌ Error: CRATES_IO_TOKEN secret is not set or empty"
            echo "Please configure CRATES_IO_TOKEN in repository or organization secrets"
            exit 1
          fi
          echo "Publishing to crates.io..."
          cargo publish || {
            echo "❌ Failed to publish to crates.io"
            echo "Check that:"
            echo "  1. CRATES_IO_TOKEN is valid"
            echo "  2. Version hasn't been published before"
            echo "  3. All dependencies are available"
            exit 1
          }
          echo "✅ Successfully published to crates.io"

      - name: Create GitHub Release
        uses: softprops/action-gh-release@v1
        with:
          tag_name: ${{ github.ref }}
          name: "${{ inputs.crate_name }} v${{ steps.get_version.outputs.version }}"
          body: |
            Release of ${{ inputs.crate_name }} v${{ steps.get_version.outputs.version }}

            See [CHANGELOG.md](CHANGELOG.md) for details.
          files: |
            target/package/${{ inputs.crate_name }}-*.crate
          draft: false
          prerelease: false
        env:
          GITHUB_TOKEN: ${{ github.token }}