vision-squeezer 0.8.1

Fit images to a vision-LLM token budget before you send them. Library, CLI and MCP server for code, agents and pipelines.
Documentation
name: Release

on:
  push:
    tags:
      - 'v*'

# A tag is immutable, so a re-tag should cancel any in-flight build for the
# same ref instead of running both to completion.
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

env:
  CARGO_TERM_COLOR: always

jobs:
  build:
    name: Build ${{ matrix.target }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        include:
          - os: macos-latest
            target: aarch64-apple-darwin
            binary: vision-squeezer-mcp
            asset: vision-squeezer-mcp-macos-arm64
          - os: macos-15-intel
            target: x86_64-apple-darwin
            binary: vision-squeezer-mcp
            asset: vision-squeezer-mcp-macos-x86_64
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            binary: vision-squeezer-mcp
            asset: vision-squeezer-mcp-linux-x86_64
          - os: ubuntu-latest
            target: aarch64-unknown-linux-gnu
            binary: vision-squeezer-mcp
            asset: vision-squeezer-mcp-linux-arm64
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            binary: vision-squeezer-mcp.exe
            asset: vision-squeezer-mcp-windows-x86_64.exe
          - os: windows-latest
            target: aarch64-pc-windows-msvc
            binary: vision-squeezer-mcp.exe
            asset: vision-squeezer-mcp-windows-arm64.exe

    steps:
      - uses: actions/checkout@v5
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}
      - uses: Swatinem/rust-cache@v2

      - name: Install cross-compiler (Linux arm64)
        if: matrix.target == 'aarch64-unknown-linux-gnu'
        run: |
          sudo apt-get update
          sudo apt-get install -y gcc-aarch64-linux-gnu

      - name: Build
        env:
          CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
        run: cargo build --release --bin vision-squeezer-mcp --target ${{ matrix.target }}

      - name: Upload artifact
        uses: actions/upload-artifact@v5
        with:
          name: ${{ matrix.asset }}
          path: target/${{ matrix.target }}/release/${{ matrix.binary }}
          if-no-files-found: error
          # Artifacts are only needed long enough for the `release` job to pull
          # them and attach to the GitHub Release. The default 90-day retention
          # wastes storage quota — 7 days is well past any retry window.
          retention-days: 7

  # GitHub Release + crates.io + npm in a single runner. Each individual
  # publish step is well under a minute; running them in one job saves the
  # ~30s × 2 runner spin-ups vs the old three-job split, and lets npm's
  # postinstall safely find the freshly-attached GH release binaries
  # (npm publish only happens after `gh release` attaches assets).
  #
  # Step order matters: cargo publish runs BEFORE artifact download so its
  # dirty-tree check sees a clean working directory. Downloading artifacts
  # first leaves `artifacts/` and `dist/` as untracked files and cargo
  # refuses to publish without `--allow-dirty`.
  publish:
    name: Publish (GitHub Release + crates.io + npm)
    needs: build
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v5

      - uses: dtolnay/rust-toolchain@stable
      - uses: Swatinem/rust-cache@v2

      - name: Publish to crates.io (skip if version exists)
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        # `--locked` forbids cargo from regenerating Cargo.lock during
        # publish (which would dirty the working tree and trip the
        # built-in cleanliness check). The lockfile must be committed
        # in sync with Cargo.toml — bump both in every version commit.
        run: |
          set +e
          OUTPUT=$(cargo publish --locked 2>&1)
          STATUS=$?
          echo "$OUTPUT"
          if [ $STATUS -ne 0 ] && echo "$OUTPUT" | grep -q "already exists"; then
            echo "Version already on crates.io — skipping."
            exit 0
          fi
          exit $STATUS

      - uses: actions/setup-node@v5
        with:
          node-version: '24'
          registry-url: 'https://registry.npmjs.org'

      - name: Download all artifacts
        uses: actions/download-artifact@v5
        with:
          path: artifacts/

      - name: Rename binaries
        run: |
          mkdir -p dist
          for dir in artifacts/*/; do
            name=$(basename "$dir")
            src="${dir}vision-squeezer-mcp.exe"
            [ -f "$src" ] || src="${dir}vision-squeezer-mcp"
            cp "$src" "dist/${name}"
          done

      - name: Extract changelog for this version
        id: changelog
        run: |
          VERSION="${GITHUB_REF_NAME#v}"
          BODY=$(awk "/^## \[${VERSION}\]/{found=1; next} found && /^## \[/{exit} found{print}" CHANGELOG.md)
          echo "body<<EOF" >> "$GITHUB_OUTPUT"
          echo "$BODY" >> "$GITHUB_OUTPUT"
          echo "EOF" >> "$GITHUB_OUTPUT"

      - name: Upload to GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          files: dist/vision-squeezer-mcp-*
          body: ${{ steps.changelog.outputs.body }}

      - name: Publish to npm
        run: npm publish --access public
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}