name: Build CLI with Embedded SQLite

on:
  push:
    branches: [main, master]
    paths:
      - 'cli/**'
      - '.forgejo/workflows/build-cli.yml'
  pull_request:
    branches: [main, master]
    paths:
      - 'cli/**'

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        target:
          - x86_64-linux
          - aarch64-linux
        include:
          - target: x86_64-linux
            arch: x86_64
          - target: aarch64-linux
            arch: arm64

    steps:
      - uses: actions/checkout@v4

      - name: Setup Zig
        uses: goto-bus-stop/setup-zig@v2
        with:
          version: 0.15.2

      - name: Fetch SQLite Amalgamation
        run: |
          cd cli
          make build-sqlite SQLITE_VERSION=3480000

      - name: Build Release Binary
        run: |
          cd cli
          zig build prod -Dtarget=${{ matrix.target }}

      - name: Upload Artifact
        uses: actions/upload-artifact@v4
        with:
          name: ml-cli-${{ matrix.target }}
          path: cli/zig-out/bin/ml

  build-macos:
    runs-on: macos-latest
    strategy:
      matrix:
        arch: [x86_64, arm64]

    steps:
      - uses: actions/checkout@v4

      - name: Setup Zig
        uses: goto-bus-stop/setup-zig@v2
        with:
          version: 0.15.2

      - name: Fetch SQLite Amalgamation
        run: |
          cd cli
          make build-sqlite SQLITE_VERSION=3480000

      - name: Build Release Binary
        run: |
          cd cli
          zig build prod -Dtarget=${{ matrix.arch }}-macos

      - name: Upload Artifact
        uses: actions/upload-artifact@v4
        with:
          name: ml-cli-${{ matrix.arch }}-macos
          path: cli/zig-out/bin/ml
