u-geometry 0.1.1

Domain-agnostic computational geometry: primitives, polygons, NFP, collision detection, spatial indexing.
Documentation
name: Release

on:
  push:
    branches: [main]
    paths:
      - 'Cargo.toml'
  workflow_dispatch:
    inputs:
      force:
        description: 'Force publish even if version unchanged'
        required: false
        default: 'true'
        type: boolean

env:
  CARGO_TERM_COLOR: always

jobs:
  check-version:
    name: Check Version Change
    runs-on: ubuntu-latest
    outputs:
      version: ${{ steps.get_version.outputs.version }}
      changed: ${{ steps.check.outputs.changed }}
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 2

      - name: Get current version
        id: get_version
        run: |
          VERSION=$(grep -m1 'version = ' Cargo.toml | sed 's/version = "\(.*\)"/\1/')
          echo "version=$VERSION" >> $GITHUB_OUTPUT
          echo "Current version: $VERSION"

      - name: Check if version is unpublished on crates.io
        id: check
        # Compare against the registry, not "git diff HEAD~1": a multi-commit
        # push whose last commit lacks the version bump silently skipped
        # publishing (u-routing 0.2.3 incident).
        run: |
          CRATE=$(grep -m1 '^name = ' Cargo.toml | sed 's/name = "\(.*\)"/\1/')
          VERSION=${{ steps.get_version.outputs.version }}
          HTTP=$(curl -s -o /dev/null -w '%{http_code}' -H "User-Agent: ${CRATE}-ci/1.0" "https://crates.io/api/v1/crates/${CRATE}/${VERSION}")
          if [ "$HTTP" = "200" ]; then
            echo "changed=false" >> $GITHUB_OUTPUT
            echo "${CRATE} ${VERSION} already on crates.io — skipping"
          else
            echo "changed=true" >> $GITHUB_OUTPUT
            echo "${CRATE} ${VERSION} not on crates.io (HTTP ${HTTP}) — will publish"
          fi

  publish:
    name: Publish to crates.io
    needs: check-version
    if: needs.check-version.outputs.changed == 'true' || github.event_name == 'workflow_dispatch'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

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

      - name: Publish
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        # No "|| true": a failed publish must fail the run. The check-version
        # gate (crates.io API) already prevents same-version re-publish.
        run: cargo publish --allow-dirty