{% if config_type == 'toolkit' %}
{% set with_coverage = False %}
{% else %}
{% set with_coverage = True %}
{% endif %}
name: tests

on:
  push:
  pull_request:
  schedule:
    - cron: '0 12 * * 0'  # run once a week on Sunday
  # Allow to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  build:
    permissions:
      contents: read
      pull-requests: write
{% if gha_services %}
    services:
{% for line in gha_services %}
      %(line)s
{% endfor %}
{% endif %}
    strategy:
      # We want to see all failures:
      fail-fast: false
      matrix:
        os:
        - ["ubuntu", "ubuntu-latest"]
{% if with_windows %}
        - ["windows", "windows-latest"]
{% endif %}
{% if with_macos %}
        - ["macos", "macos-latest"]
{% endif %}
        config:
        # [Python version, tox env]
        - ["3.11", "release-check"]
{% for (py_long_version, py_short_version) in supported_python_versions %}
        - ["%(py_long_version)s", "py%(py_short_version)s"]
{% endfor %}
{% if with_future_python %}
        - ["%(future_python_version)s", "py%(future_python_shortversion)s"]
{% endif %}
{% if with_pypy %}
        - ["pypy-%(pypy_version)s", "pypy3"]
{% endif %}
{% if with_docs %}
        - ["3.11", "docs"]
{% endif %}
{% if with_coverage %}
        - ["3.11", "coverage"]
{% endif %}
{% for line in gha_additional_config %}
        %(line)s
{% endfor %}
{% if with_windows or with_macos or gha_additional_exclude %}
        exclude:
{% endif %}
{% if with_windows %}
          - { os: ["windows", "windows-latest"], config: ["3.11", "release-check"] }
  {% if with_docs %}
          - { os: ["windows", "windows-latest"], config: ["3.11", "docs"] }
  {% endif %}
          - { os: ["windows", "windows-latest"], config: ["3.11", "coverage"] }
{% endif %}
{% if with_macos %}
          - { os: ["macos", "macos-latest"], config: ["3.11", "release-check"] }
  {% if with_docs %}
          - { os: ["macos", "macos-latest"], config: ["3.11", "docs"] }
  {% endif %}
          - { os: ["macos", "macos-latest"], config: ["3.11", "coverage"] }
{% endif %}
{% for line in gha_additional_exclude %}
          %(line)s
{% endfor %}

    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
{% if with_windows or with_macos %}
    name: ${{ matrix.os[0] }}-${{ matrix.config[1] }}
{% else %}
    name: ${{ matrix.config[1] }}
{% endif %}
    steps:
{% for line in gha_steps_before_checkout %}
    %(line)s
{% endfor %}
    - uses: actions/checkout@v5
      with:
        persist-credentials: false
{% if gha_additional_install %}
    - name: Install additional dependencies
      run: |
{% for line in gha_additional_install %}
        %(line)s
{% endfor %}
{% endif %}
    - name: Install uv + caching
      # astral/setup-uv@7.1.2
      uses: astral-sh/setup-uv@85856786d1ce8acfbcc2f13a5f3fbd6b938f9f41
      with:
        enable-cache: true
        cache-dependency-glob: |
          setup.*
          tox.ini
        python-version: ${{ matrix.config[0] }}
        github-token: ${{ secrets.GITHUB_TOKEN }}
    - name: Test
      if: ${{ !startsWith(runner.os, 'Mac') }}
{% if gha_test_environment %}
      env:
      {% for line in gha_test_environment %}
        %(line)s
      {% endfor %}
{% endif %}
{% if gha_test_commands %}
      run: |
      {% for line in gha_test_commands %}
        %(line)s
      {% endfor %}
{% else %}
      run: uvx --with tox-uv tox -e ${{ matrix.config[1] }}
{% endif %}
    - name: Test (macOS)
      if: ${{ startsWith(runner.os, 'Mac') }}
{% if gha_test_environment %}
      env:
      {% for line in gha_test_environment %}
        %(line)s
      {% endfor %}
{% endif %}
      run: uvx --with tox-uv tox -e ${{ matrix.config[1] }}-universal2
    - name: Coverage
      if: matrix.config[1] == 'coverage'
      run: |
        uvx coveralls --service=github
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
