-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
194 lines (165 loc) · 5.63 KB
/
Copy pathMakefile
File metadata and controls
194 lines (165 loc) · 5.63 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
.PHONY: help test test-verbose test-coverage test-unit test-integration clean build run docker-build docker-run lint fmt
# Default target
help:
@echo "Available targets:"
@echo " make test - Run all tests"
@echo " make test-verbose - Run tests with verbose output"
@echo " make test-coverage - Run tests with coverage report"
@echo " make test-unit - Run only unit tests"
@echo " make test-integration - Run only integration tests"
@echo " make test-short - Run tests in short mode (skip slow tests)"
@echo " make bench - Run benchmarks"
@echo " make lint - Run linter"
@echo " make fmt - Format code"
@echo " make build - Build the application"
@echo " make run - Run the application"
@echo " make clean - Clean build artifacts"
@echo " make docker-build - Build Docker image"
@echo " make docker-run - Run Docker container"
# Run all tests
test:
@echo "Running all tests..."
go test ./...
# Run tests with verbose output
test-verbose:
@echo "Running tests with verbose output..."
go test -v ./...
# Run tests with coverage
test-coverage:
@echo "Running tests with coverage..."
go test -v -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
go tool cover -func=coverage.out
# Run only unit tests (exclude integration tests)
test-unit:
@echo "Running unit tests..."
go test -v ./pkg/...
# Run only integration tests
test-integration:
@echo "Running integration tests..."
go test -v ./cmd/...
# Run tests in short mode
test-short:
@echo "Running tests in short mode..."
go test -short ./...
# Run benchmarks
bench:
@echo "Running benchmarks..."
go test -bench=. -benchmem ./...
# Run benchmarks with CPU profiling
bench-cpu:
@echo "Running benchmarks with CPU profiling..."
go test -bench=. -benchmem -cpuprofile=cpu.prof ./...
@echo "CPU profile saved to cpu.prof"
@echo "View with: go tool pprof cpu.prof"
# Run benchmarks with memory profiling
bench-mem:
@echo "Running benchmarks with memory profiling..."
go test -bench=. -benchmem -memprofile=mem.prof ./...
@echo "Memory profile saved to mem.prof"
@echo "View with: go tool pprof mem.prof"
# Run specific test by name
# Usage: make test-run TEST=TestName
test-run:
@echo "Running test: $(TEST)"
go test -v -run $(TEST) ./...
# Run linter (requires golangci-lint)
lint:
@echo "Running linter..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run ./...; \
else \
echo "golangci-lint not found. Install it from https://golangci-lint.run/"; \
echo "Or run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin"; \
fi
# Format code
fmt:
@echo "Formatting code..."
go fmt ./...
gofmt -s -w .
# Vet code
vet:
@echo "Vetting code..."
go vet ./...
# Run all checks (fmt, vet, lint, test)
check: fmt vet lint test
@echo "All checks passed!"
# Build the application
build:
@echo "Building application..."
go build -o bin/super-utils ./cmd/
# Build with version info
build-version:
@echo "Building application with version info..."
@VERSION=$$(git describe --tags --always --dirty 2>/dev/null || echo "dev"); \
BUILD_TIME=$$(date -u '+%Y-%m-%d_%H:%M:%S'); \
go build -ldflags "-X main.Version=$$VERSION -X main.BuildTime=$$BUILD_TIME" -o bin/super-utils ./cmd/
# Run the application
run:
@echo "Running application..."
go run ./cmd/
# Run with race detector
run-race:
@echo "Running application with race detector..."
go run -race ./cmd/
# Clean build artifacts and test cache
clean:
@echo "Cleaning build artifacts..."
rm -f bin/super-utils
rm -f coverage.out coverage.html
rm -f cpu.prof mem.prof
go clean -testcache
go clean -cache
# Download dependencies
deps:
@echo "Downloading dependencies..."
go mod download
go mod tidy
# Update dependencies
deps-update:
@echo "Updating dependencies..."
go get -u ./...
go mod tidy
# Build Docker image
docker-build:
@echo "Building Docker image..."
docker build -t super-utils:latest .
# Run Docker container
docker-run:
@echo "Running Docker container..."
docker run -p 8000:8000 super-utils:latest
# Show test coverage by package
coverage-by-package:
@echo "Test coverage by package:"
go test -coverprofile=coverage.out ./... > /dev/null 2>&1
go tool cover -func=coverage.out | grep -E '^github.com' | column -t
# Generate test report
test-report:
@echo "Generating test report..."
go test -v -json ./... > test-report.json
@echo "Test report saved to test-report.json"
# Watch and run tests on file changes (requires entr or similar)
test-watch:
@echo "Watching for changes and running tests..."
@if command -v find >/dev/null 2>&1 && command -v entr >/dev/null 2>&1; then \
find . -name '*.go' | entr -c make test; \
else \
echo "This target requires 'entr'. Install it with your package manager."; \
echo " Ubuntu/Debian: apt-get install entr"; \
echo " macOS: brew install entr"; \
fi
# Initialize project (install tools)
init:
@echo "Initializing project..."
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go mod download
@echo "Project initialized!"
# Show project statistics
stats:
@echo "Project Statistics:"
@echo "===================="
@echo "Total Go files: $$(find . -name '*.go' | wc -l)"
@echo "Total lines of code: $$(find . -name '*.go' -exec cat {} \; | wc -l)"
@echo "Total test files: $$(find . -name '*_test.go' | wc -l)"
@echo "Test coverage: $$(go test -coverprofile=coverage.out ./... > /dev/null 2>&1 && go tool cover -func=coverage.out | grep total | awk '{print $$3}')"