name: CI tests at GitHub

permissions:
  contents: read

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  check:

    runs-on: ${{matrix.os}}
    strategy:
      fail-fast: false
      matrix:
        os:
          - ubuntu-22.04
          - ubuntu-24.04
        python-version:
          - 3.7
          - 3.8
          - 3.9
          - '3.10'
          - 3.11
          - 3.12
          - 3.13
        exclude:
          - os: ubuntu-24.04
            python-version: 3.7

    steps:
    - uses: actions/checkout@v7
    - name: Set up Python
      uses: actions/setup-python@v6
      with:
        python-version: ${{matrix.python-version}}
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        # flake8-import-order 0.18.x uses pkg_resources; setuptools 82+ removed it.
        # 0.19.x uses importlib.metadata instead (needs Python 3.8+).
        PY_MINOR=$(python -c 'import sys; print(sys.version_info[1])')
        if [ "$PY_MINOR" -lt 8 ]; then
          python -m pip install 'setuptools>=65,<82'
          FIO='flake8-import-order==0.18.2'
        else
          python -m pip install setuptools
          FIO='flake8-import-order==0.19.2'
        fi
        python -m pip install flake8 "$FIO" \
          attrs configobj pycotap pysol-cards
        if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
    - name: Lint with flake8
      run: |
        flake8 . --show-source
    - name: Run unit tests
      run: |
        python -m unittest -v
    - name: Individually import each Python module
      run: |
        python scripts/gen_individual_importing_tests.py
        prove tests/individually-importing/*.py
