name: Tests

on:
  push:
    branches:
      - main
      - current-release
      - "*LTS"
    tags:
      - "!*"
  pull_request:
    branches:
      - main
      - current-release
      - "*LTS"
    types: [opened, synchronize, reopened, ready_for_review]

jobs:
  run_tests:
    name: "${{ matrix.config.platform == 'windows-latest' && 'Windows' || 'Linux' }} / Python ${{ matrix.config.python-version }} / tox -e ${{ matrix.config.tox-env }}"
    if: github.event.pull_request.draft == false
    runs-on: ${{ matrix.config.platform || 'ubuntu-latest' }}
    strategy:
      fail-fast: true
      matrix:
        config:
          - { python-version: "3.8",  tox-env: security }
          - { python-version: "3.9",  tox-env: security }
          - { python-version: "3.10", tox-env: security }
          - { python-version: "3.11", tox-env: security }
          - { python-version: "3.10", tox-env: lint }
          # - { python-version: "3.10", tox-env: docs }
          - { python-version: "3.8",  tox-env: type-checking }
          - { python-version: "3.9",  tox-env: type-checking }
          - { python-version: "3.10", tox-env: type-checking }
          - { python-version: "3.11", tox-env: type-checking }
          - { python-version: "3.8",  tox-env: py38,          max-attempts: 3 }
          - { python-version: "3.8",  tox-env: py38-no-ext,   max-attempts: 3 }
          - { python-version: "3.9",  tox-env: py39,          max-attempts: 3 }
          - { python-version: "3.9",  tox-env: py39-no-ext,   max-attempts: 3 }
          - { python-version: "3.10", tox-env: py310,         max-attempts: 3 }
          - { python-version: "3.10", tox-env: py310-no-ext,  max-attempts: 3 }
          - { python-version: "3.11", tox-env: py311,         max-attempts: 3 }
          - { python-version: "3.11", tox-env: py311-no-ext,  max-attempts: 3 }
          - { python-version: "3.8",  tox-env: py38-no-ext,   platform: windows-latest, ignore-errors: true }
          - { python-version: "3.9",  tox-env: py39-no-ext,   platform: windows-latest, ignore-errors: true }
          - { python-version: "3.10", tox-env: py310-no-ext,  platform: windows-latest, ignore-errors: true }
          - { python-version: "3.11", tox-env: py310-no-ext,  platform: windows-latest, ignore-errors: true }
    steps:
      - name: Run tests
        uses: sanic-org/simple-tox-action@v1
        with:
          python-version: ${{ matrix.config.python-version }}
          tox-env: ${{ matrix.config.tox-env }}
          max-attempts: ${{ matrix.config.max-attempts || 1 }}
          ignore-errors: ${{ matrix.config.ignore-errors || false }}
