name: Tests

on:
  workflow_dispatch:
    inputs:
      python_versions:
        description: "Space-separated Python versions to test"
        required: false
        type: string
      build_mode:
        description: "Build profile to use with maturin develop"
        required: true
        default: debug
        type: choice
        options:
          - debug
          - release

permissions:
  contents: read

jobs:
  test-supported-pythons:
    name: ${{ matrix.os_name }}
    runs-on: ${{ matrix.runner }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - os_name: linux
            runner: ubuntu-latest
          - os_name: windows
            runner: windows-latest
          - os_name: macos
            runner: macos-latest

    steps:
      - name: Check out repository
        uses: actions/checkout@v6
        with:
          persist-credentials: false

      - name: Set up Python
        uses: actions/setup-python@v6
        with:
          python-version: "3.13"

      - name: Set up uv
        uses: astral-sh/setup-uv@v6

      - name: Set up Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: 1.94.0

      - name: Cache Cargo registry and target
        uses: Swatinem/rust-cache@v2

      - name: Run tests across supported Python versions
        shell: bash
        env:
          RSLOOP_PYTHON_VERSIONS: ${{ github.event.inputs.python_versions || '' }}
          RSLOOP_BUILD_MODE: ${{ github.event.inputs.build_mode || 'debug' }}
        run: |
          args=()
          if [[ "$RSLOOP_BUILD_MODE" == "debug" ]]; then
            args+=(--debug)
          fi
          scripts/test-supported-pythons.sh "${args[@]}"
