cx-cli 0.7.0

Semantic code navigation for AI agents
name: Release

on:
  push:
    tags:
      - "v*"

permissions:
  contents: write
  id-token: write

jobs:
  build:
    strategy:
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
          - target: x86_64-apple-darwin
            os: macos-latest
          - target: aarch64-apple-darwin
            os: macos-latest
          - target: x86_64-pc-windows-msvc
            os: windows-latest
          - target: aarch64-pc-windows-msvc
            os: windows-latest
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}
      - name: Install cross-compilation tools
        if: matrix.target == 'aarch64-unknown-linux-gnu'
        run: |
          sudo apt-get update
          sudo apt-get install -y gcc-aarch64-linux-gnu
          echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
      - uses: Swatinem/rust-cache@v2
      - run: cargo build --release --target ${{ matrix.target }}
      - name: Package (Unix)
        if: runner.os != 'Windows'
        shell: bash
        run: |
          cd target/${{ matrix.target }}/release
          tar czf ../../../cx-${{ matrix.target }}.tar.gz cx
          cd ../../..
      - name: Package (Windows)
        if: runner.os == 'Windows'
        shell: pwsh
        run: |
          Compress-Archive -Path "target/${{ matrix.target }}/release/cx.exe" -DestinationPath "cx-${{ matrix.target }}.zip"
      - uses: actions/upload-artifact@v4
        with:
          name: cx-${{ matrix.target }}
          path: cx-${{ matrix.target }}.*

  release:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/download-artifact@v4
        with:
          merge-multiple: true
      - name: Create release
        uses: softprops/action-gh-release@v2
        with:
          generate_release_notes: true
          files: |
            cx-*.tar.gz
            cx-*.zip

  publish-crate:
    needs: release
    runs-on: ubuntu-latest
    environment: crates-io
    permissions:
      id-token: write
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - name: Authenticate with crates.io
        uses: rust-lang/crates-io-auth-action@v1
        id: auth
      - run: cargo publish
        env:
          CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}

  update-homebrew:
    needs: release
    runs-on: ubuntu-latest
    steps:
      - name: Get version and compute SHA256s
        id: info
        run: |
          VERSION="${GITHUB_REF_NAME#v}"
          BASE="https://github.com/ind-igo/cx/releases/download/${GITHUB_REF_NAME}"
          for pair in \
            "arm:cx-aarch64-apple-darwin.tar.gz" \
            "x86:cx-x86_64-apple-darwin.tar.gz" \
            "linux:cx-x86_64-unknown-linux-gnu.tar.gz" \
            "linux_arm:cx-aarch64-unknown-linux-gnu.tar.gz"; do
            key="${pair%%:*}"
            file="${pair#*:}"
            curl -sLf -o "/tmp/${file}" "${BASE}/${file}"
            sha=$(sha256sum "/tmp/${file}" | cut -d' ' -f1)
            echo "${key}_sha=$sha" >> "$GITHUB_OUTPUT"
          done
          echo "version=$VERSION" >> "$GITHUB_OUTPUT"
      - name: Update Homebrew tap
        env:
          TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
        run: |
          VERSION="${{ steps.info.outputs.version }}"
          TAG="${GITHUB_REF_NAME}"
          ARM_SHA="${{ steps.info.outputs.arm_sha }}"
          X86_SHA="${{ steps.info.outputs.x86_sha }}"
          LINUX_SHA="${{ steps.info.outputs.linux_sha }}"
          LINUX_ARM_SHA="${{ steps.info.outputs.linux_arm_sha }}"
          BASE="https://github.com/ind-igo/cx/releases/download/${TAG}"

          git clone https://x-access-token:${TAP_TOKEN}@github.com/ind-igo/homebrew-cx.git
          cd homebrew-cx
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"

          printf '%s\n' \
            'class Cx < Formula' \
            '  desc "Semantic code navigation for AI agents"' \
            '  homepage "https://github.com/ind-igo/cx"' \
            "  version \"${VERSION}\"" \
            '  license "MIT"' \
            '' \
            '  on_macos do' \
            '    if Hardware::CPU.arm?' \
            "      url \"${BASE}/cx-aarch64-apple-darwin.tar.gz\"" \
            "      sha256 \"${ARM_SHA}\"" \
            '    else' \
            "      url \"${BASE}/cx-x86_64-apple-darwin.tar.gz\"" \
            "      sha256 \"${X86_SHA}\"" \
            '    end' \
            '  end' \
            '' \
            '  on_linux do' \
            '    if Hardware::CPU.arm?' \
            "      url \"${BASE}/cx-aarch64-unknown-linux-gnu.tar.gz\"" \
            "      sha256 \"${LINUX_ARM_SHA}\"" \
            '    else' \
            "      url \"${BASE}/cx-x86_64-unknown-linux-gnu.tar.gz\"" \
            "      sha256 \"${LINUX_SHA}\"" \
            '    end' \
            '  end' \
            '' \
            '  def install' \
            '    bin.install "cx"' \
            '  end' \
            '' \
            '  test do' \
            '    assert_match version.to_s, shell_output("#{bin}/cx --version")' \
            '  end' \
            'end' > Formula/cx.rb

          git add Formula/cx.rb
          git diff --staged --quiet && exit 0
          git commit -m "cx ${VERSION}"
          git push