Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
85 changes: 85 additions & 0 deletions .github/workflows/template-pr-inspection.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Template PR Inspection

on:
pull_request:
paths:
- 'src/fastapi_fastkit/fastapi_project_template/**'
types:
- opened
- synchronize

permissions:
contents: read
pull-requests: write

jobs:
inspect-changed-templates:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for git diff

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.12"

- name: Setup PDM
uses: pdm-project/setup-pdm@v4

- name: Install dependencies
run: pdm install -G dev

- name: Install UV package manager
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
echo "$HOME/.cargo/bin" >> $GITHUB_PATH

Comment thread
bnbong marked this conversation as resolved.
Outdated
- name: Verify UV installation
run: |
export PATH="$HOME/.cargo/bin:$PATH"
uv --version
which uv

- name: Set up Docker Compose
run: |
if ! command -v docker-compose &> /dev/null; then
echo "Installing Docker Compose..."
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
fi

docker --version
docker-compose --version
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Downloading the latest docker-compose binary directly into /usr/local/bin without pinning/verification can break builds unexpectedly and is a supply-chain risk. Consider using the built-in docker compose plugin on ubuntu-latest, or install a pinned version via an official action/package manager with integrity checks.

Suggested change
if ! command -v docker-compose &> /dev/null; then
echo "Installing Docker Compose..."
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
fi
docker --version
docker-compose --version
docker --version
docker compose version

Copilot uses AI. Check for mistakes.

- name: Inspect changed templates
run: |
export PATH="$HOME/.cargo/bin:$PATH"
pdm run python scripts/inspect-changed-templates.py

- name: Comment on PR (Success)
if: success()
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '✅ **Template Inspection Passed**\n\nAll changed templates have been validated successfully.'
})

- name: Comment on PR (Failure)
if: failure()
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '❌ **Template Inspection Failed**\n\nPlease check the workflow logs for details on what needs to be fixed.\n\n[View Logs](' + context.payload.repository.html_url + '/actions/runs/' + context.runId + ')'
})
Comment thread
bnbong marked this conversation as resolved.
Outdated
53 changes: 35 additions & 18 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
default_language_version:
python: python3.12
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
rev: v6.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -15,29 +13,48 @@ repos:
hooks:
- id: format
name: format
entry: bash scripts/format.sh
language: system
entry: black --config pyproject.toml --check .
language: python
types: [python]
additional_dependencies: ['black>=24.10.0']
pass_filenames: false
Comment thread
bnbong marked this conversation as resolved.

- id: isort-check
name: isort check
entry: isort --sp pyproject.toml --check-only --diff .
language: python
types: [python]
additional_dependencies: ['isort>=5.13.2']
pass_filenames: false

- id: lint
name: lint
entry: bash scripts/lint.sh
language: system
- id: isort-fix
name: isort fix
entry: isort --sp pyproject.toml .
language: python
types: [python]
additional_dependencies: ['isort>=5.13.2']
pass_filenames: false

- id: coverage-test
name: coverage test
entry: bash scripts/coverage-report.sh
language: system
- id: black-fix
name: black fix
entry: black --config pyproject.toml .
language: python
types: [python]
additional_dependencies: ['black>=24.10.0']
pass_filenames: false
Comment thread
bnbong marked this conversation as resolved.

- id: inspect-templates
name: inspect changed fastapi templates
entry: python scripts/inspect-changed-templates.py
language: system
- id: mypy
name: mypy
entry: mypy --config-file pyproject.toml src
language: python
types: [python]
additional_dependencies:
- mypy>=1.12.0
- rich>=13.9.2
- click>=8.1.7
- pyyaml>=6.0.0
- types-PyYAML>=6.0.12
pass_filenames: false
stages: [commit]

ci:
autofix_commit_msg: 🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
Expand Down
11 changes: 11 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ Pre-commit hooks are automatically installed with `make dev-setup`. The hooks wi
- Code formatting (black, isort)
- Linting checks
- Type checking (mypy)
- Coverage test
Comment thread
bnbong marked this conversation as resolved.
Outdated

If pre-commit finds issues, fix them and commit again:

Expand Down Expand Up @@ -290,6 +291,16 @@ template-name/

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

#### ✅ CI/CD Template Inspection

When you submit a PR that modifies template files, the **Template PR Inspection** workflow automatically runs:

- 🔍 **Automatic Trigger**: Runs when files in `src/fastapi_fastkit/fastapi_project_template/` are modified
- ✅ **Validation**: Inspects changed templates using `inspect-changed-templates.py`
- 💬 **PR Feedback**: Posts success/failure comments directly on your PR

Additionally, a **Weekly Template Inspection** runs every Wednesday to validate all templates.

#### ✅ Automatic Template Testing

**Zero Configuration Required:**
Expand Down
41 changes: 24 additions & 17 deletions docs/en/contributing/code-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -645,35 +645,42 @@ We use pre-commit hooks to enforce standards:
```yaml
# .pre-commit-config.yaml
repos:
- repo: https://github.com/psf/black
rev: 23.1.0
- repo: local
hooks:
- id: black
- id: isort-check
name: isort-check
entry: isort --check-only --sp pyproject.toml .
language: python
additional_dependencies: [isort]
pass_filenames: false
always_run: true

- id: black-fix
name: black-fix
entry: black --config pyproject.toml .
language: python
additional_dependencies: [black]
pass_filenames: false
always_run: true

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.0.1
hooks:
- id: mypy
name: mypy
entry: mypy --config-file pyproject.toml src
language: python
additional_dependencies: [mypy]
pass_filenames: false
always_run: true
Comment thread
bnbong marked this conversation as resolved.
Outdated
```

> **Note:** Pre-commit hooks use isolated Python environments (`language: python`), ensuring compatibility with external Git tools like GitKraken and Sourcetree.

### IDE Configuration

Recommended VS Code settings:

```json
{
"python.linting.enabled": true,
"python.linting.flake8Enabled": true,
"python.linting.mypyEnabled": true,
"python.formatting.provider": "black",
"python.sortImports.path": "isort",
Expand Down
Loading
Loading