Skip to content

Commit 48e5f2f

Browse files
Reorganize template structure and enhance pre-commit workflow
Major changes: - Reorganized repository: moved framework files to template/ directory - Enhanced pre-commit with 12+ new quality checks - Added JSON and YAML auto-formatting - Added commit message validation hook - Implemented CI caching for 40-80s faster builds - Created comprehensive SETUP.md guide - Maintained triple-layer secret detection (defense-in-depth) - Updated README.md with commit-msg hook installation - Removed temporary documentation files New pre-commit hooks: - File validation: check-toml, check-added-large-files (1MB limit) - Filesystem: check-case-conflict, check-illegal-windows-names - Script integrity: check-executables-have-shebangs, verify permissions - Symlink validation: check-symlinks, destroyed-symlinks - Git protection: forbid-new-submodules - Formatting: pretty-format-json, yamlfmt, fix-byte-order-marker - Security: commit-msg hook for message validation CI improvements: - Pre-commit environment caching - Pip caching - 7-day artifact retention All pre-commit checks passing.
1 parent d6622ed commit 48e5f2f

17 files changed

Lines changed: 650 additions & 107 deletions

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ body:
99
label: Summary
1010
validations:
1111
required: true
12-
1312
- type: textarea
1413
id: repro
1514
attributes:
@@ -20,21 +19,18 @@ body:
2019
3. ...
2120
validations:
2221
required: true
23-
2422
- type: textarea
2523
id: expected
2624
attributes:
2725
label: Expected Behavior
2826
validations:
2927
required: true
30-
3128
- type: textarea
3229
id: actual
3330
attributes:
3431
label: Actual Behavior
3532
validations:
3633
required: true
37-
3834
- type: textarea
3935
id: env
4036
attributes:

.github/ISSUE_TEMPLATE/feature_request.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ body:
99
label: Problem Statement
1010
validations:
1111
required: true
12-
1312
- type: textarea
1413
id: outcome
1514
attributes:
1615
label: Desired Outcome
1716
validations:
1817
required: true
19-
2018
- type: textarea
2119
id: acceptance
2220
attributes:
@@ -26,7 +24,6 @@ body:
2624
- AC-2:
2725
validations:
2826
required: true
29-
3027
- type: textarea
3128
id: constraints
3229
attributes:

.github/workflows/ci.yaml

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,61 @@
11
name: CI
2-
32
on:
43
pull_request:
54
push:
65
branches: [main]
7-
86
permissions:
97
contents: read
10-
118
jobs:
129
pre-commit:
1310
name: Pre-commit Checks
1411
runs-on: ubuntu-latest
15-
1612
steps:
1713
- name: Checkout
1814
uses: actions/checkout@v4
19-
2015
- name: Set up Python
2116
uses: actions/setup-python@v5
2217
with:
2318
python-version: "3.11"
24-
19+
cache: 'pip'
20+
- name: Cache pre-commit environments
21+
uses: actions/cache@v4
22+
with:
23+
path: ~/.cache/pre-commit
24+
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
25+
restore-keys: |
26+
pre-commit-
2527
- name: Install pre-commit
2628
run: |
2729
python -m pip install --upgrade pip
2830
pip install pre-commit
29-
3031
- name: Run pre-commit (fast path)
3132
id: precommit_fast
3233
run: |
3334
pre-commit run --all-files
34-
3535
- name: Generate pre-commit log (only on failure)
3636
if: failure() && steps.precommit_fast.outcome == 'failure'
3737
run: |
38-
chmod +x scripts/run-precommit.sh
39-
./scripts/run-precommit.sh
40-
38+
chmod +x template/scripts/run-precommit.sh
39+
./template/scripts/run-precommit.sh
4140
- name: Upload pre-commit log artifact (only on failure)
4241
if: failure() && steps.precommit_fast.outcome == 'failure'
4342
uses: actions/upload-artifact@v4
4443
with:
4544
name: pre-commit-log
4645
path: artifacts/pre-commit.log
47-
46+
retention-days: 7
4847
tests:
4948
name: Unit Tests
5049
runs-on: ubuntu-latest
5150
needs: [pre-commit]
52-
5351
steps:
5452
- name: Checkout
5553
uses: actions/checkout@v4
56-
5754
- name: Set up Python
5855
uses: actions/setup-python@v5
5956
with:
6057
python-version: "3.11"
61-
58+
cache: 'pip'
6259
- name: Install dependencies
6360
run: |
6461
python -m pip install --upgrade pip
@@ -75,7 +72,6 @@ jobs:
7572
if [ -d tests ]; then
7673
pip install pytest
7774
fi
78-
7975
- name: Run pytest (if tests exist)
8076
run: |
8177
if [ -d tests ]; then

.github/workflows/security-ci.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
name: Security CI
2-
32
on:
43
pull_request:
54
push:
65
branches: ["main"]
76
workflow_dispatch:
8-
97
permissions:
108
contents: read
119
actions: read
1210
security-events: write
13-
1411
jobs:
1512
gitleaks:
1613
name: Secret scan (Gitleaks)
@@ -20,31 +17,25 @@ jobs:
2017
uses: actions/checkout@v4
2118
with:
2219
fetch-depth: 0
23-
2420
- name: Run Gitleaks
2521
uses: gitleaks/gitleaks-action@v2
26-
2722
semgrep:
2823
name: SAST (Semgrep CE)
2924
runs-on: ubuntu-latest
3025
steps:
3126
- name: Checkout
3227
uses: actions/checkout@v4
33-
3428
- name: Run Semgrep
3529
uses: returntocorp/semgrep-action@v1
3630
with:
3731
config: >-
38-
p/security-audit
39-
p/owasp-top-ten
32+
p/security-audit p/owasp-top-ten
4033
generateSarif: "1"
41-
4234
- name: Upload SARIF to GitHub Security
4335
uses: github/codeql-action/upload-sarif@v4
4436
if: always()
4537
with:
4638
sarif_file: semgrep.sarif
47-
4839
osv-scanner:
4940
name: Dependency vulns (OSV-Scanner)
5041
uses: google/osv-scanner-action/.github/workflows/osv-scanner-reusable.yml@v2.3.1

.pre-commit-config.yaml

Lines changed: 101 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,58 +4,149 @@ repos:
44
rev: v5.0.0
55
hooks:
66
- id: check-merge-conflict
7+
name: "🌳 git · Detect conflict markers"
78
- id: check-yaml
9+
name: "📄 format · Validate YAML syntax"
810
- id: check-json
11+
name: "📄 format · Validate JSON syntax"
12+
- id: check-toml
13+
name: "📄 format · Validate TOML syntax"
14+
- id: check-added-large-files
15+
name: "🌳 git · Block large file commits"
16+
args: ['--maxkb=1000']
17+
- id: check-case-conflict
18+
name: "📁 filesystem · Check case sensitivity"
19+
- id: check-illegal-windows-names
20+
name: "📁 filesystem · Validate Windows filenames"
21+
- id: check-executables-have-shebangs
22+
name: "📁 filesystem · Verify shebang presence"
23+
- id: check-shebang-scripts-are-executable
24+
name: "📁 filesystem · Verify script permissions"
25+
- id: check-symlinks
26+
name: "📁 filesystem · Check symlink validity"
27+
- id: destroyed-symlinks
28+
name: "📁 filesystem · Detect broken symlinks"
29+
- id: forbid-new-submodules
30+
name: "🌳 git · Prevent submodule creation"
931
- id: end-of-file-fixer
32+
name: "📄 format · Fix EOF"
1033
- id: trailing-whitespace
34+
name: "📄 format · Trim trailing whitespace"
1135
- id: mixed-line-ending
36+
name: "📄 format · Fix line endings"
1237
args: [--fix=lf]
38+
- id: fix-byte-order-marker
39+
name: "📄 format · Remove UTF-8 BOM"
40+
- id: pretty-format-json
41+
name: "📄 format · Auto-format JSON"
42+
args: ['--autofix', '--indent=2', '--no-sort-keys']
1343
- id: detect-private-key
14-
44+
name: "🔒 security · Detect private keys"
45+
# YAML formatting (consistent indentation and style)
46+
- repo: https://github.com/google/yamlfmt
47+
rev: v0.13.0
48+
hooks:
49+
- id: yamlfmt
50+
name: "📄 format · Auto-format YAML"
1551
# Custom secret detection (comprehensive API keys, tokens, credentials)
1652
- repo: local
1753
hooks:
1854
- id: detect-secrets
19-
name: Detect Secrets (API Keys, Tokens, Credentials)
20-
entry: scripts/detect-secrets.sh
55+
name: "🔒 security · Detect secrets (API keys, tokens, credentials)"
56+
entry: template/scripts/detect-secrets.sh
2157
language: system
2258
pass_filenames: false
2359
always_run: false
24-
60+
- id: check-commit-message
61+
name: "🔒 security · Check commit message (no secrets, IPs)"
62+
entry: template/scripts/check-commit-message.sh
63+
language: system
64+
stages: [commit-msg]
2565
# Python: Ruff (lint + autofix) and Ruff formatter
2666
- repo: https://github.com/astral-sh/ruff-pre-commit
2767
rev: v0.8.4
2868
hooks:
2969
- id: ruff
70+
name: "🐍 python · Lint and autofix with Ruff"
3071
args: [--fix]
3172
- id: ruff-format
32-
73+
name: "🐍 python · Format with Ruff"
3374
# Bash: ShellCheck
3475
- repo: https://github.com/shellcheck-py/shellcheck-py
3576
rev: v0.10.0.1
3677
hooks:
3778
- id: shellcheck
38-
79+
name: "🐚 shell · Lint with ShellCheck"
3980
# Bash: shfmt (format shell scripts)
4081
- repo: https://github.com/scop/pre-commit-shfmt
4182
rev: v3.8.0-1
4283
hooks:
4384
- id: shfmt
85+
name: "🐚 shell · Format with shfmt"
4486
args:
4587
- -w
4688
- -i
4789
- "2"
4890
- -ci
4991
- -sr
50-
5192
# Markdown: PyMarkdown (Python-based; avoids nodeenv/Node)
5293
- repo: https://github.com/jackdewinter/pymarkdown
5394
rev: v0.9.25
5495
hooks:
5596
- id: pymarkdown
97+
name: "📝 markdown · Lint with PyMarkdown"
5698
args: ["--config", ".pymarkdown.json", "scan"]
57-
exclude: ^\.github/pull_request_template\.md$
58-
59-
99+
exclude: ^(\.github/pull_request_template\.md|.*IMPROVEMENTS.*\.md|.*SUMMARY.*\.md)$
60100
default_language_version:
61101
python: python3
102+
103+
# ============================================================================
104+
# OPTIONAL HOOKS (uncomment to enable)
105+
# ============================================================================
106+
107+
# Optional: Prevent direct commits to main/master (forces PR workflow)
108+
# Note: GitHub branch protection rules are preferred for team environments
109+
# Uncomment the section below to enable:
110+
#
111+
# - repo: https://github.com/pre-commit/pre-commit-hooks
112+
# rev: v5.0.0
113+
# hooks:
114+
# - id: no-commit-to-branch
115+
# name: "🌳 git · Protect main branches"
116+
# args: ["--branch", "main", "--branch", "master"]
117+
118+
# Optional: Run fast tests before commit (good for mature projects with tests)
119+
# Requirements: pip install pytest
120+
# Tip: Mark slow tests with @pytest.mark.slow and exclude them with "-m 'not slow'"
121+
# Uncomment the section below to enable:
122+
#
123+
# - repo: local
124+
# hooks:
125+
# - id: pytest-collect
126+
# name: "🧪 test · Validate test formatting"
127+
# entry: pytest tests
128+
# language: system
129+
# types: [python]
130+
# args: ["--collect-only"]
131+
# pass_filenames: false
132+
# always_run: true
133+
# - id: pytest-fast
134+
# name: "🧪 test · Run fast tests (<3s each)"
135+
# entry: pytest tests
136+
# language: system
137+
# types: [python]
138+
# args: ["-m", "not slow", "--maxfail=1", "-x"]
139+
# pass_filenames: false
140+
# always_run: true
141+
142+
# Optional: SQL linting and formatting (only if project uses SQL files)
143+
# Requirements: pip install sqlfluff
144+
# Uncomment the section below to enable:
145+
#
146+
# - repo: https://github.com/sqlfluff/sqlfluff
147+
# rev: 3.3.0
148+
# hooks:
149+
# - id: sqlfluff-fix
150+
# name: "📊 SQL · Auto-fix rule violations"
151+
# - id: sqlfluff-lint
152+
# name: "📊 SQL · Lint SQL code files"

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,14 @@ cd <your-repo-name>
349349
```bash
350350
pip install pre-commit
351351
pre-commit install
352+
pre-commit install --hook-type commit-msg
352353
```
353354

354355
**Verification Checklist**:
355356

356357
- [ ] Pre-commit is installed
357-
- [ ] Pre-commit hooks are installed
358-
- [ ] Run `./scripts/run-precommit.sh` to verify setup
358+
- [ ] Pre-commit hooks are installed (both pre-commit and commit-msg)
359+
- [ ] Run `./template/scripts/run-precommit.sh` to verify setup
359360

360361
### Step 4: Populate Project-Specific Files
361362

0 commit comments

Comments
 (0)