echoes 0.10.2

Find duplicated Rust doctests, functions and contexts
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-26.04
    outputs:
      crate-release: ${{ steps.check.outputs.crate-release }}

    steps:
      - name: Checkout
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          persist-credentials: false

      - 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

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

    steps:
      - name: Checkout
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          persist-credentials: false

      - name: Install stable toolchain
        uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # master
        with:
          toolchain: stable

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

      # The first version of a crate is published by hand, since crates.io trusts a publisher
      # only for a crate that exists, so a version already on crates.io is skipped.
      - name: Publish each crate whose version is new
        run: |
          for name in syn-canon echoes; do
            version="$(cargo metadata --no-deps --format-version 1 | jq -r --arg n "$name" '.packages[] | select(.name == $n) | .version')"
            case "${#name}" in
              1) path="1/$name" ;;
              2) path="2/$name" ;;
              3) path="3/${name:0:1}/$name" ;;
              *) path="${name:0:2}/${name:2:2}/$name" ;;
            esac
            if curl -sf "https://index.crates.io/$path" | jq -e --arg v "$version" 'select(.vers == $v)' > /dev/null; then
              echo "$name $version is already on crates.io"
            else
              cargo publish --locked -p "$name"
            fi
          done
        env:
          CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}

  create-release:
    name: Create the GitHub release
    needs: ci
    runs-on: ubuntu-26.04
    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-26.04
          - 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@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          persist-credentials: false

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

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

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