agentdiff 0.1.16

Audit and trace autonomous AI code contributions in git repositories
name: release

on:
  push:
    tags:
      - "v*"

permissions:
  contents: write

jobs:
  verify:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Verify tag matches Cargo.toml version
        shell: bash
        run: |
          set -euo pipefail
          tag_version="${GITHUB_REF_NAME#v}"
          crate_version="$(python3 -c 'import tomllib; print(tomllib.load(open("Cargo.toml","rb"))["package"]["version"])')"
          if [[ "$tag_version" != "$crate_version" ]]; then
            echo "Tag version ($tag_version) does not match Cargo.toml version ($crate_version)." >&2
            exit 1
          fi

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

      - name: Setup Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.11"

      - name: Cargo test
        run: cargo test --locked

      - name: Python unit tests
        run: python3 -m unittest discover -s scripts/tests -p "test_*.py"

      - name: Build debug binaries
        run: cargo build --locked

      - name: MCP smoke test
        run: python3 scripts/mcp-smoke-test.py

  build:
    needs: verify
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            ext: ""
            archive: tar.gz
          - os: macos-14
            target: x86_64-apple-darwin
            ext: ""
            archive: tar.gz
          - os: macos-14
            target: aarch64-apple-darwin
            ext: ""
            archive: tar.gz
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            ext: ".exe"
            archive: zip
    runs-on: ${{ matrix.os }}
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}

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

      - name: Package unix artifacts
        if: matrix.archive == 'tar.gz'
        shell: bash
        run: |
          set -euo pipefail
          VERSION="${GITHUB_REF_NAME}"
          mkdir -p dist/package
          cp "target/${{ matrix.target }}/release/agentdiff${{ matrix.ext }}" dist/package/
          cp "target/${{ matrix.target }}/release/agentdiff-mcp${{ matrix.ext }}" dist/package/
          tar -C dist/package -czf "dist/agentdiff-${VERSION}-${{ matrix.target }}.tar.gz" .

      - name: Package windows artifacts
        if: matrix.archive == 'zip'
        shell: pwsh
        run: |
          $Version = "${env:GITHUB_REF_NAME}"
          New-Item -ItemType Directory -Force -Path dist/package | Out-Null
          Copy-Item "target/${{ matrix.target }}/release/agentdiff${{ matrix.ext }}" "dist/package/"
          Copy-Item "target/${{ matrix.target }}/release/agentdiff-mcp${{ matrix.ext }}" "dist/package/"
          Compress-Archive -Path "dist/package/*" -DestinationPath "dist/agentdiff-$Version-${{ matrix.target }}.zip" -Force

      - name: Upload build artifact
        uses: actions/upload-artifact@v4
        with:
          name: release-${{ matrix.target }}
          path: dist/*

  checksums:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - name: Download artifacts
        uses: actions/download-artifact@v4
        with:
          pattern: release-*
          path: dist
          merge-multiple: true

      - name: Generate SHA256SUMS
        run: |
          set -euo pipefail
          cd dist
          sha256sum agentdiff-* > SHA256SUMS

      - name: Upload checksums
        uses: actions/upload-artifact@v4
        with:
          name: release-checksums
          path: dist/SHA256SUMS

  github-release:
    needs: [build, checksums]
    runs-on: ubuntu-latest
    steps:
      - name: Download artifacts
        uses: actions/download-artifact@v4
        with:
          path: dist

      - name: Flatten artifact tree
        run: |
          set -euo pipefail
          mkdir -p release
          find dist -type f \( -name "agentdiff-*" -o -name "SHA256SUMS" \) -exec cp {} release/ \;
          ls -la release

      - name: Publish GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          files: |
            release/agentdiff-*
            release/SHA256SUMS

  publish-crate:
    needs: verify
    runs-on: ubuntu-latest
    env:
      CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
    steps:
      - name: Checkout
        uses: actions/checkout@v4

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

      - name: Publish to crates.io
        shell: bash
        run: |
          set -euo pipefail
          if [[ -z "${CARGO_REGISTRY_TOKEN:-}" ]]; then
            echo "CARGO_REGISTRY_TOKEN is not set; skipping crates.io publish."
            exit 0
          fi

          set +e
          publish_output="$(cargo publish --locked 2>&1)"
          publish_status=$?
          set -e

          echo "$publish_output"

          if [[ $publish_status -ne 0 ]]; then
            if grep -q "already exists on crates.io index" <<<"$publish_output"; then
              echo "crate version already published; skipping."
              exit 0
            fi
            exit $publish_status
          fi