dejadoc 0.5.0

Find duplicated Rust doctests and functions across a workspace
Documentation
name: Release

on:
  push:
    tags:
      - "v*.*"

permissions:
  contents: read

env:
  CARGO_TERM_COLOR: always

jobs:
  verify-version:
    name: Verify tag matches version
    runs-on: ubuntu-latest
    outputs:
      crate-release: ${{ steps.check.outputs.crate-release }}

    steps:
      - name: Checkout
        uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5

      - name: Check tag against Cargo.toml version
        id: check
        run: |
          tag="${GITHUB_REF_NAME#v}"
          manifest="$(grep -m1 '^version = ' Cargo.toml | sed -E 's/version = "(.*)"/\1/')"
          echo "tag version: $tag"
          echo "manifest version: $manifest"
          if [ "$tag" = "$manifest" ]; then
            echo "crate-release=true" >> "$GITHUB_OUTPUT"
          elif [ "${tag%%.*}" != "${manifest%%.*}" ]; then
            echo "tag $tag is not a crate release tag for version $manifest, skipping" >> "$GITHUB_STEP_SUMMARY"
            echo "crate-release=false" >> "$GITHUB_OUTPUT"
          else
            echo "::error::tag $tag does not match Cargo.toml version $manifest"
            exit 1
          fi

  ci:
    name: CI
    needs: verify-version
    if: needs.verify-version.outputs.crate-release == 'true'
    uses: ./.github/workflows/ci.yml
    secrets: inherit

  publish:
    name: Publish to crates.io
    needs: ci
    runs-on: ubuntu-latest
    permissions:
      contents: read
      id-token: write

    steps:
      - name: Checkout
        uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5

      - name: Install stable toolchain
        uses: dtolnay/rust-toolchain@6bed0761d98439e5a578e2877258200ad565ba87 # stable
        with:
          toolchain: stable

      - name: Authenticate to crates.io
        id: auth
        uses: rust-lang/crates-io-auth-action@c6f97d42243bad5fab37ca0427f495c86d5b1a18 # v1

      - name: Publish syn-canon when its version is new
        run: |
          version="$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name == "syn-canon") | .version')"
          if curl -sf https://index.crates.io/sy/n-/syn-canon | jq -e --arg v "$version" 'select(.vers == $v)' > /dev/null; then
            echo "syn-canon $version is already on crates.io"
          else
            cargo publish --locked -p syn-canon
          fi
        env:
          CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}

      - name: Publish crate
        run: cargo publish --locked -p dejadoc
        env:
          CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}

  create-release:
    name: Create the GitHub release
    needs: ci
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - name: Create or reuse the release
        env:
          GH_TOKEN: ${{ github.token }}
        run: |
          gh release create "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" \
            --verify-tag --generate-notes --title "$GITHUB_REF_NAME" \
            || gh release view "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" >/dev/null

  # Binaries are best effort and independent of publish. A failed target never blocks the
  # crate release, the action falls back to source for a missing asset, and re-running the
  # target completes the release because upload is idempotent.
  binaries:
    name: Build ${{ matrix.target }}
    needs: create-release
    permissions:
      contents: write
    strategy:
      fail-fast: false
      matrix:
        # Keep this target list in sync with the platform case in action.yml.
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-24.04-arm
          - target: x86_64-apple-darwin
            os: macos-latest
          - target: aarch64-apple-darwin
            os: macos-latest
          - target: x86_64-pc-windows-msvc
            os: windows-latest
    runs-on: ${{ matrix.os }}
    steps:
      - name: Checkout
        uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5

      - name: Install stable toolchain
        uses: dtolnay/rust-toolchain@6bed0761d98439e5a578e2877258200ad565ba87 # stable
        with:
          toolchain: stable
          targets: ${{ matrix.target }}

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

      - name: Package and upload the binary
        shell: bash
        env:
          GH_TOKEN: ${{ github.token }}
        run: |
          set -euo pipefail
          bin=cargo-dejadoc
          [ "$RUNNER_OS" = "Windows" ] && bin=cargo-dejadoc.exe
          asset="cargo-dejadoc-${{ matrix.target }}.tar.gz"
          tar -czf "$asset" -C "target/${{ matrix.target }}/release" "$bin"
          gh release upload "$GITHUB_REF_NAME" "$asset" --repo "$GITHUB_REPOSITORY" --clobber