name: Tests

on:
  push:
    branches:
      - master
  pull_request:
  workflow_dispatch:

concurrency:
  group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }}-${{ github.event_name != 'pull_request' && github.sha || '' }}
  cancel-in-progress: true

jobs:
  quality:
    name: 🧑‍🏭 Quality & Docs
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.13"
          cache: pip

      - name: Install dependencies
        run: python -m pip install tox

      - name: Run linters
        run: python -m tox -q -e types,lint

      - name: Build the documentation
        run: python -m tox -q -e docs

  tox:
    name: ${{ matrix.tox.name }} ${{ matrix.os.emoji }} ${{ matrix.os.name }} ${{ matrix.python }}
    runs-on: ${{ matrix.os.runs-on }}
    timeout-minutes: 15
    strategy:
      fail-fast: false
      matrix:
        os:
          - name: Linux
            matrix: linux
            emoji: 🐧
            runs-on: [ubuntu-latest]
          - name: macOS
            matrix: macos
            emoji: 🍎
            runs-on: [macos-latest]
          - name: Windows
            matrix: windows
            emoji: 🪟
            runs-on: [windows-latest]
        python:
          - "3.9"
          - "3.10"
          - "3.11"
          - "3.12"
          - "3.13"
          - "pypy-3.9"
        exclude:
          - os:
              matrix: macos
            python: "pypy-3.9"
          - os:
              matrix: windows
            python: "pypy-3.9"

    steps:
      - name: Checkout
        uses: actions/checkout@v4

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

      - name: Install dependencies
        run: python -m pip install tox

      - name: Run tests
        run: python -m tox -q -e py
