name: tests
on: [push, pull_request]
jobs:
  code-quality:
    name: code-quality
    runs-on: ubuntu-latest
    steps:
      - name: repository checkout step
        uses: actions/checkout@v4
      - name: python environment step
        uses: actions/setup-python@v5
        with:
          python-version: "3.11"
      - name: install pre-commit
        run: python3 -m pip install pre-commit
      - id: changed-files
        name: identify modified files
        uses: tj-actions/changed-files@v45
      - name: run pre-commit hooks on modified files
        run: pre-commit run --color always --files ${{ steps.changed-files.outputs.all_changed_files }} --show-diff-on-failure
      - name: check missing __init__ files
        run: build_tools/fail_on_missing_init_files.sh
        shell: bash

  pytests-without-numba:
    name: pytests-without-numba
    strategy:
      fail-fast: false
      matrix:
        python-version:
          - "3.9"
          - "3.13"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
      - name: Run skchange without Numba
        run: |
          python -m pip install --upgrade pip
          python -m pip install .
          python -m pip install pytest pytest-cov
          pytest --cov --cov-report=xml --cov-report=term
      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@v3
        with:
          files: ./coverage.xml
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

  pytests-with-numba:
    name: pytests-with-numba
    runs-on: ubuntu-latest
    needs: pytests-without-numba
    steps:
      - uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
      - name: Run skchange with and without Numba
      # Both with and without to get full coverage report.
      # Without numba is very fast, so it doesn't hurt to run it twice.
        run: |
          python -m pip install --upgrade pip
          python -m pip install .
          python -m pip install pytest pytest-cov
          pytest --cov --cov-report=xml
          python -m pip install .[numba]
          pytest --cov --cov-report=xml --cov-append --cov-report=term
      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@v3
        with:
          files: ./coverage.xml
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
