---
name: Linting

# yamllint disable-line rule:truthy
on:
  push:
    branches:
      - main
    paths:
      - "**.py"
      - "pyproject.toml"
      - "uv.lock"
      - "pypaperless/**"
      - "tests/**"
  pull_request:
    paths:
      - "**.py"
      - "pyproject.toml"
      - "uv.lock"
      - "pypaperless/**"
      - "tests/**"
  workflow_dispatch:

env:
  DEFAULT_PYTHON: "3.13"

jobs:
  lint:
    name: ${{ matrix.tool }}
    runs-on: ubuntu-latest
    strategy:
      matrix:
        tool: [codespell, ruff, pre-commit-hooks, pylint, yamllint]
    steps:
      - name: ⤵️ Check out code from GitHub
        uses: actions/checkout@v4.2.2
      - name: 🏗 Set up Python ${{ env.DEFAULT_PYTHON }}
        id: python
        uses: actions/setup-python@v5.6.0
        with:
          python-version: ${{ env.DEFAULT_PYTHON }}
      - name: 🏗 Set up uv
        run: |
          pipx install uv
          uv venv
      - name: 🏗 Install Python dependencies
        run: uv sync --group dev
      - name: 🚀 Execute checks
        run: |
          if [ "${{ matrix.tool }}" = "codespell" ]; then
            uv run pre-commit run codespell --all-files
          elif [ "${{ matrix.tool }}" = "ruff" ]; then
            uv run ruff check --output-format=github .
            uv run ruff format --check .
          elif [ "${{ matrix.tool }}" = "pre-commit-hooks" ]; then
            uv run pre-commit run check-ast --all-files
            uv run pre-commit run check-case-conflict --all-files
            uv run pre-commit run check-docstring-first --all-files
            uv run pre-commit run check-json --all-files
            uv run pre-commit run check-merge-conflict --all-files
            uv run pre-commit run check-symlinks --all-files
            uv run pre-commit run check-toml --all-files
            uv run pre-commit run check-yaml --all-files
            uv run pre-commit run detect-private-key --all-files
            uv run pre-commit run end-of-file-fixer --all-files
            uv run pre-commit run trailing-whitespace --all-files
          elif [ "${{ matrix.tool }}" = "pylint" ]; then
            uv run pre-commit run pylint --all-files
          elif [ "${{ matrix.tool }}" = "yamllint" ]; then
            uv run yamllint .
          fi
