ferryllm 0.1.4

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

  release:
    name: Publish GitHub Release
    runs-on: ubuntu-latest
    needs: [build, 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

  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)
          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