ferryllm 0.2.0

Universal LLM protocol middleware for OpenAI, Anthropic, Claude Code, and OpenAI-compatible backends.
Documentation
name: Release

on:
  push:
    tags:
      - "v*"
  workflow_dispatch:
    inputs:
      tag:
        description: "Release tag, for example v0.1.0"
        required: true
        type: string

permissions:
  contents: write
  id-token: write

env:
  CARGO_TERM_COLOR: always

jobs:
  build:
    name: Build ${{ matrix.target }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            archive: tar.gz
          - os: ubuntu-latest
            target: aarch64-unknown-linux-gnu
            archive: tar.gz
          - os: macos-15-intel
            target: x86_64-apple-darwin
            archive: tar.gz
          - os: macos-14
            target: aarch64-apple-darwin
            archive: tar.gz
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            archive: zip
          - os: windows-latest
            target: aarch64-pc-windows-msvc
            archive: zip

    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          ref: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}

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

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

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

      - name: Configure Linux cross linker
        if: matrix.target == 'aarch64-unknown-linux-gnu'
        run: |
          mkdir -p .cargo
          cat >> .cargo/config.toml <<'EOF'
          [target.aarch64-unknown-linux-gnu]
          linker = "aarch64-linux-gnu-gcc"
          EOF

      - name: Build
        run: cargo build --release --features http --bin ferryllm --target ${{ matrix.target }}

      - name: Package Unix
        if: matrix.archive == 'tar.gz'
        shell: bash
        run: |
          set -euo pipefail
          tag="${GITHUB_REF_NAME}"
          if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
            tag="${{ inputs.tag }}"
          fi
          name="ferryllm-${tag}-${{ matrix.target }}"
          mkdir -p "dist/${name}"
          cp "target/${{ matrix.target }}/release/ferryllm" "dist/${name}/"
          cp README.md README.zh-CN.md LICENSE CHANGELOG.md "dist/${name}/"
          tar -C dist -czf "dist/${name}.tar.gz" "${name}"

      - name: Package Windows
        if: matrix.archive == 'zip'
        shell: pwsh
        run: |
          $tag = $env:GITHUB_REF_NAME
          if ("${{ github.event_name }}" -eq "workflow_dispatch") {
            $tag = "${{ inputs.tag }}"
          }
          $name = "ferryllm-$tag-${{ matrix.target }}"
          New-Item -ItemType Directory -Force -Path "dist/$name" | Out-Null
          Copy-Item "target/${{ matrix.target }}/release/ferryllm.exe" "dist/$name/"
          Copy-Item README.md,README.zh-CN.md,LICENSE,CHANGELOG.md "dist/$name/"
          Compress-Archive -Path "dist/$name" -DestinationPath "dist/$name.zip"

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: ferryllm-${{ matrix.target }}
          path: |
            dist/*.tar.gz
            dist/*.zip
          if-no-files-found: error

  build-desktop:
    name: Build Desktop ${{ matrix.target }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-22.04
            target: x86_64-unknown-linux-gnu
            archive: deb
          - os: macos-14
            target: aarch64-apple-darwin
            archive: dmg
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            archive: msi

    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          ref: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}

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

      - name: Cache cargo
        uses: Swatinem/rust-cache@v2
        with:
          key: desktop-${{ matrix.target }}
          workspaces: |
            .
            desktop/src-tauri

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20

      - name: Install system dependencies (Linux)
        if: matrix.os == 'ubuntu-22.04'
        run: |
          sudo apt-get update
          sudo apt-get install -y \
            libwebkit2gtk-4.1-dev libgtk-3-dev libayatana-appindicator3-dev \
            librsvg2-dev patchelf libssl-dev

      - name: Build ferryllm sidecar
        run: cargo build --release --bin ferryllm --target ${{ matrix.target }}

      - name: Copy sidecar to desktop binaries
        shell: bash
        run: |
          mkdir -p desktop/src-tauri/binaries
          target_triple="${{ matrix.target }}"
          if [[ "$target_triple" == *"windows"* ]]; then
            cp "target/${target_triple}/release/ferryllm.exe" "desktop/src-tauri/binaries/ferryllm-${target_triple}.exe"
          else
            cp "target/${target_triple}/release/ferryllm" "desktop/src-tauri/binaries/ferryllm-${target_triple}"
            chmod +x "desktop/src-tauri/binaries/ferryllm-${target_triple}"
          fi

      - name: Install frontend dependencies
        working-directory: desktop
        run: npm ci

      - name: Build Tauri app
        uses: tauri-apps/tauri-action@v0
        with:
          projectPath: desktop
          args: --target ${{ matrix.target }}

      - name: Upload desktop artifact
        uses: actions/upload-artifact@v4
        with:
          name: ferryllm-desktop-${{ matrix.target }}
          path: |
            desktop/src-tauri/target/${{ matrix.target }}/release/bundle/**/*.msi
            desktop/src-tauri/target/${{ matrix.target }}/release/bundle/**/*.exe
            desktop/src-tauri/target/${{ matrix.target }}/release/bundle/**/*.dmg
            desktop/src-tauri/target/${{ matrix.target }}/release/bundle/**/*.app
            desktop/src-tauri/target/${{ matrix.target }}/release/bundle/**/*.deb
            desktop/src-tauri/target/${{ matrix.target }}/release/bundle/**/*.AppImage
          if-no-files-found: error

  release:
    name: Publish GitHub Release
    runs-on: ubuntu-latest
    needs: [build, build-desktop, publish-crates]
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          ref: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}

      - name: Download artifacts
        uses: actions/download-artifact@v4
        with:
          path: dist
          merge-multiple: true

      - name: Resolve release tag
        id: tag
        shell: bash
        run: |
          if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
            echo "tag=${{ inputs.tag }}" >> "$GITHUB_OUTPUT"
          else
            echo "tag=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
          fi

      - name: Create release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ steps.tag.outputs.tag }}
          name: ferryllm ${{ steps.tag.outputs.tag }}
          body_path: CHANGELOG.md
          files: |
            dist/*.tar.gz
            dist/*.zip
            dist/**/*.msi
            dist/**/*.exe
            dist/**/*.dmg
            dist/**/*.deb
            dist/**/*.AppImage

  publish-crates:
    name: Publish crates.io
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          ref: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}

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

      - name: Detect package version
        id: version
        shell: bash
        run: |
          version=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n 1 | tr -d '\r')
          echo "version=$version" >> "$GITHUB_OUTPUT"

      - name: Check release tag matches package version
        shell: bash
        run: |
          tag="${GITHUB_REF_NAME}"
          if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
            tag="${{ inputs.tag }}"
          fi
          if [ "v${{ steps.version.outputs.version }}" != "$tag" ]; then
            echo "Tag $tag does not match package version v${{ steps.version.outputs.version }}" >&2
            exit 1
          fi

      - name: Check whether version is already published
        id: publish
        shell: bash
        run: |
          if curl -fsSL "https://crates.io/api/v1/crates/ferryllm/versions" \
            | jq -e --arg version "${{ steps.version.outputs.version }}" '.versions[] | select(.num == $version)' >/dev/null; then
            echo "should_publish=false" >> "$GITHUB_OUTPUT"
          else
            echo "should_publish=true" >> "$GITHUB_OUTPUT"
          fi

      - name: Publish to crates.io
        if: steps.publish.outputs.should_publish == 'true'
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        run: cargo publish --registry crates-io