name: Tests

on:
  push:

jobs:
  build:
    permissions:
      contents: read
      pull-requests: write
    strategy:
      # We want to see all failures:
      fail-fast: false
      matrix:
        os:
        - ["ubuntu", "ubuntu-latest"]
        config:
        # [Python version, visual name, tox env]
        - %(gh_config_lines)s

    runs-on: ${{ matrix.os[1] }}
    if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
    name: ${{ matrix.config[1] }}
    steps:
    - uses: actions/checkout@v5
      with:
        persist-credentials: false
    - name: Set up Python
      uses: actions/setup-python@v6
      with:
        python-version: ${{ matrix.config[0] }}
        allow-prereleases: true
{% if os_dependencies %}
    - name: install OS packages
      run: sudo apt-get install -y %(os_dependencies)s
{% endif %}
%(extra_lines_after_os_dependencies)s
##
# Add extra configuration options in .meta.toml:
#  [github]
#  extra_lines_after_os_dependencies = """
#  _your own configuration lines_
#  """
##
    - name: Pip cache
      uses: actions/cache@v4
      with:
        path: ~/.cache/pip
        key: ${{ runner.os }}-pip-${{ matrix.config[0] }}-${{ hashFiles('setup.*', 'tox.ini') }}
        restore-keys: |
          ${{ runner.os }}-pip-${{ matrix.config[0] }}-
          ${{ runner.os }}-pip-
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install tox
    - name: Initialize tox
      # the bash one-liner below does not work on Windows
      if: contains(matrix.os, 'ubuntu')
      run: |
        if [ `tox list --no-desc -f init|wc -l` = 1 ]; then tox -e init;else true; fi
    - name: Test
      run: tox -e ${{ matrix.config[2] }}

%(extra_lines)s
##
# Add extra configuration options in .meta.toml:
#  [github]
#  extra_lines = """
#  _your own configuration lines_
#  """
##
