-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile
More file actions
160 lines (126 loc) · 5.33 KB
/
Makefile
File metadata and controls
160 lines (126 loc) · 5.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# Makefile for Bon HTTP Router Library
.PHONY: help test lint clean bench coverage fmt vet mod-tidy mod-download test-verbose dev-setup ci check perf profile-mem profile-cpu bench-compare qt qb watch
# Default target
.DEFAULT_GOAL := help
# Colors for output
CYAN := \033[36m
RESET := \033[0m
# Help - Show available commands
help: ## Show this help message
@echo "Available commands:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "$(CYAN)%-20s$(RESET) %s\n", $$1, $$2}'
# ==================== Basic Commands ====================
# Run all tests
test: ## Run all tests
@echo "Running tests..."
go test -v ./...
# Run linter
lint: ## Run golangci-lint
@echo "Running lint..."
@which golangci-lint > /dev/null || (echo "golangci-lint not found. Install with: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"; exit 1)
golangci-lint run
# Clean generated files
clean: ## Clean test artifacts and generated files
@echo "Cleaning up..."
go clean
rm -f coverage.out coverage.html *.prof
# ==================== Code Quality ====================
# Format code
fmt: ## Format code using go fmt and gofmt
@echo "Formatting code..."
go fmt ./...
gofmt -s -w .
# Run go vet
vet: ## Run go vet
@echo "Running go vet..."
go vet ./...
# Run all checks
check: fmt vet lint test ## Run all code quality checks (fmt, vet, lint, test)
# ==================== Testing ====================
# Run tests with race detector and coverage
test-verbose: ## Run tests with race detector and coverage report
@echo "Running tests with coverage..."
go test -v -race -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
# Generate coverage report
coverage: ## Generate test coverage report
@echo "Generating coverage report..."
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
# ==================== Benchmarks ====================
# Run all benchmarks
bench: ## Run all benchmarks
@echo "Running benchmarks..."
go test -bench=. -benchmem ./...
# Run benchmarks and save to BENCHMARK_RESULTS.md
bench-save: ## Run benchmarks and save results to BENCHMARK_RESULTS.md
@echo "Running benchmarks and saving to BENCHMARK_RESULTS.md..."
@echo "# Benchmark Results" > BENCHMARK_RESULTS.md
@echo "" >> BENCHMARK_RESULTS.md
@echo "Generated on: $$(date '+%Y-%m-%d %H:%M:%S')" >> BENCHMARK_RESULTS.md
@echo "" >> BENCHMARK_RESULTS.md
@echo "## System Information" >> BENCHMARK_RESULTS.md
@echo "\`\`\`" >> BENCHMARK_RESULTS.md
@echo "OS: $$(go env GOOS)" >> BENCHMARK_RESULTS.md
@echo "Arch: $$(go env GOARCH)" >> BENCHMARK_RESULTS.md
@echo "Go Version: $$(go version | awk '{print $$3}')" >> BENCHMARK_RESULTS.md
@echo "CPU: $$(sysctl -n machdep.cpu.brand_string 2>/dev/null || grep -m 1 'model name' /proc/cpuinfo 2>/dev/null | cut -d: -f2 | xargs || echo 'Unknown')" >> BENCHMARK_RESULTS.md
@echo "\`\`\`" >> BENCHMARK_RESULTS.md
@echo "" >> BENCHMARK_RESULTS.md
@echo "## Benchmark Results" >> BENCHMARK_RESULTS.md
@echo "\`\`\`" >> BENCHMARK_RESULTS.md
@go test -bench=. -benchmem ./... >> BENCHMARK_RESULTS.md 2>&1
@echo "\`\`\`" >> BENCHMARK_RESULTS.md
@echo "Benchmark results saved to BENCHMARK_RESULTS.md"
# Run specific benchmarks for comparison
bench-compare: ## Run router benchmarks for comparison
@echo "Running router comparison benchmarks..."
go test -bench=BenchmarkMux -benchmem ./...
# Run performance tests
perf: ## Run performance benchmarks (5s duration)
@echo "Running performance tests..."
go test -run=XXX -bench=. -benchtime=5s -benchmem ./...
# ==================== Profiling ====================
# Generate memory profile
profile-mem: ## Generate memory profile
@echo "Generating memory profile..."
go test -bench=BenchmarkMuxStaticRoute -benchmem -memprofile=mem.prof
@echo "View profile with: go tool pprof mem.prof"
# Generate CPU profile
profile-cpu: ## Generate CPU profile
@echo "Generating CPU profile..."
go test -bench=BenchmarkMuxStaticRoute -cpuprofile=cpu.prof
@echo "View profile with: go tool pprof cpu.prof"
# ==================== Dependencies ====================
# Tidy go modules
mod-tidy: ## Run go mod tidy
@echo "Tidying modules..."
go mod tidy
# Download dependencies
mod-download: ## Download go modules
@echo "Downloading dependencies..."
go mod download
# ==================== Development ====================
# Setup development environment
dev-setup: ## Setup development environment (install tools)
@echo "Setting up development environment..."
go mod download
@echo "Installing development tools..."
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
@echo "Development environment ready!"
# ==================== CI/CD ====================
# Run CI pipeline
ci: lint test ## Run CI pipeline (lint, test)
# ==================== Quick Commands ====================
# Quick test without verbose output
qt: ## Quick test (no verbose)
@go test ./...
# Quick benchmark
qb: ## Quick benchmark (1s duration)
@go test -bench=. -benchtime=1s ./...
# Watch for changes and run tests (requires entr)
watch: ## Watch files and run tests on change (requires entr)
@which entr > /dev/null || (echo "entr not found. Install with your package manager."; exit 1)
@find . -name "*.go" | entr -c make test