Skip to content

Commit 82b59dd

Browse files
authored
Merge pull request #39 from bnbong/dev
[DOCS, FIX] edit pre-commit hooks, update FastAPI-fastkit guides
2 parents 6224140 + df75477 commit 82b59dd

File tree

7 files changed

+329
-113
lines changed

7 files changed

+329
-113
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: Template PR Inspection
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'src/fastapi_fastkit/fastapi_project_template/**'
7+
types:
8+
- opened
9+
- synchronize
10+
11+
permissions:
12+
contents: read
13+
pull-requests: write
14+
15+
jobs:
16+
inspect-changed-templates:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0 # Fetch all history for git diff
24+
25+
- name: Set up Python
26+
uses: actions/setup-python@v4
27+
with:
28+
python-version: "3.12"
29+
30+
- name: Setup PDM
31+
uses: pdm-project/setup-pdm@v4
32+
33+
- name: Install dependencies
34+
run: pdm install -G dev
35+
36+
- name: Setup UV
37+
uses: astral-sh/setup-uv@v7
38+
39+
- name: Verify Docker and Compose
40+
run: |
41+
docker --version
42+
docker compose version
43+
44+
- name: Inspect changed templates
45+
run: pdm run python scripts/inspect-changed-templates.py
46+
47+
- name: Create or Update PR Comment
48+
if: always()
49+
uses: actions/github-script@v7
50+
with:
51+
script: |
52+
const marker = '<!-- template-inspection-bot -->';
53+
const success = '${{ job.status }}' === 'success';
54+
55+
const successBody = `${marker}
56+
✅ **Template Inspection Passed**
57+
58+
All changed templates have been validated successfully.
59+
60+
---
61+
*Last updated: ${new Date().toISOString()}*`;
62+
63+
const failureBody = `${marker}
64+
❌ **Template Inspection Failed**
65+
66+
Please check the workflow logs for details on what needs to be fixed.
67+
68+
[View Logs](${context.payload.repository.html_url}/actions/runs/${context.runId})
69+
70+
---
71+
*Last updated: ${new Date().toISOString()}*`;
72+
73+
const body = success ? successBody : failureBody;
74+
75+
// Find existing bot comment
76+
const { data: comments } = await github.rest.issues.listComments({
77+
owner: context.repo.owner,
78+
repo: context.repo.repo,
79+
issue_number: context.issue.number
80+
});
81+
82+
const botComment = comments.find(comment =>
83+
comment.body.includes(marker)
84+
);
85+
86+
if (botComment) {
87+
// Update existing comment
88+
await github.rest.issues.updateComment({
89+
owner: context.repo.owner,
90+
repo: context.repo.repo,
91+
comment_id: botComment.id,
92+
body: body
93+
});
94+
console.log('Updated existing comment');
95+
} else {
96+
// Create new comment
97+
await github.rest.issues.createComment({
98+
owner: context.repo.owner,
99+
repo: context.repo.repo,
100+
issue_number: context.issue.number,
101+
body: body
102+
});
103+
console.log('Created new comment');
104+
}

.pre-commit-config.yaml

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
# See https://pre-commit.com for more information
22
# See https://pre-commit.com/hooks.html for more hooks
3-
default_language_version:
4-
python: python3.12
53
repos:
64
- repo: https://github.com/pre-commit/pre-commit-hooks
7-
rev: v3.2.0
5+
rev: v6.0.0
86
hooks:
97
- id: trailing-whitespace
108
- id: end-of-file-fixer
@@ -15,29 +13,48 @@ repos:
1513
hooks:
1614
- id: format
1715
name: format
18-
entry: bash scripts/format.sh
19-
language: system
16+
entry: black --config pyproject.toml --check .
17+
language: python
18+
types: [python]
19+
additional_dependencies: ['black>=24.10.0']
20+
pass_filenames: false
21+
22+
- id: isort-check
23+
name: isort check
24+
entry: isort --sp pyproject.toml --check-only --diff .
25+
language: python
26+
types: [python]
27+
additional_dependencies: ['isort>=5.13.2']
2028
pass_filenames: false
2129

22-
- id: lint
23-
name: lint
24-
entry: bash scripts/lint.sh
25-
language: system
30+
- id: isort-fix
31+
name: isort fix
32+
entry: isort --sp pyproject.toml .
33+
language: python
34+
types: [python]
35+
additional_dependencies: ['isort>=5.13.2']
2636
pass_filenames: false
2737

28-
- id: coverage-test
29-
name: coverage test
30-
entry: bash scripts/coverage-report.sh
31-
language: system
38+
- id: black-fix
39+
name: black fix
40+
entry: black --config pyproject.toml .
41+
language: python
3242
types: [python]
43+
additional_dependencies: ['black>=24.10.0']
3344
pass_filenames: false
3445

35-
- id: inspect-templates
36-
name: inspect changed fastapi templates
37-
entry: python scripts/inspect-changed-templates.py
38-
language: system
46+
- id: mypy
47+
name: mypy
48+
entry: mypy --config-file pyproject.toml src
49+
language: python
50+
types: [python]
51+
additional_dependencies:
52+
- mypy>=1.12.0
53+
- rich>=13.9.2
54+
- click>=8.1.7
55+
- pyyaml>=6.0.0
56+
- types-PyYAML>=6.0.12
3957
pass_filenames: false
40-
stages: [commit]
4158

4259
ci:
4360
autofix_commit_msg: 🎨 [pre-commit.ci] Auto format from pre-commit.com hooks

CONTRIBUTING.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,16 @@ template-name/
290290

291291
FastAPI-fastkit includes **automated template testing** that provides comprehensive validation:
292292

293+
#### ✅ CI/CD Template Inspection
294+
295+
When you submit a PR that modifies template files, the **Template PR Inspection** workflow automatically runs:
296+
297+
- 🔍 **Automatic Trigger**: Runs when files in `src/fastapi_fastkit/fastapi_project_template/` are modified
298+
-**Validation**: Inspects changed templates using `inspect-changed-templates.py`
299+
- 💬 **PR Feedback**: Posts success/failure comments directly on your PR
300+
301+
Additionally, a **Weekly Template Inspection** runs every Wednesday to validate all templates.
302+
293303
#### ✅ Automatic Template Testing
294304

295305
**Zero Configuration Required:**

docs/en/contributing/code-guidelines.md

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -645,35 +645,75 @@ We use pre-commit hooks to enforce standards:
645645
```yaml
646646
# .pre-commit-config.yaml
647647
repos:
648-
- repo: https://github.com/psf/black
649-
rev: 23.1.0
648+
- repo: https://github.com/pre-commit/pre-commit-hooks
649+
rev: v6.0.0
650650
hooks:
651-
- id: black
651+
- id: trailing-whitespace
652+
- id: end-of-file-fixer
653+
- id: check-yaml
654+
- id: check-toml
652655
653-
- repo: https://github.com/pycqa/isort
654-
rev: 5.12.0
656+
- repo: local
655657
hooks:
656-
- id: isort
657-
658-
- repo: https://github.com/pycqa/flake8
659-
rev: 6.0.0
660-
hooks:
661-
- id: flake8
662-
663-
- repo: https://github.com/pre-commit/mirrors-mypy
664-
rev: v1.0.1
665-
hooks:
666-
- id: mypy
658+
- id: format
659+
name: format
660+
entry: black --config pyproject.toml --check .
661+
language: python
662+
types: [python]
663+
additional_dependencies: ['black>=24.10.0']
664+
pass_filenames: false
665+
666+
- id: isort-check
667+
name: isort check
668+
entry: isort --sp pyproject.toml --check-only --diff .
669+
language: python
670+
types: [python]
671+
additional_dependencies: ['isort>=5.13.2']
672+
pass_filenames: false
673+
674+
- id: isort-fix
675+
name: isort fix
676+
entry: isort --sp pyproject.toml .
677+
language: python
678+
types: [python]
679+
additional_dependencies: ['isort>=5.13.2']
680+
pass_filenames: false
681+
682+
- id: black-fix
683+
name: black fix
684+
entry: black --config pyproject.toml .
685+
language: python
686+
types: [python]
687+
additional_dependencies: ['black>=24.10.0']
688+
pass_filenames: false
689+
690+
- id: mypy
691+
name: mypy
692+
entry: mypy --config-file pyproject.toml src
693+
language: python
694+
types: [python]
695+
additional_dependencies:
696+
- mypy>=1.12.0
697+
- rich>=13.9.2
698+
- click>=8.1.7
699+
- pyyaml>=6.0.0
700+
- types-PyYAML>=6.0.12
701+
pass_filenames: false
702+
703+
ci:
704+
autofix_commit_msg: 🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
705+
autoupdate_commit_msg: ⬆ [pre-commit.ci] pre-commit autoupdate
667706
```
668707
708+
> **Note:** Pre-commit hooks use isolated Python environments (`language: python`).
709+
669710
### IDE Configuration
670711
671712
Recommended VS Code settings:
672713
673714
```json
674715
{
675716
"python.linting.enabled": true,
676-
"python.linting.flake8Enabled": true,
677717
"python.linting.mypyEnabled": true,
678718
"python.formatting.provider": "black",
679719
"python.sortImports.path": "isort",

0 commit comments

Comments
 (0)