Files
seeddsandv0lumehi 7f5ef4155e Lint Python tools in CI with a checker-specific baseline ratchet (#323)
Add pinned ruff and pyright checks, the existing-findings baseline, and a
workflow that rejects new findings and requires fixed findings to be removed.

Compare checker pins numerically and permit baseline growth only for the
checker whose release version increased. Comments, unrelated dependency
edits and downgrades retain the guard. Add 10 regression tests using Git
trees and document the policy.

Validation: 14 guard/documentation tests pass; pinned lint reports 414
existing findings, zero new findings and zero stale baseline entries.

Co-authored-by: v0lumehi <aljic.zijad@gmail.com>
2026-10-27 02:57:38 +08:00

49 lines
2.3 KiB
YAML

# Python lint and types over scripts/ and the tools under dm/: ruff (lint rules for bugs, never formatting) and pyright in basic mode, configured in pyproject.toml.
# A ratchet: the findings the code had when this came in are in dm/tools/lint_python_baseline.tsv, so the job fails only on a new finding, and on a fixed one still
# listed there (`python3 dm/tools/lint_python.py --update` shrinks it). On a pull request the baseline may not grow over the base branch's either.
# ty (Astral's type checker, beta) runs beside it as advisory: its findings go to the job summary and never fail the build.
# The tool versions are pinned in .github/requirements/lint.txt; docs/development.md has the commands.
name: lint-python
on:
pull_request:
paths: ['**.py', pyproject.toml, .github/requirements/lint.txt, .github/workflows/lint-python.yml, dm/tools/lint_python_baseline.tsv]
push:
branches: [main]
paths: ['**.py', pyproject.toml, .github/requirements/lint.txt, .github/workflows/lint-python.yml, dm/tools/lint_python_baseline.tsv]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: lint-python-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
defaults:
run:
shell: bash
# Actions are pinned to commit SHAs (the tag in the comment), as in tests.yml.
jobs:
lint:
name: ruff and pyright (ratchet)
runs-on: ubuntu-24.04 # pyproject.toml fixes the platform pyright assumes (Darwin), so the findings match a Mac's
timeout-minutes: 10
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: '3.14'
cache: pip
cache-dependency-path: .github/requirements/lint.txt
- name: Install the pinned tools
run: python -m pip install -r .github/requirements/lint.txt
- name: Base branch's baseline (pull requests)
if: github.event_name == 'pull_request'
run: git fetch --no-tags --depth=1 origin "$GITHUB_BASE_REF"
- name: ruff and pyright against the baseline
run: python dm/tools/lint_python.py ${{ github.event_name == 'pull_request' && '--against FETCH_HEAD' || '' }}