whetstone-cli 2.0.0

Installer and CLI for Claude Code token optimization (Headroom + RTK + MemStack)
name: Release

on:
  push:
    branches: [main]
    paths: [VERSION]
  workflow_dispatch:

permissions:
  contents: write

env:
  CARGO_TERM_COLOR: always

jobs:
  check-tag:
    name: Check if release needed
    runs-on: ubuntu-latest
    outputs:
      tag: ${{ steps.version.outputs.tag }}
      needed: ${{ steps.version.outputs.needed }}
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Read version and check tag
        id: version
        run: |
          VERSION=$(cat VERSION | tr -d '[:space:]')
          TAG="v${VERSION}"
          echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
          if git rev-parse "${TAG}" >/dev/null 2>&1; then
            echo "needed=false" >> "$GITHUB_OUTPUT"
            echo "Tag ${TAG} already exists, skipping release"
          else
            echo "needed=true" >> "$GITHUB_OUTPUT"
            echo "Will create release ${TAG}"
          fi

  build:
    name: Build ${{ matrix.target }}
    needs: check-tag
    if: needs.check-tag.outputs.needed == 'true'
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            cross: false
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
            cross: true
          - target: x86_64-apple-darwin
            os: macos-latest
            cross: false
          - target: aarch64-apple-darwin
            os: macos-latest
            cross: false

    steps:
      - uses: actions/checkout@v4

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

      - uses: Swatinem/rust-cache@v2
        with:
          key: ${{ matrix.target }}

      - name: Install cross
        if: matrix.cross
        run: cargo install cross --git https://github.com/cross-rs/cross

      - name: Build
        run: |
          if [ "${{ matrix.cross }}" = "true" ]; then
            cross build --release --target ${{ matrix.target }}
          else
            cargo build --release --target ${{ matrix.target }}
          fi

      - name: Package
        run: |
          cd target/${{ matrix.target }}/release
          tar czf ../../../whetstone-${{ matrix.target }}.tar.gz whetstone
          cd ../../..

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: whetstone-${{ matrix.target }}
          path: whetstone-${{ matrix.target }}.tar.gz

  assets:
    name: Package assets
    needs: check-tag
    if: needs.check-tag.outputs.needed == 'true'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Package assets
        run: tar czf whetstone-assets.tar.gz -C assets .

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: whetstone-assets
          path: whetstone-assets.tar.gz

  release:
    name: Create Release
    needs: [check-tag, build, assets]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Create tag
        run: |
          git tag ${{ needs.check-tag.outputs.tag }}
          git push origin ${{ needs.check-tag.outputs.tag }}

      - uses: actions/download-artifact@v4
        with:
          merge-multiple: true

      - name: Create GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ needs.check-tag.outputs.tag }}
          generate_release_notes: true
          files: whetstone-*.tar.gz

  publish-crate:
    name: Publish to crates.io
    needs: [check-tag, release]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: dtolnay/rust-toolchain@stable

      - uses: Swatinem/rust-cache@v2

      - name: Publish
        run: cargo publish
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}