name: Python CI

on:
  push:
    branches: [main]
    paths-ignore:
      - '**.md'
      - 'doc/**'
  pull_request:
    branches: [main]
    paths-ignore:
      - '**.md'
      - 'doc/**'

env:
  CARGO_TERM_COLOR: always
  MACOSX_DEPLOYMENT_TARGET: "13.0"
  CARGO_PROFILE_RELEASE_LTO: thin
  CARGO_PROFILE_RELEASE_CODEGEN_UNITS: 16
  SCCACHE_GHA_ENABLED: "true"
  RUSTC_WRAPPER: sccache
  # fff-search alone exceeds the 600s default on windows, and the server sees
  # no new requests while it compiles, so it would idle out mid-unit.
  SCCACHE_IDLE_TIMEOUT: "0"

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: ${{ github.ref != 'refs/heads/main' && !startsWith(github.ref, 'refs/tags/') }}

jobs:
  test:
    name: Python bindings (${{ matrix.os }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]

    steps:
      - uses: actions/checkout@v5
        with:
          persist-credentials: false

      - name: Install Rust
        uses: actions-rust-lang/setup-rust-toolchain@v1.15.4
        with:
          cache: true
          cache-on-failure: true
          cache-key: "v1-rust-python"

      - name: Setup sccache
        uses: mozilla-actions/sccache-action@v0.0.11
        with:
          version: v0.17.0

      - name: Setup uv
        uses: astral-sh/setup-uv@v5
        with:
          version: "0.11.14"
          enable-cache: true

      - name: Build and test Python bindings
        working-directory: packages/fff-python
        shell: bash
        run: |
          # --no-install-project: uv would otherwise build the wheel via
          # maturin's PEP 517 backend, then `maturin develop` builds it again.
          uv sync --all-extras --no-install-project
          uv run maturin develop --release
          uv run pytest -v
