Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/autofix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Ruff rewrites quote styles and capitalises docstrings without any help
# from a person, so a contributor should never have to. This hands those
# fixes to the autofix.ci app, which commits them to the pull request
# branch, forks included. The existing lint gate still reports any
# findings that ruff cannot fix.
#
# The filename and the workflow name are both fixed by autofix.ci, which
# uses them to identify the workflow it trusts. Renaming either one stops
# the app from accepting the patch.
name: autofix.ci # needed to securely identify the workflow

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

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
autofix:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1
with:
python-version: '3.13'
- run: uvx --with tox-uv tox -e ruff-fix
- uses: autofix-ci/action@c5b2d67aa2274e7b5a18224e8171550871fc7e4a # v1.3.4
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ jobs:
python-version: '3.13'
- name: Install tox
run: uv pip install '.[tox]'
- name: Apply Ruff fixes to pull requests
if: github.event_name == 'pull_request' && matrix.env == 'lint'
run: tox -e ruff-fix
- name: Run tox
env:
RUFF_OUTPUT_FORMAT: >-
${{ github.event_name == 'pull_request' && 'github' || 'full' }}
TOX_ENV: ${{ matrix.env }}
run: tox -e "$TOX_ENV"

Expand Down
13 changes: 13 additions & 0 deletions CONTRIBUTING.MD
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,16 @@ processes in parallel.
pip install tox detox
detox
```

## Automatic formatting

Pull requests apply Ruff fixes before the lint check. With the autofix.ci
app installed for this repository, those fixes are committed to the pull
request branch, including forks. Findings Ruff cannot fix still fail CI.
Push builds check the committed files without applying fixes.

Apply the same fixes locally with:

```console
uvx --with tox-uv tox -e ruff-fix
```
11 changes: 11 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ set_env =
# ── Lint ─────────────────────────────────────────────────────

[testenv:lint]
pass_env = RUFF_OUTPUT_FORMAT
description = Lint and format-check with ruff
skip_install = true
deps = ruff>=0.15.0
Expand Down Expand Up @@ -105,3 +106,13 @@ commands =
coverage combine {toxworkdir}
coverage report --fail-under=100
coverage lcov -o {toxworkdir}/coverage.lcov


[testenv:ruff-fix]
labels = fix
description = Apply the available Ruff fixes
skip_install = true
deps = ruff>=0.15.0
commands =
ruff check --fix --exit-zero django_admin_generator test_project
ruff format django_admin_generator test_project
Loading