-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
313 lines (270 loc) · 15.9 KB
/
Makefile
File metadata and controls
313 lines (270 loc) · 15.9 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
# ╔════════════════════════════════════════════════════════════════════════════╗
# ║ REGLET MAKEFILE ║
# ╚════════════════════════════════════════════════════════════════════════════╝
#
# Usage: make <target>
# Run 'make help' for a list of available targets
#
.PHONY: all build clean test test-race test-coverage lint fmt vet help install dev
.PHONY: fuzz fuzz-nightly fuzz-extended profile-cpu profile-mem test-bench tidy changelog
# ─────────────────────────────────────────────────────────────────────────────
# Configuration
# ─────────────────────────────────────────────────────────────────────────────
BINARY_NAME := reglet
VERSION ?= dev
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_DATE := $(shell date -u '+%Y-%m-%d_%H:%M:%S')
LDFLAGS := -ldflags "\
-X github.com/reglet-dev/reglet/internal/infrastructure/build.Version=$(VERSION) \
-X github.com/reglet-dev/reglet/internal/infrastructure/build.Commit=$(COMMIT) \
-X github.com/reglet-dev/reglet/internal/infrastructure/build.BuildDate=$(BUILD_DATE)"
# Go commands
GOCMD := go
GOBUILD := $(GOCMD) build
GOCLEAN := $(GOCMD) clean
GOTEST := $(GOCMD) test
GOGET := $(GOCMD) get
GOMOD := $(GOCMD) mod
GOFMT := $(GOCMD) fmt
GOVET := $(GOCMD) vet
# ─────────────────────────────────────────────────────────────────────────────
# Colors and Formatting
# ─────────────────────────────────────────────────────────────────────────────
# Colors
RESET := \033[0m
BOLD := \033[1m
RED := \033[31m
GREEN := \033[32m
YELLOW := \033[33m
BLUE := \033[34m
MAGENTA := \033[35m
CYAN := \033[36m
WHITE := \033[37m
# Styled prefixes
INFO := @printf "$(BOLD)$(CYAN)▸$(RESET) "
SUCCESS := @printf "$(BOLD)$(GREEN)✓$(RESET) "
WARN := @printf "$(BOLD)$(YELLOW)⚠$(RESET) "
ERROR := @printf "$(BOLD)$(RED)✗$(RESET) "
STEP := @printf "$(BOLD)$(MAGENTA)→$(RESET) "
# ═══════════════════════════════════════════════════════════════════════════════
# PRIMARY TARGETS
# ═══════════════════════════════════════════════════════════════════════════════
.DEFAULT_GOAL := help
##@ Primary
all: clean lint test build ## Run full pipeline: clean → lint → test → build
$(SUCCESS)
@printf "$(GREEN)All tasks completed successfully!$(RESET)\n"
build: ## Build the reglet binary
$(INFO)
@printf "Building $(BOLD)$(BINARY_NAME)$(RESET)...\n"
@$(GOBUILD) $(LDFLAGS) -o bin/$(BINARY_NAME) ./cmd/reglet
$(SUCCESS)
@printf "Binary built: $(GREEN)bin/$(BINARY_NAME)$(RESET)\n"
dev: build ## Build and run locally
$(STEP)
@printf "Running $(BOLD)$(BINARY_NAME)$(RESET)...\n"
@./bin/$(BINARY_NAME)
install: build ## Install binary to $$GOPATH/bin
$(INFO)
@printf "Installing $(BOLD)$(BINARY_NAME)$(RESET) to $(GOPATH)/bin...\n"
@cp bin/$(BINARY_NAME) $(GOPATH)/bin/
$(SUCCESS)
@printf "Installed to $(GREEN)$(GOPATH)/bin/$(BINARY_NAME)$(RESET)\n"
# ═══════════════════════════════════════════════════════════════════════════════
# TESTING
# ═══════════════════════════════════════════════════════════════════════════════
##@ Testing
test: ## Run all tests with race detector
$(INFO)
@printf "Running tests with race detector...\n"
@$(GOTEST) -v -race ./...
$(SUCCESS)
@printf "$(GREEN)All tests passed$(RESET)\n"
test-race: ## Run tests with race detector (alias)
$(INFO)
@printf "Running tests with race detector...\n"
@$(GOTEST) -race ./...
test-coverage: ## Run tests with coverage report
$(INFO)
@printf "Running tests with coverage...\n"
@$(GOTEST) -coverprofile=coverage.out ./...
@$(GOCMD) tool cover -html=coverage.out -o coverage.html
$(SUCCESS)
@printf "Coverage report: $(GREEN)coverage.html$(RESET)\n"
test-bench: ## Run benchmark tests
$(INFO)
@printf "Running benchmarks...\n"
@$(GOTEST) -bench=. -benchmem ./...
# ═══════════════════════════════════════════════════════════════════════════════
# CODE QUALITY
# ═══════════════════════════════════════════════════════════════════════════════
##@ Code Quality
lint: ## Run golangci-lint
$(INFO)
@printf "Running linters...\n"
@which golangci-lint > /dev/null || (printf "$(RED)golangci-lint not found$(RESET)\n" && \
printf "Install: $(CYAN)https://golangci-lint.run/usage/install/$(RESET)\n" && exit 1)
@golangci-lint run ./...
$(SUCCESS)
@printf "$(GREEN)Linting passed$(RESET)\n"
fmt: ## Format Go source files
$(INFO)
@printf "Formatting code...\n"
@$(GOFMT) ./...
$(SUCCESS)
@printf "$(GREEN)Code formatted$(RESET)\n"
vet: ## Run go vet
$(INFO)
@printf "Running go vet...\n"
@$(GOVET) ./...
$(SUCCESS)
@printf "$(GREEN)Vet passed$(RESET)\n"
tidy: ## Tidy go.mod dependencies
$(INFO)
@printf "Tidying dependencies...\n"
@$(GOMOD) tidy
$(SUCCESS)
@printf "$(GREEN)Dependencies tidied$(RESET)\n"
changelog: ## Generate CHANGELOG.md from git history
$(INFO)
@printf "Generating changelog...\n"
@which git-cliff > /dev/null || (printf "$(RED)git-cliff not found$(RESET)\n" && \
printf "Install: $(CYAN)cargo install git-cliff$(RESET)\n" && exit 1)
@git-cliff -o CHANGELOG.md
$(SUCCESS)
@printf "$(GREEN)CHANGELOG.md updated$(RESET)\n"
# ═══════════════════════════════════════════════════════════════════════════════
# PROFILING
# ═══════════════════════════════════════════════════════════════════════════════
##@ Profiling
profile-cpu: ## Run CPU profiling (opens browser)
$(INFO)
@printf "Running CPU profiling...\n"
@$(GOTEST) -cpuprofile=cpu.prof -bench=. ./...
$(STEP)
@printf "Opening profile viewer at $(CYAN)http://localhost:8080$(RESET)\n"
@$(GOCMD) tool pprof -http=:8080 cpu.prof
profile-mem: ## Run memory profiling (opens browser)
$(INFO)
@printf "Running memory profiling...\n"
@$(GOTEST) -memprofile=mem.prof -bench=. ./...
$(STEP)
@printf "Opening profile viewer at $(CYAN)http://localhost:8080$(RESET)\n"
@$(GOCMD) tool pprof -http=:8080 mem.prof
# ═══════════════════════════════════════════════════════════════════════════════
# FUZZING
# ═══════════════════════════════════════════════════════════════════════════════
##@ Fuzzing
fuzz: ## Run all fuzz tests (5s each, for CI)
$(INFO)
@printf "Running fuzz tests $(YELLOW)(5s each)$(RESET)...\n"
@printf "\n$(BOLD)$(BLUE)◆ Capabilities$(RESET)\n"
@go test -fuzz=^FuzzNetworkPatternMatching$$ -fuzztime=5s ./internal/domain/capabilities/
@go test -fuzz=^FuzzFilesystemPatternMatching$$ -fuzztime=5s ./internal/domain/capabilities/
@go test -fuzz=^FuzzExecPatternMatching$$ -fuzztime=5s ./internal/domain/capabilities/
@go test -fuzz=^FuzzEnvironmentPatternMatching$$ -fuzztime=5s ./internal/domain/capabilities/
@printf "\n$(BOLD)$(BLUE)◆ Config$(RESET)\n"
@go test -fuzz=^FuzzYAMLLoading$$ -fuzztime=5s ./internal/infrastructure/config/
@go test -fuzz=^FuzzVariableSubstitution$$ -fuzztime=5s ./internal/infrastructure/config/
@printf "\n$(BOLD)$(BLUE)◆ Host Functions$(RESET)\n"
@printf " (Host function fuzz tests moved to reglet-host-sdk)\n"
@printf "\n$(BOLD)$(BLUE)◆ Validation$(RESET)\n"
@go test -fuzz=^FuzzPluginNameValidation$$ -fuzztime=5s ./internal/infrastructure/validation/
@go test -fuzz=^FuzzVersionValidation$$ -fuzztime=5s ./internal/infrastructure/validation/
@go test -fuzz=^FuzzSchemaValidation$$ -fuzztime=5s ./internal/infrastructure/validation/
@printf "\n$(BOLD)$(BLUE)◆ Redaction$(RESET)\n"
@go test -fuzz=^FuzzRedactorScrubString$$ -fuzztime=5s ./internal/infrastructure/sensitivedata/
@go test -fuzz=^FuzzRedactorWalker$$ -fuzztime=5s ./internal/infrastructure/sensitivedata/
@printf "\n$(BOLD)$(BLUE)◆ Output$(RESET)\n"
@go test -fuzz=^FuzzSARIFGeneration$$ -fuzztime=5s ./internal/infrastructure/output/
$(SUCCESS)
@printf "$(GREEN)Fuzz tests completed$(RESET)\n"
fuzz-extended: ## Run extended fuzz tests (30m each)
$(WARN)
@printf "Running $(BOLD)extended$(RESET) fuzz tests $(YELLOW)(30m each)$(RESET)...\n"
@printf "$(YELLOW)This will take several hours to complete!$(RESET)\n\n"
@printf "$(BOLD)$(BLUE)◆ Capabilities$(RESET)\n"
@go test -fuzz=^FuzzNetworkPatternMatching$$ -fuzztime=30m ./internal/domain/capabilities/
@go test -fuzz=^FuzzFilesystemPatternMatching$$ -fuzztime=30m ./internal/domain/capabilities/
@go test -fuzz=^FuzzExecPatternMatching$$ -fuzztime=30m ./internal/domain/capabilities/
@go test -fuzz=^FuzzEnvironmentPatternMatching$$ -fuzztime=30m ./internal/domain/capabilities/
@printf "\n$(BOLD)$(BLUE)◆ Config$(RESET)\n"
@go test -fuzz=^FuzzYAMLLoading$$ -fuzztime=30m ./internal/infrastructure/config/
@go test -fuzz=^FuzzVariableSubstitution$$ -fuzztime=30m ./internal/infrastructure/config/
@printf "\n$(BOLD)$(BLUE)◆ Host Functions$(RESET)\n"
@printf " (Host function fuzz tests moved to reglet-host-sdk)\n"
@printf "\n$(BOLD)$(BLUE)◆ Validation$(RESET)\n"
@go test -fuzz=^FuzzPluginNameValidation$$ -fuzztime=30m ./internal/infrastructure/validation/
@go test -fuzz=^FuzzVersionValidation$$ -fuzztime=30m ./internal/infrastructure/validation/
@go test -fuzz=^FuzzSchemaValidation$$ -fuzztime=30m ./internal/infrastructure/validation/
@printf "\n$(BOLD)$(BLUE)◆ Redaction$(RESET)\n"
@go test -fuzz=^FuzzRedactorScrubString$$ -fuzztime=30m ./internal/infrastructure/sensitivedata/
@go test -fuzz=^FuzzRedactorWalker$$ -fuzztime=30m ./internal/infrastructure/sensitivedata/
@printf "\n$(BOLD)$(BLUE)◆ Output$(RESET)\n"
@go test -fuzz=^FuzzSARIFGeneration$$ -fuzztime=30m ./internal/infrastructure/output/
$(SUCCESS)
@printf "$(GREEN)Extended fuzz tests completed$(RESET)\n"
fuzz-nightly: ## Run fuzz tests for nightly CI (1m each)
$(INFO)
@printf "Running $(BOLD)nightly$(RESET) fuzz tests $(YELLOW)(1m each)$(RESET)...\n"
@printf "\n$(BOLD)$(BLUE)◆ Capabilities$(RESET)\n"
@go test -fuzz=^FuzzNetworkPatternMatching$$ -fuzztime=1m ./internal/domain/capabilities/
@go test -fuzz=^FuzzFilesystemPatternMatching$$ -fuzztime=1m ./internal/domain/capabilities/
@go test -fuzz=^FuzzExecPatternMatching$$ -fuzztime=1m ./internal/domain/capabilities/
@go test -fuzz=^FuzzEnvironmentPatternMatching$$ -fuzztime=1m ./internal/domain/capabilities/
@printf "\n$(BOLD)$(BLUE)◆ Config$(RESET)\n"
@go test -fuzz=^FuzzYAMLLoading$$ -fuzztime=1m ./internal/infrastructure/config/
@go test -fuzz=^FuzzVariableSubstitution$$ -fuzztime=1m ./internal/infrastructure/config/
@printf "\n$(BOLD)$(BLUE)◆ Host Functions$(RESET)\n"
@printf " (Host function fuzz tests moved to reglet-host-sdk)\n"
@printf "\n$(BOLD)$(BLUE)◆ Validation$(RESET)\n"
@go test -fuzz=^FuzzPluginNameValidation$$ -fuzztime=1m ./internal/infrastructure/validation/
@go test -fuzz=^FuzzVersionValidation$$ -fuzztime=1m ./internal/infrastructure/validation/
@go test -fuzz=^FuzzSchemaValidation$$ -fuzztime=1m ./internal/infrastructure/validation/
@printf "\n$(BOLD)$(BLUE)◆ Redaction$(RESET)\n"
@go test -fuzz=^FuzzRedactorScrubString$$ -fuzztime=1m ./internal/infrastructure/sensitivedata/
@go test -fuzz=^FuzzRedactorWalker$$ -fuzztime=1m ./internal/infrastructure/sensitivedata/
@printf "\n$(BOLD)$(BLUE)◆ Output$(RESET)\n"
@go test -fuzz=^FuzzSARIFGeneration$$ -fuzztime=1m ./internal/infrastructure/output/
$(SUCCESS)
@printf "$(GREEN)Nightly fuzz tests completed$(RESET)\n"
# ═══════════════════════════════════════════════════════════════════════════════
# CLEANUP
# ═══════════════════════════════════════════════════════════════════════════════
##@ Cleanup
clean: ## Remove build artifacts and generated files
$(INFO)
@printf "Cleaning build artifacts...\n"
@$(GOCLEAN)
@rm -rf bin/
@rm -rf coverage.out coverage.html
@rm -rf *.prof
$(SUCCESS)
@printf "$(GREEN)Clean complete$(RESET)\n"
# ═══════════════════════════════════════════════════════════════════════════════
# HELP
# ═══════════════════════════════════════════════════════════════════════════════
##@ Help
help: ## Show this help message
@printf "\n"
@printf "$(BOLD)$(CYAN)╔════════════════════════════════════════════════════════════════╗$(RESET)\n"
@printf "$(BOLD)$(CYAN)║$(RESET) $(BOLD)REGLET$(RESET) - Makefile Help $(BOLD)$(CYAN)║$(RESET)\n"
@printf "$(BOLD)$(CYAN)╚════════════════════════════════════════════════════════════════╝$(RESET)\n"
@printf "\n"
@printf "$(BOLD)Usage:$(RESET) make $(CYAN)<target>$(RESET)\n\n"
@awk 'BEGIN {FS = ":.*##"; section=""} \
/^##@/ { \
section=substr($$0, 5); \
printf "\n$(BOLD)$(YELLOW)%s$(RESET)\n", section \
} \
/^[a-zA-Z_-]+:.*?##/ { \
if (section != "") { \
printf " $(CYAN)%-18s$(RESET) %s\n", $$1, $$2 \
} \
}' $(MAKEFILE_LIST)
@printf "\n"
@printf "$(BOLD)Examples:$(RESET)\n"
@printf " make build $(WHITE)# Build the binary$(RESET)\n"
@printf " make test $(WHITE)# Run all tests$(RESET)\n"
@printf " make all $(WHITE)# Full CI pipeline$(RESET)\n"
@printf "\n"