name: Checks

permissions:
  contents: read

on:
  push:
    branches:
    - master
    - '[0-9]+.[0-9]+'
  pull_request:
    types: [opened, synchronize, reopened, closed]

concurrency:
  group: ${{github.workflow}}-${{ github.head_ref || github.ref }}
  cancel-in-progress: true

jobs:
  checks:
    if: github.event.action != 'closed'
    runs-on: ubuntu-latest
    env:
      # Make uv use the interpreter that actions/setup-python installed instead
      # of downloading one of its own.
      UV_PYTHON_PREFERENCE: only-system
    strategy:
      fail-fast: false
      matrix:
        include:
        - python-version: "3.14"
          env:
            TOXENV: pylint
        - python-version: "3.10"
          env:
            TOXENV: mypy
        - python-version: "3.10"
          env:
            TOXENV: mypy-tests
        # Keep in sync with pyproject.toml tool.sphinx-scrapy.python-version.
        - python-version: "3.14"
          env:
            TOXENV: docs
        - python-version: "3.13"
          env:
            TOXENV: docs-tests
        - python-version: "3.14"
          env:
            TOXENV: twinecheck

    steps:
    - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      with:
        persist-credentials: false

    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
      with:
        python-version: ${{ matrix.python-version }}

    - name: Set up uv
      uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
      with:
        cache-dependency-glob: |
          docs/requirements.txt
          pyproject.toml
          tox.ini

    - name: Run check
      env: ${{ matrix.env }}
      run: uvx --with tox-uv tox

  pre-commit:
    if: github.event.action != 'closed'
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      with:
        persist-credentials: false
    - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
