granite-cli 0.1.10

CLI for discovering, configuring, and launching AI workflows powered by IBM Granite models.
name: Release

on:
  release:
    types: [published]

jobs:
  # ── Quality gate (same as PR CI) ──────────────────────────────────────────
  check:
    name: fmt / clippy / build / test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

      - uses: dtolnay/rust-toolchain@2c7215f132e9ebf062739d9130488b56d53c060c # 1.96.1
        with:
          toolchain: 1.88.0
          components: rustfmt, clippy

      - uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1

      - name: Check formatting
        run: cargo fmt --all -- --check

      - name: Run Clippy
        run: cargo clippy --all-targets --all-features -- -D warnings

      - name: Build
        run: cargo build --locked --all-targets --all-features

      - name: Test
        run: cargo test --locked --all-targets --all-features

  # ── Prebuilt binaries ─────────────────────────────────────────────────────
  build-binaries:
    name: Build binary (${{ matrix.target }})
    needs: check
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            artifact: granite-cli-linux-x86_64
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
            artifact: granite-cli-linux-aarch64
          - target: x86_64-apple-darwin
            os: macos-latest
            artifact: granite-cli-macos-x86_64
          - target: aarch64-apple-darwin
            os: macos-latest
            artifact: granite-cli-macos-aarch64
          - target: x86_64-pc-windows-msvc
            os: windows-latest
            artifact: granite-cli-windows-x86_64.exe

    steps:
      - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

      - uses: dtolnay/rust-toolchain@2c7215f132e9ebf062739d9130488b56d53c060c # 1.96.1
        with:
          toolchain: 1.88.0
          targets: ${{ matrix.target }}

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

      # Cross-compiler for Linux aarch64
      - name: Install cross-compilation tools
        if: matrix.target == 'aarch64-unknown-linux-gnu'
        run: |
          sudo apt-get update
          sudo apt-get install -y gcc-aarch64-linux-gnu

      - name: Build release binary
        run: cargo build --locked --release --target ${{ matrix.target }}
        env:
          CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc

      - name: Rename binary (Unix)
        if: matrix.os != 'windows-latest'
        run: |
          cp target/${{ matrix.target }}/release/granite-cli ${{ matrix.artifact }}

      - name: Rename binary (Windows)
        if: matrix.os == 'windows-latest'
        run: |
          cp target/${{ matrix.target }}/release/granite-cli.exe ${{ matrix.artifact }}

      - name: Upload binary to release
        uses: softprops/action-gh-release@3d0d9888cb7fd7b750713d6e236d1fcb99157228 # 3.0.2
        with:
          files: ${{ matrix.artifact }}

  # ── Publish to crates.io ──────────────────────────────────────────────────
  publish:
    name: Publish to crates.io
    needs: build-binaries
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

      - uses: dtolnay/rust-toolchain@2c7215f132e9ebf062739d9130488b56d53c060c # 1.96.1
        with:
          toolchain: 1.88.0

      - uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1

      - name: Publish
        run: ./scripts/publish.sh
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}