lattice 0.2.0

A markdown predicate linter and backlink reconciler, shipped as an LSP server.
Documentation
# Release — on a vX.Y.Z tag push:
#   1. verify        the tag matches Cargo.toml's version
#   2. build         cross-platform binaries on the self-hosted fleet
#   3. publish-crate to crates.io via Trusted Publishing (OIDC — no stored token)
#   4. release       cut a GitHub Release with the binaries attached
#
# Triggered ONLY by tag pushes, which require write access — a fork PR can never
# trigger this, so it is safe to run on the persistent Windows/macOS runners
# (the publish credential is never exposed to untrusted code).
#
# This is the first workflow to create GitHub Releases; v0.1.0 was tagged before
# it existed (a pre-history crates.io name-grab), so v0.2.0 is the first Release.
#
# One-time setup before the first successful run:
#   - crates.io  → crate Settings → Trusted Publishing → add repo TwoWells/Lattice
#                  and workflow file `release.yml`.
#   - macOS      → register the M2 Max runner (labels: self-hosted,macos,arm64).
#   - Runner provisioning: rustup everywhere; MSVC Build Tools on Windows;
#                  Xcode Command Line Tools on macOS; cc/gcc on Linux.
name: Release

on:
  push:
    tags: ['v*']

permissions:
  contents: write # create the GitHub Release
  id-token: write # OIDC token for crates.io Trusted Publishing

jobs:
  # Guard: a pushed tag whose version disagrees with Cargo.toml is a mistake.
  verify:
    runs-on: homeserver-pool
    outputs:
      version: ${{ steps.v.outputs.version }}
    steps:
      - uses: actions/checkout@v6
      - id: v
        name: Tag must match Cargo.toml version
        run: |
          tag="${GITHUB_REF_NAME#v}"
          manifest="$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')"
          echo "tag=$tag  manifest=$manifest"
          if [ "$tag" != "$manifest" ]; then
            echo "::error::tag v$tag does not match Cargo.toml version $manifest"
            exit 1
          fi
          echo "version=$tag" >> "$GITHUB_OUTPUT"

  # Native build on each platform's own runner. fail-fast: false so one
  # platform's failure doesn't cancel the others.
  build:
    needs: verify
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            runner: homeserver-pool
            container: ghcr.io/twowells/rust-ci:latest
            archive: tar
          - target: x86_64-pc-windows-msvc
            runner: [self-hosted, windows, x64]
            archive: zip
          - target: aarch64-apple-darwin
            runner: [self-hosted, macos, arm64]
            archive: tar
    runs-on: ${{ matrix.runner }}
    # Linux builds inside the rust-ci image (bare ARC pod). Windows/macOS define
    # no matrix container, so this evaluates empty and they build natively on the
    # VM / M2 Max, which carry their own MSVC / Xcode toolchains.
    container: ${{ matrix.container }}
    steps:
      - uses: actions/checkout@v6

      - name: Materialize Rust toolchain
        run: |
          rustup show
          rustup target add ${{ matrix.target }}

      - name: Build release binary
        run: cargo build --release --locked --target ${{ matrix.target }}

      - name: Package (tar.gz)
        if: matrix.archive == 'tar'
        shell: bash
        run: |
          mkdir -p dist
          tar -C "target/${{ matrix.target }}/release" -czf \
            "dist/lattice-${{ matrix.target }}.tar.gz" lattice

      - name: Package (zip)
        if: matrix.archive == 'zip'
        shell: pwsh
        run: |
          New-Item -ItemType Directory -Force dist | Out-Null
          Compress-Archive -Force `
            -Path "target/${{ matrix.target }}/release/lattice.exe" `
            -DestinationPath "dist/lattice-${{ matrix.target }}.zip"

      - uses: actions/upload-artifact@v7
        with:
          name: lattice-${{ matrix.target }}
          path: dist/*

  # Publish to crates.io. Idempotent: skips if this version is already live, so
  # a re-run (or a re-pushed tag) is a harmless no-op rather than a hard failure.
  publish-crate:
    needs: verify
    runs-on: homeserver-pool
    # Bare ARC pod → run in the toolchain image (cargo publish + the curl guard).
    container: ghcr.io/twowells/rust-ci:latest
    # Container default shell is sh (dash); force bash for the guard/publish steps.
    defaults:
      run:
        shell: bash
    # Must match the Environment name registered in crates.io Trusted Publishing.
    # Scopes the OIDC token subject to this environment (tighter trust binding)
    # and gives you a hook for required-reviewer / tag protection rules later.
    # Create it under Settings -> Environments to attach those rules; otherwise
    # GitHub auto-creates it (unprotected) on first run.
    environment: release
    steps:
      - uses: actions/checkout@v6

      - name: Materialize Rust toolchain
        run: rustup show

      - name: Skip if version already on crates.io
        id: guard
        run: |
          v="${{ needs.verify.outputs.version }}"
          # Query the sparse index, NOT /api/v1 — the API 403s requests without a
          # descriptive User-Agent, but the index enforces no such policy.
          # Path layout for a name >= 4 chars: <chars 1-2>/<chars 3-4>/<name>.
          # `|| true` tolerates the 404 a never-yet-published crate returns.
          idx="$(curl -fsS https://index.crates.io/la/tt/lattice || true)"
          if printf '%s\n' "$idx" | grep -q "\"vers\":\"$v\""; then
            echo "lattice $v is already published — skipping."
            echo "already=1" >> "$GITHUB_OUTPUT"
          fi

      # OIDC: exchanges the GitHub id-token for a short-lived crates.io token.
      # Nothing long-lived is stored in secrets or on the runner.
      - name: Authenticate to crates.io (Trusted Publishing)
        if: steps.guard.outputs.already != '1'
        id: auth
        uses: rust-lang/crates-io-auth-action@v1

      - name: cargo publish
        if: steps.guard.outputs.already != '1'
        run: cargo publish --locked
        env:
          CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}

  release:
    needs: [verify, build, publish-crate]
    runs-on: homeserver-pool
    steps:
      - uses: actions/download-artifact@v8
        with:
          path: dist
          merge-multiple: true

      - uses: softprops/action-gh-release@v3
        with:
          tag_name: ${{ github.ref_name }}
          name: v${{ needs.verify.outputs.version }}
          generate_release_notes: true
          files: dist/*