Skip to content

Commit 42a228e

Browse files
authored
build: Replace pre-commit with prek (#2702)
* feat: Replace pre-commit with prek in configuration files * feat: Enhance GitHub Actions workflows with pull_request_target support and actor conditions * fix: Simplify prek command by moving SKIP environment variable to command line * fix: Update GitHub Actions checkout step to handle fallback for ref and repository
1 parent fef6065 commit 42a228e

7 files changed

Lines changed: 105 additions & 88 deletions

File tree

.github/workflows/cli-docs.yaml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,37 @@ on:
1717
- 'src/datamodel_code_generator/arguments.py'
1818
- 'src/datamodel_code_generator/cli_options.py'
1919
- 'scripts/build_cli_docs.py'
20+
pull_request_target:
21+
types: [labeled]
22+
paths:
23+
- 'tests/main/**'
24+
- 'tests/test_main_kr.py'
25+
- 'src/datamodel_code_generator/arguments.py'
26+
- 'src/datamodel_code_generator/cli_options.py'
27+
- 'scripts/build_cli_docs.py'
2028

2129
permissions:
2230
contents: write
2331

2432
jobs:
2533
update-cli-docs:
26-
if: github.event_name == 'push' || !github.event.pull_request.head.repo.fork
34+
if: |
35+
github.event_name == 'push' ||
36+
!github.event.pull_request.head.repo.fork ||
37+
github.actor == 'koxudaxi' ||
38+
github.actor == 'gaborbernat' ||
39+
github.actor == 'ilovelinux' ||
40+
(github.event_name == 'pull_request_target' && github.event.label.name == 'safe-to-fix' &&
41+
(github.event.sender.login == 'koxudaxi' ||
42+
github.event.sender.login == 'gaborbernat' ||
43+
github.event.sender.login == 'ilovelinux'))
2744
runs-on: ubuntu-latest
2845
steps:
2946
- uses: actions/checkout@v4
3047
with:
3148
fetch-depth: 0
32-
ref: ${{ github.head_ref || github.ref }}
49+
ref: ${{ github.event.pull_request.head.ref || github.ref }}
50+
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
3351
token: ${{ secrets.PAT }}
3452
- name: Install the latest version of uv
3553
uses: astral-sh/setup-uv@v5

.github/workflows/lint.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Lint
2+
on:
3+
push:
4+
branches: [main]
5+
pull_request:
6+
pull_request_target:
7+
types: [labeled]
8+
9+
jobs:
10+
lint:
11+
if: |
12+
github.event_name == 'push' ||
13+
github.event_name == 'pull_request' ||
14+
(github.event_name == 'pull_request_target' && github.event.label.name == 'safe-to-fix' &&
15+
(github.event.sender.login == 'koxudaxi' ||
16+
github.event.sender.login == 'gaborbernat' ||
17+
github.event.sender.login == 'ilovelinux'))
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
with:
22+
token: ${{ secrets.PAT || github.token }}
23+
ref: ${{ github.event.pull_request.head.ref || github.ref }}
24+
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
25+
- uses: astral-sh/setup-uv@v5
26+
- uses: actions/setup-python@v5
27+
with:
28+
python-version: "3.14"
29+
- run: uvx prek run --all-files --show-diff-on-failure --skip readme
30+
- if: |
31+
github.event_name == 'push' ||
32+
github.event.pull_request.head.repo.full_name == github.repository ||
33+
github.actor == 'koxudaxi' ||
34+
github.actor == 'gaborbernat' ||
35+
github.actor == 'ilovelinux' ||
36+
(github.event_name == 'pull_request_target' && github.event.label.name == 'safe-to-fix' &&
37+
(github.event.sender.login == 'koxudaxi' ||
38+
github.event.sender.login == 'gaborbernat' ||
39+
github.event.sender.login == 'ilovelinux'))
40+
uses: stefanzweifel/git-auto-commit-action@v5
41+
with:
42+
commit_message: "style: auto-fix by prek"

.github/workflows/readme.yaml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,33 @@ on:
99
branches: [main]
1010
paths:
1111
- 'src/datamodel_code_generator/**'
12+
pull_request_target:
13+
types: [labeled]
14+
paths:
15+
- 'src/datamodel_code_generator/**'
1216

1317
permissions:
1418
contents: write
1519

1620
jobs:
1721
update-readme:
18-
if: github.event_name == 'push' || !github.event.pull_request.head.repo.fork
22+
if: |
23+
github.event_name == 'push' ||
24+
!github.event.pull_request.head.repo.fork ||
25+
github.actor == 'koxudaxi' ||
26+
github.actor == 'gaborbernat' ||
27+
github.actor == 'ilovelinux' ||
28+
(github.event_name == 'pull_request_target' && github.event.label.name == 'safe-to-fix' &&
29+
(github.event.sender.login == 'koxudaxi' ||
30+
github.event.sender.login == 'gaborbernat' ||
31+
github.event.sender.login == 'ilovelinux'))
1932
runs-on: ubuntu-latest
2033
steps:
2134
- uses: actions/checkout@v4
2235
with:
2336
fetch-depth: 0
24-
ref: ${{ github.head_ref || github.ref }}
37+
ref: ${{ github.event.pull_request.head.ref || github.ref }}
38+
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
2539
token: ${{ secrets.PAT }}
2640
- name: Install the latest version of uv
2741
uses: astral-sh/setup-uv@v5

.pre-commit-config.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
ci:
2-
skip: [readme]
3-
41
repos:
52
- repo: https://github.com/python-jsonschema/check-jsonschema
63
rev: 0.35.0

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ isort5 = [ "isort>=5,<6" ]
113113
isort6 = [ "isort>=6,<7" ]
114114
isort7 = [ "isort>=7,<8; python_version>='3.10'" ]
115115
pydantic1 = [ "pydantic<2" ]
116-
fix = [ "pre-commit-uv>=4.1.4" ]
116+
fix = [ "prek>=0.2.22" ]
117117
pkg-meta = [ "check-wheel-contents>=0.6.1", "twine>=6.1", "uv>=0.5.22" ]
118118
coverage = [
119119
"covdefaults>=2.3",

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ dependency_groups =
5858
[testenv:fix]
5959
description = format the code base to adhere to our styles, and complain about what we cannot do automatically
6060
commands =
61-
pre-commit run --all-files --show-diff-on-failure
61+
prek run --all-files --show-diff-on-failure
6262
dependency_groups = fix
6363

6464
[testenv:readme]

0 commit comments

Comments
 (0)