Skip to content

Commit cc2ac7c

Browse files
authored
[FEAT] Go Pre-Commit (#12)
Implemented pre-commit mvp in Go
1 parent 1307e78 commit cc2ac7c

182 files changed

Lines changed: 19937 additions & 3213 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/.env.shared

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -84,26 +84,30 @@ STALE_OPERATIONS_PER_RUN=300 # Maximum API operations per w
8484
# ───────────────────────────────────────────────────────────────────────────────
8585
SYNC_LABELS_FILE=.github/labels.yml # Path to the labels manifest file
8686

87-
# ───────────────────────────────────────────────────────────────────────────────
88-
# ENV: Python Dependencies Workflow Configuration
89-
# ───────────────────────────────────────────────────────────────────────────────
90-
UPDATE_PYTHON_DEPENDENCIES_BRANCH=chore/update-python-dependencies # Branch name for python dependency update PRs
91-
PIP_DIRECTORY=.github/pip # Directory containing all pip requirement files
92-
UPDATE_PYTHON_DEPENDENCIES_SCHEDULE_UPDATE_MAIN=true # Default: Update main requirements on scheduled runs
93-
UPDATE_PYTHON_DEPENDENCIES_SCHEDULE_UPDATE_PIP_TOOLS=true # Default: Update pip-tools requirements on scheduled runs
94-
UPDATE_PYTHON_DEPENDENCIES_SCHEDULE_CREATE_PR=true # Default: Create PR on scheduled runs
95-
UPDATE_PYTHON_DEPENDENCIES_PR_LABELS=dependencies,chore # Labels to apply to PRs (comma-separated)
96-
UPDATE_PYTHON_DEPENDENCIES_PR_ASSIGNEE=mrz1836 # Default assignee for PRs
9787

9888
# ───────────────────────────────────────────────────────────────────────────────
99-
# ENV: Pre-commit Hooks Workflow Configuration
100-
# ───────────────────────────────────────────────────────────────────────────────
101-
UPDATE_PRE_COMMIT_HOOKS_BRANCH=chore/update-pre-commit-hooks # Branch name for pre-commit update PRs
102-
PRE_COMMIT_CONFIG_FILE=.pre-commit-config.yaml # Path to the pre-commit config file
103-
UPDATE_PRE_COMMIT_HOOKS_SCHEDULE_CREATE_PR=true # Default: Create PR on scheduled runs
104-
UPDATE_PRE_COMMIT_HOOKS_PR_LABELS=dependencies,chore # Labels to apply to PRs (comma-separated)
105-
UPDATE_PRE_COMMIT_HOOKS_PR_ASSIGNEE=mrz1836 # Default assignee for PRs
106-
UPDATE_PRE_COMMIT_HOOKS_TEST_ON_UPDATE=true # Default: Test hooks after update
89+
# ENV: GoFortress Pre-commit System Configuration
90+
# ───────────────────────────────────────────────────────────────────────────────
91+
ENABLE_PRE_COMMIT_SYSTEM=true # Enable GoFortress pre-commit system integration
92+
PRE_COMMIT_SYSTEM_DIRECTORY=.github/pre-commit # Directory containing the self-contained pre-commit module
93+
PRE_COMMIT_SYSTEM_ENABLED_CHECKS=lint,format,security,test # Comma-separated list of enabled checks
94+
PRE_COMMIT_SYSTEM_FAIL_FAST=false # Stop on first failure vs run all checks
95+
PRE_COMMIT_SYSTEM_TIMEOUT_SECONDS=120 # Maximum time allowed for all pre-commit checks in seconds
96+
PRE_COMMIT_SYSTEM_VERBOSE_OUTPUT=false # Enable verbose logging for debugging
97+
PRE_COMMIT_SYSTEM_CONFIG_FILE=.github/pre-commit/config.yml # Path to pre-commit system configuration
98+
PRE_COMMIT_SYSTEM_EXCLUDE_PATHS=vendor/,third_party/,testdata/ # Comma-separated paths to exclude from checks
99+
PRE_COMMIT_SYSTEM_EXCLUDE_FILES=*.pb.go,*_mock.go,mock_*.go # Comma-separated file patterns to exclude
100+
PRE_COMMIT_SYSTEM_GO_VERSION_REQUIRED=1.22 # Minimum Go version required for pre-commit checks
101+
PRE_COMMIT_SYSTEM_GOLANGCI_LINT_VERSION=v1.61.0 # Version of golangci-lint to use
102+
PRE_COMMIT_SYSTEM_FUMPT_VERSION=v0.7.0 # Version of gofumpt to use for formatting
103+
PRE_COMMIT_SYSTEM_GOVULNCHECK_VERSION=v1.1.4 # Version of govulncheck for security scanning
104+
PRE_COMMIT_SYSTEM_AUTO_UPDATE_BRANCH=chore/update-pre-commit-system # Branch name for auto-update PRs
105+
PRE_COMMIT_SYSTEM_AUTO_UPDATE_ENABLED=true # Enable automatic updates of pre-commit tools
106+
PRE_COMMIT_SYSTEM_AUTO_UPDATE_SCHEDULE=weekly # Update schedule: daily, weekly, monthly
107+
PRE_COMMIT_SYSTEM_PR_LABELS=pre-commit-system,chore # Labels to apply to PRs (comma-separated)
108+
PRE_COMMIT_SYSTEM_PR_ASSIGNEE=mrz1836 # Default assignee for PRs
109+
PRE_COMMIT_SYSTEM_PARALLEL_WORKERS=2 # Number of parallel workers (0 = auto)
110+
PRE_COMMIT_SYSTEM_LOG_LEVEL=debug # Log level: debug, info, warn, error
107111

108112
# ───────────────────────────────────────────────────────────────────────────────
109113
# ENV: Dependabot Auto-merge Workflow Configuration

.github/CLAUDE.md

Lines changed: 99 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This repository uses **`AGENTS.md`** as the entry point to our modular technical
1111
* **Infrastructure**: CI/CD, dependencies, security, workflows
1212
* **Project Management**: Labeling conventions
1313

14-
> **TL;DR:** **Start with `AGENTS.md`**, then explore specific conventions in **`tech-conventions/`**.
14+
> **TL;DR:** **Start with `AGENTS.md`**, then explore specific conventions in **`tech-conventions/`**.
1515
> All technical questions are answered in these focused documents.
1616
1717
---
@@ -64,7 +64,7 @@ make test-all-modules-race # Test all modules with race detection
6464
```bash
6565
# Phase-specific integration tests
6666
make test-integration-complex # Phase 1: Complex workflows
67-
make test-integration-advanced # Phase 2: Advanced scenarios
67+
make test-integration-advanced # Phase 2: Advanced scenarios
6868
make test-integration-network # Phase 3: Network edge cases
6969
make test-integration-all # All integration test phases
7070
```
@@ -161,7 +161,7 @@ go tool pprof mem.prof
161161
```bash
162162
# Run tests with verbose output
163163
go test -v ./...
164-
164+
165165
# Run specific failing test
166166
go test -v -run TestSpecificFunction ./internal/package
167167
```
@@ -171,7 +171,7 @@ go tool pprof mem.prof
171171
# Fix formatting issues
172172
make fumpt # Apply gofumpt formatting
173173
goimports -w . # Fix import statements
174-
174+
175175
# Check linting rules
176176
make lint-version # Show linter version
177177
make lint # Run all linters
@@ -182,7 +182,7 @@ go tool pprof mem.prof
182182
# Profile memory usage
183183
go test -bench=. -memprofile=mem.prof ./internal/component
184184
go tool pprof mem.prof
185-
185+
186186
# Monitor goroutines
187187
go test -bench=. -trace=trace.out ./internal/worker
188188
go tool trace trace.out
@@ -292,6 +292,98 @@ The GoFortress coverage system uses an **incremental deployment strategy** that
292292
- **Missing branch coverage**: Ensure the branch has pushed after coverage setup
293293
- **PR badge not showing**: Check that `COVERAGE_PR_COMMENT_ENABLED=true` in `.env.shared`
294294

295+
### 🪝 GoFortress Pre-commit System
296+
297+
The GoFortress Pre-commit System is a **production-ready, high-performance Go-native pre-commit framework** that delivers 17x faster execution than traditional Python-based solutions.
298+
299+
**Quick Setup:**
300+
```bash
301+
# Navigate to pre-commit system
302+
cd .github/pre-commit
303+
304+
# Build and install
305+
make build
306+
./gofortress-pre-commit install
307+
308+
# Normal development - hooks run automatically
309+
git add .
310+
git commit -m "feat: new feature"
311+
# ✅ All checks passed in <2s
312+
```
313+
314+
**Key Features:**
315+
-**17x faster execution** - <2 second commits with parallel processing
316+
- 📦 **Zero Python dependencies** - Pure Go binary, no runtime requirements
317+
- 🔧 **Make integration** - Wraps existing Makefile targets (fumpt, lint, mod-tidy)
318+
- ⚙️ **Environment-driven** - All configuration via `.github/.env.shared`
319+
- 🎯 **Production ready** - 80.6% test coverage with comprehensive validation
320+
321+
**Available Checks (5 MVP checks):**
322+
1. **fumpt** - Code formatting via `make fumpt`
323+
2. **lint** - Linting via `make lint`
324+
3. **mod-tidy** - Module tidying via `make mod-tidy`
325+
4. **whitespace** - Trailing whitespace removal (built-in)
326+
5. **eof** - End-of-file newline enforcement (built-in)
327+
328+
**Configuration in `.github/.env.shared`:**
329+
```bash
330+
# Enable the system
331+
ENABLE_PRE_COMMIT_SYSTEM=true
332+
333+
# Individual check control
334+
PRE_COMMIT_SYSTEM_ENABLE_FUMPT=true
335+
PRE_COMMIT_SYSTEM_ENABLE_LINT=true
336+
PRE_COMMIT_SYSTEM_ENABLE_MOD_TIDY=true
337+
PRE_COMMIT_SYSTEM_ENABLE_WHITESPACE=true
338+
PRE_COMMIT_SYSTEM_ENABLE_EOF=true
339+
340+
# Performance tuning
341+
PRE_COMMIT_SYSTEM_PARALLEL_WORKERS=0 # 0 = auto (CPU count)
342+
PRE_COMMIT_SYSTEM_TIMEOUT_MINUTES=10
343+
PRE_COMMIT_SYSTEM_FAIL_FAST=false
344+
```
345+
346+
**Development Commands:**
347+
```bash
348+
# Manual execution
349+
./gofortress-pre-commit run # All checks on staged files
350+
./gofortress-pre-commit run --all-files # All checks on all files
351+
./gofortress-pre-commit run lint fumpt # Specific checks only
352+
./gofortress-pre-commit run --verbose # Debug output
353+
354+
# Skip functionality
355+
SKIP=lint git commit -m "wip: work in progress"
356+
PRE_COMMIT_SYSTEM_SKIP=all git commit -m "hotfix: critical fix"
357+
358+
# Status and management
359+
./gofortress-pre-commit status --verbose # Installation status
360+
./gofortress-pre-commit uninstall # Remove hooks
361+
```
362+
363+
**CI/CD Integration:**
364+
```yaml
365+
# Automatic integration via fortress-pre-commit.yml
366+
pre-commit:
367+
name: 🪝 Pre-commit Checks
368+
if: needs.setup.outputs.pre-commit-enabled == 'true'
369+
uses: ./.github/workflows/fortress-pre-commit.yml
370+
```
371+
372+
**Performance Benchmarks:**
373+
- **Total pipeline**: <2s (17x faster than baseline)
374+
- **fumpt**: 6ms (37% faster)
375+
- **lint**: 68ms (94% faster)
376+
- **mod-tidy**: 110ms (53% faster)
377+
- **Text processing**: <1ms (built-in speed)
378+
379+
**Troubleshooting:**
380+
- **"gofortress-pre-commit not found"**: Run `cd .github/pre-commit && make build`
381+
- **"make: gofumpt: No such file or directory"**: Install with `go install mvdan.cc/gofumpt@latest`
382+
- **"Hook already exists"**: Use `./gofortress-pre-commit install --force`
383+
- **Slow execution**: Increase timeout with `PRE_COMMIT_SYSTEM_TIMEOUT_MINUTES=15`
384+
385+
**📚 Complete Documentation:** [`.github/pre-commit/README.md`](.github/pre-commit/README.md)
386+
295387
### 📚 Documentation Navigation
296388

297389
**Core Documentation:**
@@ -372,7 +464,7 @@ Before starting any development work:
372464
```bash
373465
make mod-download
374466
make install-stdlib
375-
pre-commit install # Optional but recommended
467+
cd .github/pre-commit && make build && ./gofortress-pre-commit install # Optional but recommended
376468
```
377469
3. **Validate environment:**
378470
```bash
@@ -407,7 +499,7 @@ Before starting any development work:
407499
- **Security first** - Run `govulncheck` and validate all external dependencies
408500
- **Performance matters** - Use benchmarks to validate optimizations
409501

410-
If you encounter conflicting guidance elsewhere, `AGENTS.md` wins.
502+
If you encounter conflicting guidance elsewhere, `AGENTS.md` wins.
411503
Questions or ambiguities? Open a discussion or ping a maintainer instead of guessing.
412504

413505
---

.github/CODE_STANDARDS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# ✅ Code Standards
22

3-
Welcome to a modern Go codebase.
3+
Welcome to a modern Go codebase.
44

55
This library follows best-in-class practices for clarity, performance, and maintainability.
66

77
<br/>
88

99
## 🎓 Effective Go
1010

11-
We adhere to the patterns and philosophy in [Effective Go](https://golang.org/doc/effective_go.html).
11+
We adhere to the patterns and philosophy in [Effective Go](https://golang.org/doc/effective_go.html).
1212

1313
Stick to idiomatic code. Avoid cleverness when clarity wins.
1414

.github/CONTRIBUTING.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ Thank you for your interest in contributing to go-broadcast! This document provi
1212
## 📦 How to Contribute
1313

1414
1. **Fork the repo** and create a feature branch
15-
2. **Install pre-commit hooks**:
15+
2. **Install GoFortress Pre-commit System**:
1616
```bash
17-
pip install pre-commit
18-
pre-commit install
17+
cd .github/pre-commit
18+
make build
19+
./gofortress-pre-commit install
1920
```
2021
3. **Development setup**:
2122
```bash
@@ -113,7 +114,7 @@ if !regexp.MustCompile(`^[a-zA-Z0-9._-]+/[a-zA-Z0-9._-]+$`).MatchString(repo) {
113114
// ✅ Use shared benchmark patterns
114115
func BenchmarkOperation(b *testing.B) {
115116
files := benchmark.SetupBenchmarkFiles(b, tempDir, 100)
116-
117+
117118
benchmark.WithMemoryTracking(b, func() {
118119
for i := 0; i < b.N; i++ {
119120
processFiles(files)
@@ -213,7 +214,7 @@ func TestNewFunction(t *testing.T) {
213214
tests := []testutil.TestCase[Input, Output]{
214215
{Name: "description", Input: input, Expected: output, WantErr: false},
215216
}
216-
217+
217218
testutil.RunTableTests(t, tests, func(t *testing.T, tc testutil.TestCase[Input, Output]) {
218219
result, err := NewFunction(tc.Input)
219220
if tc.WantErr {
@@ -257,12 +258,12 @@ func ProcessFile(path string) error {
257258
if err := validation.ValidatePath(path); err != nil {
258259
return err
259260
}
260-
261+
261262
data, err := os.ReadFile(path)
262263
if err != nil {
263264
return errors.WrapWithContext(err, "read file")
264265
}
265-
266+
266267
return processData(data)
267268
}
268269
```
@@ -273,7 +274,7 @@ func ProcessFile(path string) error {
273274
func TestFileProcessing(t *testing.T) {
274275
tempDir := testutil.CreateTestDirectory(t)
275276
files := testutil.CreateTestFiles(t, tempDir, 5)
276-
277+
277278
for _, file := range files {
278279
err := ProcessFile(file)
279280
testutil.AssertNoError(t, err)
@@ -368,4 +369,4 @@ For detailed workflows, commit standards, branch naming, PR templates, and more
368369

369370
<br/>
370371

371-
Thank you for contributing to go-broadcast! Let's build something great. 💪 🎉
372+
Thank you for contributing to go-broadcast! Let's build something great. 💪 🎉

.github/SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ We welcome responsible disclosures from researchers, vendors, users, and curious
3535
* 📢 **Status updates** every 5 business days
3636
***Resolution target** of 30 days (for confirmed vulnerabilities)
3737

38-
Prefer encrypted comms? Let us know in your initial email—we’ll reply with our PGP public key.
38+
Prefer encrypted comms? Let us know in your initial email—we’ll reply with our PGP public key.
3939
All official security responses are signed with it.
4040

4141
<br/>

.github/actions/warm-cache/action.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -201,37 +201,37 @@ runs:
201201
if [ -f ".github/coverage/go.mod" ]; then
202202
echo "📊 Warming coverage module cache..."
203203
cd .github/coverage
204-
204+
205205
echo "⬇️ Downloading coverage module dependencies..."
206206
go mod download
207-
207+
208208
echo "🔧 Pre-building coverage module packages..."
209209
go build $(if [ "${{ inputs.enable-verbose }}" = "true" ]; then echo "-v"; fi) ./...
210-
210+
211211
echo "🏗️ Building coverage tool executable..."
212212
cd cmd/gofortress-coverage
213213
go build -o /tmp/gofortress-coverage .
214214
cd ../../..
215-
215+
216216
echo "✅ Coverage module cache warmed comprehensively"
217217
fi
218218
219219
# Also warm pre-commit module dependencies
220220
if [ -f ".github/pre-commit/go.mod" ]; then
221221
echo "🪝 Warming pre-commit module cache..."
222222
cd .github/pre-commit
223-
223+
224224
echo "⬇️ Downloading pre-commit module dependencies..."
225225
go mod download
226-
226+
227227
echo "🔧 Pre-building pre-commit module packages..."
228228
go build $(if [ "${{ inputs.enable-verbose }}" = "true" ]; then echo "-v"; fi) ./...
229-
229+
230230
echo "🏗️ Building pre-commit tool executable..."
231-
cd cmd/gofortress-hooks
232-
go build -o /tmp/gofortress-hooks .
231+
cd cmd/gofortress-pre-commit
232+
go build -o /tmp/gofortress-pre-commit .
233233
cd ../../..
234-
234+
235235
echo "✅ Pre-commit module cache warmed comprehensively"
236236
fi
237237

.github/coverage/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ coverage.txt
1616

1717
# OS files
1818
.DS_Store
19-
Thumbs.db
19+
Thumbs.db

.github/coverage/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ The PR comment feature provides beautiful, informative coverage comments with an
129129

130130
### Features
131131
- **Single Comment Per PR**: Automatically updates existing comments instead of creating new ones
132-
- **Anti-Spam Protection**:
132+
- **Anti-Spam Protection**:
133133
- Maximum 1 comment per PR
134134
- Minimum 5-minute update interval
135135
- Only updates on significant changes (>1% coverage change)
@@ -187,4 +187,4 @@ go test ./...
187187

188188
## License
189189

190-
This coverage system inherits the license from the parent repository.
190+
This coverage system inherits the license from the parent repository.

.github/coverage/cmd/gofortress-coverage/cmd/complete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ var ErrEmptyIndexHTML = errors.New("generated index.html is empty")
7373
var completeCmd = &cobra.Command{ //nolint:gochecknoglobals // CLI command
7474
Use: "complete",
7575
Short: "Run complete coverage pipeline",
76-
Long: `Run the complete coverage pipeline: parse coverage, generate badge and report,
76+
Long: `Run the complete coverage pipeline: parse coverage, generate badge and report,
7777
update history, and create GitHub PR comment if in PR context.`,
7878
RunE: func(cmd *cobra.Command, _ []string) error {
7979
// Get flags

.github/coverage/docs/IMPLEMENTATION_SUMMARY.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ Successfully implemented the PR comment feature for the GoFortress coverage syst
88
### 1. Anti-Spam Protection
99
- **Single Comment Per PR**: Only one coverage comment per PR (configured via `MaxCommentsPerPR: 1`)
1010
- **Update Existing Comments**: Automatically finds and updates existing coverage comments instead of creating new ones
11-
- **Smart Update Logic**:
11+
- **Smart Update Logic**:
1212
- Minimum 5-minute interval between updates
1313
- Only updates on significant changes (>1% coverage difference)
1414
- Uses metadata signature `gofortress-coverage-v1` to identify comments
1515

1616
### 2. Beautiful Template System
17-
- **Multiple Templates**:
17+
- **Multiple Templates**:
1818
- `comprehensive`: Full details with badges, metrics, and trends
19-
- `detailed`: Deep analysis with file-level breakdowns
19+
- `detailed`: Deep analysis with file-level breakdowns
2020
- `compact`: Clean, minimal design
2121
- `summary`: High-level overview
2222
- `minimal`: Just the essentials

0 commit comments

Comments
 (0)