refactor: main into app modules and route registrars #11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Lint Backend | |
| on: | |
| pull_request: | |
| paths: | |
| - 'src/**.py' | |
| - 'tests/**.py' | |
| - 'pyproject.toml' | |
| - 'uv.lock' | |
| - '.github/workflows/lint-backend.yml' | |
| # Cancel in-flight runs on the same PR when a new push lands. | |
| concurrency: | |
| group: lint-backend-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| lint: | |
| name: Ruff and mypy on changed files | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| # Need the full base ref locally so we can compute the diff | |
| # against the PR's merge base. | |
| fetch-depth: 0 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v3 | |
| with: | |
| enable-cache: true | |
| - name: Set up Python | |
| run: uv python install 3.13 | |
| - name: Install dev dependencies | |
| run: uv sync --group dev | |
| - name: Compute changed Python files | |
| id: changed | |
| run: | | |
| base="${{ github.event.pull_request.base.sha }}" | |
| head="${{ github.event.pull_request.head.sha }}" | |
| # Diff against the merge base so we only see files touched in the PR. | |
| merge_base=$(git merge-base "$base" "$head") | |
| mapfile -t files < <(git diff --name-only --diff-filter=ACMR "$merge_base" "$head" -- '*.py') | |
| if [ "${#files[@]}" -eq 0 ]; then | |
| echo "No Python files changed." | |
| echo "files=" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| printf '%s\n' "${files[@]}" | |
| # Pass as a single space-separated string to subsequent steps. | |
| echo "files=${files[*]}" >> "$GITHUB_OUTPUT" | |
| - name: Ruff (auto-fix dry run + format check) | |
| if: steps.changed.outputs.files != '' | |
| run: | | |
| # `--no-fix` reports the same set of issues that `--fix` would | |
| # apply, so the developer sees what to run locally to clean up. | |
| uv run ruff check --no-fix --output-format=github ${{ steps.changed.outputs.files }} | |
| uv run ruff format --check ${{ steps.changed.outputs.files }} | |
| - name: Mypy | |
| if: steps.changed.outputs.files != '' | |
| run: | | |
| # Run mypy from src/ so module paths resolve, dropping the | |
| # leading "src/" from each path. Tests files are checked from | |
| # the repo root. | |
| src_files=() | |
| test_files=() | |
| for f in ${{ steps.changed.outputs.files }}; do | |
| case "$f" in | |
| src/*) src_files+=("${f#src/}") ;; | |
| tests/*) test_files+=("$f") ;; | |
| esac | |
| done | |
| if [ "${#src_files[@]}" -gt 0 ]; then | |
| (cd src && uv run mypy "${src_files[@]}") | |
| fi | |
| if [ "${#test_files[@]}" -gt 0 ]; then | |
| uv run mypy "${test_files[@]}" | |
| fi |