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-py310-min-deps
          - ci-py310-min-optional-deps
          - ci-py311-transformers
          - ci-py314-latest-deps
          - ci-py314-latest-optional-deps
          - ci-py314-polars-without-pyarrow
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v6
      - uses: prefix-dev/setup-pixi@v0.9.3
        with:
          pixi-version: v0.59.0
          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: Run user guide doctests
        run: pixi run -e ${{ matrix.environment }} test-user-guide
      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@v5.5.1
        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@v6
        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 nightly dependencies
    steps:
      - uses: actions/checkout@v6
      - uses: prefix-dev/setup-pixi@v0.9.3
        with:
          pixi-version: v0.59.0
          environments: ci-nightly-deps
          # 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 ci-nightly-deps test -n auto
