sampling2api 0.1.0

Expose MCP client sampling as an Anthropic-compatible Messages API
Documentation
name: Release

on:
  push:
    tags:
      - "v*.*.*"

permissions:
  contents: write

concurrency:
  group: release-${{ github.ref }}
  cancel-in-progress: false

jobs:
  verify-version:
    name: Verify Tag Version
    runs-on: ubuntu-latest
    outputs:
      version: ${{ steps.version.outputs.version }}
      tag: ${{ steps.version.outputs.tag }}
    steps:
      - name: Checkout repository
        uses: actions/checkout@v5

      - name: Read crate version
        id: version
        shell: bash
        run: |
          crate_version=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n 1)
          tag_version="${GITHUB_REF_NAME#v}"

          if [[ -z "${crate_version}" ]]; then
            echo "Unable to determine crate version from Cargo.toml" >&2
            exit 1
          fi

          if [[ "${crate_version}" != "${tag_version}" ]]; then
            echo "Tag version (${tag_version}) does not match Cargo.toml version (${crate_version})" >&2
            exit 1
          fi

          echo "version=${crate_version}" >> "${GITHUB_OUTPUT}"
          echo "tag=${GITHUB_REF_NAME}" >> "${GITHUB_OUTPUT}"

  build-artifacts:
    name: Build Release Asset (${{ matrix.target }})
    needs: verify-version
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            asset_suffix: x86_64-unknown-linux-gnu
            archive_ext: tar.gz
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            asset_suffix: x86_64-pc-windows-msvc
            archive_ext: zip
          - os: macos-15-intel
            target: x86_64-apple-darwin
            asset_suffix: x86_64-apple-darwin
            archive_ext: tar.gz
          - os: macos-15
            target: aarch64-apple-darwin
            asset_suffix: aarch64-apple-darwin
            archive_ext: tar.gz

    steps:
      - name: Checkout repository
        uses: actions/checkout@v5

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

      - name: Cache Rust dependencies
        uses: Swatinem/rust-cache@v2

      - name: Build release binary
        run: cargo build --locked --release --target ${{ matrix.target }}

      - name: Package archive (Unix)
        if: runner.os != 'Windows'
        shell: bash
        env:
          ASSET_BASENAME: sampling2api-${{ needs.verify-version.outputs.version }}-${{ matrix.asset_suffix }}
        run: |
          mkdir -p dist
          cp "target/${{ matrix.target }}/release/sampling2api" dist/
          cp README.md LICENSE dist/
          tar -czf "${ASSET_BASENAME}.${{ matrix.archive_ext }}" -C dist .
          shasum -a 256 "${ASSET_BASENAME}.${{ matrix.archive_ext }}" > "${ASSET_BASENAME}.${{ matrix.archive_ext }}.sha256"

      - name: Package archive (Windows)
        if: runner.os == 'Windows'
        shell: pwsh
        env:
          ASSET_BASENAME: sampling2api-${{ needs.verify-version.outputs.version }}-${{ matrix.asset_suffix }}
        run: |
          New-Item -ItemType Directory -Force -Path dist | Out-Null
          Copy-Item "target\${{ matrix.target }}\release\sampling2api.exe" dist\
          Copy-Item README.md, LICENSE dist\
          Compress-Archive -Path dist\* -DestinationPath "${env:ASSET_BASENAME}.${{ matrix.archive_ext }}" -Force
          $hash = (Get-FileHash "${env:ASSET_BASENAME}.${{ matrix.archive_ext }}" -Algorithm SHA256).Hash.ToLower()
          Set-Content -Path "${env:ASSET_BASENAME}.${{ matrix.archive_ext }}.sha256" -Value "$hash  ${env:ASSET_BASENAME}.${{ matrix.archive_ext }}"

      - name: Upload packaged artifact
        uses: actions/upload-artifact@v6
        with:
          name: release-${{ matrix.asset_suffix }}
          path: |
            sampling2api-${{ needs.verify-version.outputs.version }}-${{ matrix.asset_suffix }}.${{ matrix.archive_ext }}
            sampling2api-${{ needs.verify-version.outputs.version }}-${{ matrix.asset_suffix }}.${{ matrix.archive_ext }}.sha256

  publish-github-release:
    name: Publish GitHub Release
    needs:
      - verify-version
      - build-artifacts
    runs-on: ubuntu-latest
    steps:
      - name: Download packaged artifacts
        uses: actions/download-artifact@v5
        with:
          path: release-assets
          pattern: release-*
          merge-multiple: true

      - name: Create GitHub release
        uses: softprops/action-gh-release@v2
        with:
          files: release-assets/*
          generate_release_notes: true

  publish-crate:
    name: Publish To crates.io
    needs:
      - publish-github-release
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v5

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

      - name: Cache Rust dependencies
        uses: Swatinem/rust-cache@v2

      - name: Ensure crates.io token is configured
        shell: bash
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        run: |
          if [[ -z "${CARGO_REGISTRY_TOKEN}" ]]; then
            echo "Repository secret CARGO_REGISTRY_TOKEN is required for cargo publish" >&2
            exit 1
          fi

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