name: Test

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
  schedule:
    - cron: "0 5 1,15 * *"

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  test:
    runs-on: ${{ matrix.os }}
    defaults:
      run:
        shell: bash -e {0} # -e to fail on error

    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            python: "3.9"

    name: ${{ matrix.name }} Python ${{ matrix.python }}

    env:
      OS: ${{ matrix.os }}
      PYTHON: ${{ matrix.python }}

    steps:
      - uses: actions/checkout@v4
      - name: Set up Python ${{ matrix.python }}
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python }}
          cache: "pip"
          cache-dependency-path: "**/pyproject.toml"

      - name: Set up external packages
        if: steps.changed-files-specific.outputs.only_changed != 'true'
        uses: ./.github/actions/setup
      - name: Install test dependencies
        run: |
          python -m pip install --upgrade pip wheel
      - name: Install dependencies
        run: |
          pip install ${{ matrix.pip-flags }} ".[dev,tests]"
      - name: Test
        env:
          MPLBACKEND: agg
          PLATFORM: ${{ matrix.os }}
          DISPLAY: :42
        run: |
          coverage run -m pytest -v --color=yes
      - name: Report coverage
        run: |
          coverage report
      - name: Upload coverage
        uses: codecov/codecov-action@v3
