name: Checks

on:
  push:
  pull_request:

jobs:
  tests:
    name: "Python ${{ matrix.python-version }}"
    runs-on: ubuntu-latest

    strategy:
      matrix:
        python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]

    steps:
    - uses: actions/checkout@v4

    - name: Set up Python
      uses: actions/setup-python@v4
      with:
        python-version: "${{ matrix.python-version }}"

    - name: Cache Python dependencies
      uses: actions/cache@v3
      with:
        path: .venv
        key: ${{ runner.os }}-pip-${{ hashFiles('**/poetry.lock') }}-py-${{ matrix.python-version }}

    - name: Install Poetry
      run: pipx install poetry

    - name: Install dependencies
      run: |
        poetry config virtualenvs.in-project true
        poetry install --no-interaction

    - name: Check code formatting
      run: |
        poetry run black --check .
        poetry run ruff check .

    - name: Static type checks with mypy
      run: poetry run mypy .

    - name: Test with pytest
      run: poetry run pytest
