Skip to content

Commit 79e2617

Browse files
committed
Add pre-commit hooks
1 parent 1604369 commit 79e2617

2 files changed

Lines changed: 62 additions & 21 deletions

File tree

.github/workflows/ci.yml

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
11
name: CI
2-
32
on:
43
push:
54
branches:
65
- main
76
pull_request:
87
jobs:
9-
10-
lint:
8+
pre-commit:
9+
if: startsWith(github.head_ref, 'dependabot/') != true
10+
name: pre-commit
1111
runs-on: ubuntu-latest
12-
strategy:
13-
matrix:
14-
lint-command:
15-
- "ruff format --check --diff ."
16-
- "ruff check --output-format=github ."
12+
outputs:
13+
file-names: ${{ steps.diff.outputs.file-names }}
1714
steps:
1815
- uses: actions/checkout@v6
19-
- uses: actions/setup-python@v6
2016
with:
21-
python-version: "3.x"
22-
cache: 'pip'
23-
cache-dependency-path: '**/pyproject.toml'
24-
- run: python -m pip install -e .[lint]
25-
- run: ${{ matrix.lint-command }}
26-
17+
fetch-depth: 0
18+
- run: echo "file-names=$(git diff --name-only ${{ github.event.pull_request.base.sha }} HEAD | grep '\.py$' | tr '\n' ' ' || true)" >> "$GITHUB_OUTPUT"
19+
id: diff
20+
- uses: astral-sh/setup-uv@v7
21+
- uses: actions/cache@v5
22+
with:
23+
path: ~/.cache/pre-commit/
24+
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
25+
- run: SKIP=$(yq '.ci.skip' -o csv .pre-commit-config.yaml) uvx pre-commit run --all-files --show-diff-on-failure
2726
dist:
2827
runs-on: ubuntu-latest
29-
needs: [lint]
28+
needs: [pre-commit]
3029
steps:
3130
- uses: actions/checkout@v6
3231
- uses: actions/setup-python@v6
@@ -37,11 +36,9 @@ jobs:
3736
- run: python -m pip install --upgrade pip build twine
3837
- run: python -m build --sdist --wheel
3938
- run: python -m twine check dist/*
40-
41-
4239
docs:
4340
runs-on: ubuntu-latest
44-
needs: [lint]
41+
needs: [pre-commit]
4542
steps:
4643
- uses: actions/checkout@v6
4744
- name: setup Python
@@ -52,10 +49,9 @@ jobs:
5249
cache-dependency-path: '**/pyproject.toml'
5350
- run: python -m pip install -e .[docs]
5451
- run: python -m sphinx -b html -W docs docs/_build
55-
5652
PyTest:
5753
runs-on: ubuntu-latest
58-
needs: [lint]
54+
needs: [pre-commit]
5955
strategy:
6056
matrix:
6157
python-version:

.pre-commit-config.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v6.0.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: check-merge-conflict
7+
- id: check-ast
8+
- id: check-toml
9+
- id: check-yaml
10+
- id: check-symlinks
11+
- id: debug-statements
12+
- id: end-of-file-fixer
13+
- id: no-commit-to-branch
14+
args: [--branch, main]
15+
- repo: https://github.com/asottile/pyupgrade
16+
rev: v3.21.2
17+
hooks:
18+
- id: pyupgrade
19+
- repo: https://github.com/adamchainz/django-upgrade
20+
rev: 1.29.1
21+
hooks:
22+
- id: django-upgrade
23+
- repo: https://github.com/hukkin/mdformat
24+
rev: 1.0.0
25+
hooks:
26+
- id: mdformat
27+
additional_dependencies:
28+
- mdformat-ruff
29+
- mdformat-footnote
30+
- mdformat-gfm
31+
- mdformat-gfm-alerts
32+
- repo: https://github.com/astral-sh/ruff-pre-commit
33+
rev: v0.14.9
34+
hooks:
35+
- id: ruff-check
36+
args: [--fix, --exit-non-zero-on-fix]
37+
- id: ruff-format
38+
- repo: https://github.com/google/yamlfmt
39+
rev: v0.20.0
40+
hooks:
41+
- id: yamlfmt
42+
ci:
43+
autoupdate_schedule: weekly
44+
skip:
45+
- no-commit-to-branch

0 commit comments

Comments
 (0)