numr 0.7.0

High-performance numerical computing with multi-backend GPU acceleration (CPU/CUDA/WebGPU)
Documentation
# Manual distribution workflow. Push a v* tag first; `Release Prepare` runs CI
# + benchmarks and packages the crate. Then run this workflow with that tag and
# the successful prepare run ID.
#
# crates.io and the GitHub Release both consume the prepare run's crate
# artifact, so a failed publish or release stage is retried by re-dispatching
# with only that stage enabled — CI and packaging are never rerun to fix a
# crates.io timeout or a bad release body.
#
# Stages:
#   publish_crate   -> crates.io
#   github_release  -> GitHub Release with the .crate attached
#
# Each stage is idempotent: an already-indexed version is skipped, the release
# is overwritten in place. Re-running is safe.
#
# Required secret: CARGO_REGISTRY_TOKEN.

name: Release
run-name: Release ${{ inputs.tag }}

on:
  workflow_dispatch:
    inputs:
      tag:
        description: "Release tag to publish, e.g. v0.7.0"
        required: true
        type: string
      prepare_run_id:
        description: "Successful Release Prepare run ID holding the crate"
        required: true
        type: string
      publish_crate:
        description: "Publish numr to crates.io"
        type: boolean
        default: true
      github_release:
        description: "Create the GitHub Release"
        type: boolean
        default: true

concurrency:
  group: release
  cancel-in-progress: false

permissions:
  contents: read

env:
  CARGO_TERM_COLOR: always

jobs:
  # Always runs. Cheap, and it guarantees the dispatched tag still means what
  # the prepare run assumed it meant.
  validate-version:
    uses: ./.github/workflows/release-validate.yml
    with:
      ref: ${{ inputs.tag }}

  # ── crates.io ────────────────────────────────────────────────────────────
  # numr is a single leaf crate — no publish-order tiers. A verifying publish
  # (no --no-verify) is the strongest guarantee the uploaded tarball builds
  # from a clean checkout under default features.
  publish-crate:
    name: Publish to crates.io
    needs: validate-version
    if: inputs.publish_crate
    runs-on: ubuntu-latest
    environment: crates-io
    steps:
      - uses: actions/checkout@v5
        with:
          ref: ${{ inputs.tag }}

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Set version from tag
        run: bash scripts/ci/stamp_version.sh "${{ needs.validate-version.outputs.version }}"

      - name: Publish numr
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        run: |
          set -euo pipefail
          VERSION=$(cargo metadata --no-deps --format-version=1 \
            | jq -r '.packages[] | select(.name == "numr") | .version')

          is_published() {
            curl -sf \
              -H "User-Agent: numr-ci (github.com/ml-rust/numr)" \
              "https://crates.io/api/v1/crates/numr/$1" > /dev/null 2>&1
          }

          if is_published "$VERSION"; then
            echo "numr@$VERSION already published — skipping"
            exit 0
          fi

          echo "Publishing numr@$VERSION..."
          # --allow-dirty: stamp_version.sh may have edited Cargo.toml for a
          # prerelease tag; the verifying publish still runs.
          cargo publish -p numr --allow-dirty

  # ── GitHub Release ───────────────────────────────────────────────────────
  # Independent of publish-crate: a crates.io outage must not block cutting the
  # release, and re-running this stage alone is the fix for a bad release body.
  github-release:
    name: Create GitHub Release
    needs: validate-version
    if: inputs.github_release
    runs-on: ubuntu-latest
    permissions:
      contents: write
      actions: read
    steps:
      - uses: actions/checkout@v5
        with:
          ref: ${{ inputs.tag }}
          fetch-depth: 0

      # Runs before the download so a wrong, unfinished, or foreign run is
      # rejected without its crate ever reaching the runner.
      - name: Verify prepare run
        env:
          GH_TOKEN: ${{ github.token }}
          PREPARE_RUN_ID: ${{ inputs.prepare_run_id }}
        run: |
          set -euo pipefail
          [[ "$PREPARE_RUN_ID" =~ ^[0-9]+$ ]] || {
            echo "::error::prepare_run_id must be numeric"
            exit 1
          }
          gh api \
            -H "Accept: application/vnd.github+json" \
            -H "X-GitHub-Api-Version: 2022-11-28" \
            "repos/${GITHUB_REPOSITORY}/actions/runs/${PREPARE_RUN_ID}" \
            >"$RUNNER_TEMP/prepare-run.json"
          bash scripts/ci/verify_prepare_run.sh \
            "$RUNNER_TEMP/prepare-run.json" \
            "$(git rev-parse HEAD)"

      - name: Download crate artifact
        uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          name: crate-package
          run-id: ${{ inputs.prepare_run_id }}
          github-token: ${{ github.token }}
          path: ./artifacts

      # The changelog is the release notes. Auto-generated notes list commit
      # subjects, which describe what was done to the code; the changelog
      # describes what changed for the person upgrading. `validate-version`
      # has already proved this section exists and is non-empty.
      - name: Build release notes from the changelog
        env:
          TAG: ${{ inputs.tag }}
          BASE: ${{ needs.validate-version.outputs.base_version }}
        run: |
          set -euo pipefail
          # -l is required: without it git reads 'v*' as a tag to CREATE and
          # errors, which `|| true` then swallows into an empty PREVIOUS_TAG —
          # silently degrading every release to a tree link.
          PREVIOUS_TAG=$(git tag -l 'v*' --sort=-v:refname | grep -v "^${TAG}$" | head -n 1 || true)

          bash scripts/ci/changelog_section.sh "$BASE" /tmp/changelog-section.md

          {
            cat /tmp/changelog-section.md
            echo
            if [[ -n "$PREVIOUS_TAG" ]]; then
              echo "**Full diff:** https://github.com/ml-rust/numr/compare/${PREVIOUS_TAG}...${TAG}"
            else
              echo "**Tree:** https://github.com/ml-rust/numr/tree/${TAG}"
            fi
          } > /tmp/release-notes.md

      - name: Create GitHub Release
        uses: softprops/action-gh-release@3d0d9888cb7fd7b750713d6e236d1fcb99157228 # v3.0.2
        with:
          tag_name: ${{ inputs.tag }}
          name: numr ${{ needs.validate-version.outputs.version }}
          body_path: /tmp/release-notes.md
          draft: false
          prerelease: ${{ needs.validate-version.outputs.is_full_release != 'true' }}
          files: artifacts/*.crate
          fail_on_unmatched_files: true