# Lint Workflow - GitHub Actions
# Generated by pypreset augment

name: Lint

on:
  push:
    branches: [main, master]
  pull_request:
    branches: [main, master]

jobs:
  lint:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - name: Set up Python {{ project.python_version }}
        uses: actions/setup-python@v5
        with:
          python-version: "{{ project.python_version }}"

{% if package_manager == "poetry" %}
      - name: Install Poetry
        uses: snok/install-poetry@v1
        with:
          virtualenvs-create: true
          virtualenvs-in-project: true

      - name: Load cached venv
        id: cached-poetry-dependencies
        uses: actions/cache@v4
        with:
          path: .venv
          key: {% raw %}venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}{% endraw %}

      - name: Install dependencies
        if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
        run: poetry install --no-interaction --no-root

      - name: Install project
        run: poetry install --no-interaction

{% if formatting.tool == "ruff" %}
      - name: Lint with ruff
        run: poetry run ruff check {{ source_dirs | join(' ') }}{% if has_src_layout %} tests{% endif %}


      - name: Check formatting with ruff
        run: poetry run ruff format --check {{ source_dirs | join(' ') }}{% if has_src_layout %} tests{% endif %}

{% elif formatting.tool == "black" %}
      - name: Check formatting with black
        run: poetry run black --check {{ source_dirs | join(' ') }}{% if has_src_layout %} tests{% endif %}

{% elif formatting.tool == "flake8" %}
      - name: Lint with flake8
        run: poetry run flake8 {{ source_dirs | join(' ') }}{% if has_src_layout %} tests{% endif %}

{% endif %}
{% if typing.enabled %}
{% if typing.checker == "mypy" %}
      - name: Type check with mypy
        run: poetry run mypy {{ source_dirs | join(' ') }}
{% elif typing.checker == "pyright" %}
      - name: Type check with pyright
        run: poetry run pyright {{ source_dirs | join(' ') }}
{% endif %}
{% endif %}
{% elif package_manager == "pdm" %}
      - name: Install PDM
        uses: pdm-project/setup-pdm@v4
        with:
          python-version: "{{ project.python_version }}"

      - name: Install dependencies
        run: pdm install

{% if formatting.tool == "ruff" %}
      - name: Lint with ruff
        run: pdm run ruff check {{ source_dirs | join(' ') }}{% if has_src_layout %} tests{% endif %}


      - name: Check formatting with ruff
        run: pdm run ruff format --check {{ source_dirs | join(' ') }}{% if has_src_layout %} tests{% endif %}

{% elif formatting.tool == "black" %}
      - name: Check formatting with black
        run: pdm run black --check {{ source_dirs | join(' ') }}{% if has_src_layout %} tests{% endif %}

{% endif %}
{% if typing.enabled %}
{% if typing.checker == "mypy" %}
      - name: Type check with mypy
        run: pdm run mypy {{ source_dirs | join(' ') }}
{% elif typing.checker == "pyright" %}
      - name: Type check with pyright
        run: pdm run pyright {{ source_dirs | join(' ') }}
{% endif %}
{% endif %}
{% elif package_manager == "hatch" %}
      - name: Install Hatch
        run: pip install hatch

{% if formatting.tool == "ruff" %}
      - name: Lint with ruff
        run: hatch run lint:check
{% elif formatting.tool == "black" %}
      - name: Check formatting with black
        run: hatch run lint:format
{% endif %}
{% if typing.enabled %}
      - name: Type check
        run: hatch run types:check
{% endif %}
{% else %}
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -e ".[dev]"

{% if formatting.tool == "ruff" %}
      - name: Lint with ruff
        run: ruff check {{ source_dirs | join(' ') }}{% if has_src_layout %} tests{% endif %}


      - name: Check formatting with ruff
        run: ruff format --check {{ source_dirs | join(' ') }}{% if has_src_layout %} tests{% endif %}

{% elif formatting.tool == "black" %}
      - name: Check formatting with black
        run: black --check {{ source_dirs | join(' ') }}{% if has_src_layout %} tests{% endif %}

{% elif formatting.tool == "flake8" %}
      - name: Lint with flake8
        run: flake8 {{ source_dirs | join(' ') }}{% if has_src_layout %} tests{% endif %}

{% endif %}
{% if typing.enabled %}
{% if typing.checker == "mypy" %}
      - name: Type check with mypy
        run: mypy {{ source_dirs | join(' ') }}
{% elif typing.checker == "pyright" %}
      - name: Type check with pyright
        run: pyright {{ source_dirs | join(' ') }}
{% endif %}
{% endif %}
{% endif %}
