name: 'test'

on:
  push:
    branches:
      - "main"
  pull_request:
    branches:
      - '*'
  schedule:
    - cron: "30 2 * * *"

jobs:
  test:
    strategy:
      matrix:
        os: [windows-latest, ubuntu-latest, macos-latest]
        environment: [
            ci-py309-min-deps,
            ci-py309-min-optional-deps,
            ci-py311-transformers,
            ci-py313-latest-deps,
            ci-py313-latest-optional-deps
        ]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      - uses: prefix-dev/setup-pixi@v0.8.3
        with:
          pixi-version: v0.41.3
          environments: ${{ matrix.environment }}
          # we can freeze the environment and manually bump the dependencies to the
          # latest version time to time.
          frozen: true

      - name: Run tests
        run: pixi run -e ${{ matrix.environment }} test -n auto

      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@v5.4.0
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          slug: skrub-data/skrub

  check_run_nightly:
    runs-on: ubuntu-latest
    outputs:
      run: ${{ github.event_name == 'schedule' || contains(steps.get_head_commit_message.outputs.COMMIT_MSG, '[deps nightly]') }}
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.event.pull_request.head.sha }}
      - id: get_head_commit_message
        name: get head commit message
        run: echo "COMMIT_MSG=$(git show -s --format=%s)" >> "$GITHUB_OUTPUT"

  test_against_nightly:
    needs: check_run_nightly
    if: ${{ needs.check_run_nightly.outputs.run == 'true' }}
    runs-on: ubuntu-latest
    name: test against nighlty dependencies
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
            python-version: "3.11"
        name: 'Setup python'
      - shell: bash {0}
        run: |
          dev_anaconda_url=https://pypi.anaconda.org/scientific-python-nightly-wheels/simple
          pip install --pre --upgrade --timeout=60 --extra-index $dev_anaconda_url .
          dev_arrow=https://pypi.fury.io/arrow-nightlies/
          pip install --extra-index-url $dev_arrow --prefer-binary --pre .[optional]
          pip install .[test]
        name: 'Install skrub and nightly dependencies'
      - shell: bash {0}
        run: pytest -vsl --cov=skrub --cov-report=xml skrub -n 3
        name: 'Run tests'
