# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Build and Test

# Run workflow for pushes to main and version branches, or pull requests
on:
  push:
    branches:
      - main
      - 'v[0-9]+.[0-9]+'
  pull_request:

jobs:
  build:

    runs-on: ubuntu-24.04
    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "pypy3.9"]

    steps:
    - uses: actions/checkout@v4

    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v5
      with:
        python-version: ${{ matrix.python-version }}
        cache: 'pip'

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        python -m pip install -r requirements.txt
        python -m pip install -r tests/requirements.txt

    - name: Test with pytest without flake8 (for pypy)
      if: startsWith(matrix.python-version, 'pypy')
      # flake8 runs very slowly with pypy, so skip it (see #146)
      run: pytest -o 'flake8-ignore=*.py ALL'

    - name: Test with pytest
      if: startsWith(matrix.python-version, 'pypy') != true
      run: pytest

    - name: Generate coverage report
      run: coverage xml

    - name: Upload coverage report to Codecov
      uses: codecov/codecov-action@v5
      with:
        fail_ci_if_error: true
        token: ${{ secrets.CODECOV_TOKEN }}
        verbose: true
