-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
650 lines (588 loc) · 23.2 KB
/
Makefile
File metadata and controls
650 lines (588 loc) · 23.2 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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
# Project Root Makefile.
# Coordinates all component Makefiles and provides centralized commands.
# Define the root directory of the project
ROOT_DIR := $(shell pwd)
SERVICE_NAME := reporter
BIN_DIR := ./.bin
ARTIFACTS_DIR := ./artifacts
# Determine version: use git describe if available, else git short SHA
VERSION := $(shell git describe --tags --abbrev=0 2>/dev/null || git rev-parse --short HEAD 2>/dev/null || echo "dev")
# Docker command detection (supports both docker compose and docker-compose)
DOCKER_VERSION := $(shell docker version --format '{{.Server.Version}}' 2>/dev/null || echo "0")
DOCKER_MIN_VERSION := 20.10.13
DOCKER_CMD := $(shell \
if [ "$(shell printf '%s\n' "$(DOCKER_MIN_VERSION)" "$(DOCKER_VERSION)" | sort -V | head -n1)" = "$(DOCKER_MIN_VERSION)" ]; then \
echo "docker compose"; \
else \
echo "docker-compose"; \
fi \
)
# Component directories
INFRA_DIR := ./components/infra
MANAGER_DIR := ./components/manager
WORKER_DIR := ./components/worker
# Define a list of all component directories for easier iteration
BACKEND_COMPONENTS := $(WORKER_DIR) $(MANAGER_DIR)
COMPONENTS := $(INFRA_DIR) $(WORKER_DIR) $(MANAGER_DIR)
# Include shared utility functions
# Define common utility functions
define print_title
@echo ""
@echo "------------------------------------------"
@echo " 📝 $(1) "
@echo "------------------------------------------"
endef
# Check if a command is available
define check_command
@which $(1) > /dev/null || (echo "Error: $(1) is required but not installed. $(2)" && exit 1)
endef
# Check if environment files exist
define check_env_files
@missing=false; \
for dir in $(COMPONENTS); do \
if [ ! -f "$$dir/.env" ]; then \
missing=true; \
break; \
fi; \
done; \
if [ "$$missing" = "true" ]; then \
echo "Environment files are missing. Running set-env command first..."; \
$(MAKE) set-env; \
fi
endef
MK_DIR := $(abspath mk)
include $(MK_DIR)/tests.mk
#-------------------------------------------------------
# Help Command
#-------------------------------------------------------
help:
@echo ""
@echo ""
@echo "Reporter Commands"
@echo ""
@echo ""
@echo "Core Commands:"
@echo " make help - Display this help message"
@echo " make test - Run tests on all components"
@echo " make build - Build all components"
@echo " make clean - Clean all build artifacts"
@echo " make cover - Run test coverage"
@echo ""
@echo ""
@echo "Code Quality Commands:"
@echo " make lint - Run golangci-lint"
@echo " make lint-fix - Run golangci-lint with auto-fix"
@echo " make format - Format code with gofumpt"
@echo " make imports - Organize imports with goimports"
@echo " make tidy - Clean dependencies in root directory"
@echo " make check-tests - Verify test coverage for components"
@echo " make sec - Run security checks (gosec + govulncheck)"
@echo " make sec-gosec - Run gosec security scanner"
@echo " make sec-govulncheck - Run govulncheck vulnerability scanner"
@echo " make sec-trivy - Run Trivy container vulnerability scan"
@echo ""
@echo ""
@echo "Git Hook Commands:"
@echo " make setup-git-hooks - Install and configure git hooks"
@echo " make check-hooks - Verify git hooks installation status"
@echo " make check-envs - Check if github hooks are installed and secret env files are not exposed"
@echo ""
@echo ""
@echo "Setup Commands:"
@echo " make check-tools - Verify all required development tools are installed"
@echo " make dev-setup - Install all development tools and set up environment"
@echo " make set-env - Copy .env.example to .env for all components"
@echo ""
@echo ""
@echo "Service Commands:"
@echo " make up - Start all services with Docker Compose"
@echo " make down - Stop all services with Docker Compose"
@echo " make start - Start all containers"
@echo " make stop - Stop all containers"
@echo " make restart - Restart all containers"
@echo " make rebuild-up - Rebuild and restart all services"
@echo " make wait-for-infra - Wait for infrastructure services to become healthy"
@echo " make clean-docker - Clean all Docker resources (containers, networks, volumes)"
@echo " make logs - Show logs for all services"
@echo ""
@echo ""
@echo "Code Generation Commands:"
@echo " make generate - Run code generation (go generate)"
@echo " make generate-mocks - Generate mock files"
@echo ""
@echo ""
@echo "Documentation Commands:"
@echo " make generate-docs - Generate Swagger documentation for all services"
@echo " make serve-docs - Serve Swagger UI locally at http://localhost:8080"
@echo ""
@echo ""
@echo "Test Suite Aliases:"
@echo " make test-unit - Run Go unit tests (exclude ./tests/**)"
@echo " make test-integration - Run Go integration tests (brings up backend)"
@echo " make test-fuzzy - Run fuzz/robustness tests (brings up backend)"
@echo " make test-chaos - Run chaos/resilience tests (brings up backend)"
@echo " make test-property - Run property-based tests"
@echo " make test-all - Run all test suites (unit + integration + fuzz + chaos + property)"
@echo ""
@echo "Coverage Commands:"
@echo " make coverage-unit - Run unit tests with coverage report"
@echo ""
@echo ""
#-------------------------------------------------------
# Git Hook Commands
#-------------------------------------------------------
.PHONY: setup-git-hooks
setup-git-hooks:
$(call print_title,"Installing and configuring git hooks")
@sh ./scripts/setup-git-hooks.sh
@echo "[ok] Git hooks installed successfully ✔️"
.PHONY: check-hooks
check-hooks:
$(call print_title,"Verifying git hooks installation status")
@err=0; \
for hook_dir in .githooks/*; do \
hook_name=$$(basename $$hook_dir); \
if [ ! -f ".git/hooks/$$hook_name" ]; then \
echo "Git hook $$hook_name is not installed"; \
err=1; \
else \
echo "Git hook $$hook_name is installed"; \
fi; \
done; \
if [ $$err -eq 0 ]; then \
echo "[ok] All git hooks are properly installed ✔️"; \
else \
echo "[error] Some git hooks are missing. Run 'make setup-git-hooks' to fix. ❌"; \
exit 1; \
fi
.PHONY: check-envs
check-envs:
$(call print_title,"Checking if github hooks are installed and secret env files are not exposed")
@sh ./scripts/check-envs.sh
@echo "[ok] Environment check completed ✔️"
#-------------------------------------------------------
# Setup Commands
#-------------------------------------------------------
.PHONY: set-env
set-env:
$(call print_title,"Setting up environment files")
@for dir in $(COMPONENTS); do \
if [ -f "$$dir/.env.example" ] && [ ! -f "$$dir/.env" ]; then \
echo "Creating .env in $$dir from .env.example"; \
cp "$$dir/.env.example" "$$dir/.env"; \
elif [ ! -f "$$dir/.env.example" ]; then \
echo "Warning: No .env.example found in $$dir"; \
else \
echo ".env already exists in $$dir"; \
fi; \
done
@echo "[ok] Environment files set up successfully"
#-------------------------------------------------------
# Build Commands
#-------------------------------------------------------
.PHONY: build
build:
$(call print_title,Building all components)
@echo "Building backend components..."
@for dir in $(BACKEND_COMPONENTS); do \
component_name=$$(basename $$dir); \
echo "Building $$component_name..."; \
(cd $$dir && $(MAKE) build) || exit 1; \
done
@echo "[ok] All components built successfully"
.PHONY: cover
cover:
$(call print_title,Generating test coverage report)
@echo "Note: PostgreSQL repository tests are excluded from coverage metrics."
@echo "See coverage report for details on why and what is being tested."
$(call check_command,go,"Install Go from https://golang.org/doc/install")
@sh ./scripts/coverage.sh
@go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated at coverage.html"
@echo ""
@echo "Coverage Summary:"
@echo "----------------------------------------"
@go tool cover -func=coverage.out | grep total | awk '{print "Total coverage: " $$3}'
@echo "----------------------------------------"
@echo "Open coverage.html in your browser to view detailed coverage report"
@echo "[ok] Coverage report generated successfully ✔️"
.PHONY: cover-html
cover-html:
$(call print_title,"Generating HTML test coverage report")
@PACKAGES=$$(go list ./... | grep -v -f ./scripts/coverage_ignore.txt); \
go test -coverprofile=$(ARTIFACTS_DIR)/coverage.out $$PACKAGES
@go tool cover -html=$(ARTIFACTS_DIR)/coverage.out -o $(ARTIFACTS_DIR)/coverage.html
@echo "Coverage report generated at $(ARTIFACTS_DIR)/coverage.html"
@echo ""
@echo "Coverage Summary:"
@echo "----------------------------------------"
@go tool cover -func=$(ARTIFACTS_DIR)/coverage.out | grep total | awk '{print "Total coverage: " $$3}'
@echo "----------------------------------------"
@echo "Open $(ARTIFACTS_DIR)/coverage.html in your browser to view detailed coverage report"
#-------------------------------------------------------
# Test Coverage Commands
#-------------------------------------------------------
.PHONY: check-tests
check-tests:
$(call print_title,"Verifying test coverage")
@if find . -name "*.go" -type f | grep -q .; then \
echo "Running test coverage check..."; \
go test -coverprofile=coverage.tmp ./... > /dev/null 2>&1; \
if [ -f coverage.tmp ]; then \
coverage=$$(go tool cover -func=coverage.tmp | grep total | awk '{print $$3}'); \
echo "Test coverage: $$coverage"; \
rm coverage.tmp; \
else \
echo "No coverage data generated"; \
fi; \
else \
echo "No Go files found, skipping test coverage check"; \
fi
#-------------------------------------------------------
# Code Quality Commands
#-------------------------------------------------------
.PHONY: lint
lint: format imports
$(call print_title,"Running linters")
@if ! command -v golangci-lint >/dev/null 2>&1; then \
echo "golangci-lint not found, installing..."; \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; \
else \
echo "golangci-lint already installed ✔️"; \
fi
@golangci-lint run --fix ./... --verbose
@echo "[ok] Linting completed successfully"
.PHONY: format
format:
$(call print_title,"Formatting code with gofumpt")
@if ! command -v gofumpt >/dev/null 2>&1; then \
echo "Installing gofumpt..."; \
go install mvdan.cc/gofumpt@latest; \
fi
@gofumpt -w .
@echo "[ok] Formatting completed successfully ✔️"
.PHONY: imports
imports:
$(call print_title,"Organizing imports with goimports")
@if ! command -v goimports >/dev/null 2>&1; then \
echo "Installing goimports..."; \
go install golang.org/x/tools/cmd/goimports@latest; \
fi
@goimports -w .
@echo "[ok] Imports organized successfully ✔️"
.PHONY: tidy
tidy:
$(call print_title,"Update and Cleaning dependencies")
@go get -u ./...
@go mod tidy
@echo "[ok] Dependencies updated and cleaned successfully ✔️"
#-------------------------------------------------------
# Security Commands
#-------------------------------------------------------
.PHONY: sec-gosec
sec-gosec:
@if ! command -v gosec >/dev/null 2>&1; then \
echo "Installing gosec..."; \
go install github.com/securego/gosec/v2/cmd/gosec@latest; \
fi
@if find ./components ./pkg -name "*.go" -type f | grep -q .; then \
echo "Running gosec on components/ and pkg/ folders..."; \
if [ "$(SARIF)" = "1" ]; then \
echo "Generating SARIF output: gosec-report.sarif"; \
gosec -fmt sarif -out gosec-report.sarif ./components/... ./pkg/...; \
echo "[ok] SARIF report generated: gosec-report.sarif"; \
else \
gosec ./components/... ./pkg/...; \
fi; \
else \
echo "No Go files found, skipping gosec"; \
fi
.PHONY: sec-govulncheck
sec-govulncheck:
@if ! command -v govulncheck >/dev/null 2>&1; then \
echo "Installing govulncheck..."; \
go install golang.org/x/vuln/cmd/govulncheck@latest; \
fi
@if find ./components ./pkg -name "*.go" -type f | grep -q .; then \
echo "Running govulncheck on components/ and pkg/ folders..."; \
govulncheck ./components/... ./pkg/...; \
else \
echo "No Go files found, skipping govulncheck"; \
fi
.PHONY: sec
sec:
$(call print_title,Running security checks)
@$(MAKE) sec-gosec SARIF=$(SARIF)
@$(MAKE) sec-govulncheck
@echo "[ok] Security checks completed"
#-------------------------------------------------------
# Clean Commands
#-------------------------------------------------------
.PHONY: clean
clean:
@./scripts/clean-artifacts.sh
.PHONY: clean-docker
clean-docker:
$(call print_title,Cleaning all Docker resources)
@echo "Cleaning backend Docker resources..."
@for dir in $(BACKEND_COMPONENTS); do \
component_name=$$(basename $$dir); \
echo "Cleaning $$component_name Docker resources..."; \
(cd $$dir && $(MAKE) clean-docker 2>/dev/null || true); \
done
@echo "Cleaning infrastructure Docker resources..."
@cd $(INFRA_DIR) && $(MAKE) clean-docker 2>/dev/null || true
@echo "Pruning system-wide Docker resources..."
@docker system prune -f
@echo "Pruning system-wide Docker volumes..."
@docker volume prune -f
@echo "[ok] All Docker resources cleaned successfully"
#-------------------------------------------------------
# Docker Commands
#-------------------------------------------------------
.PHONY: run
run:
$(call print_title,"Running the manager application")
@cd components/manager && go run cmd/app/main.go
@echo "[ok] Application started successfully ✔️"
.PHONY: build-docker
build-docker:
$(call print_title,"Building Docker images")
@for dir in $(BACKEND_COMPONENTS); do \
component_name=$$(basename $$dir); \
echo "Building Docker image for $$component_name (version: $(VERSION))..."; \
(cd $$dir && IMAGE_TAG=$(VERSION) $(DOCKER_CMD) -f docker-compose.yml build $(c)) || exit 1; \
done
@echo "[ok] Docker images built successfully ✔️"
# Maximum time (in seconds) to wait for infrastructure health checks.
INFRA_HEALTH_TIMEOUT ?= 60
# Polling interval (in seconds) between health-check attempts.
INFRA_HEALTH_INTERVAL ?= 2
.PHONY: wait-for-infra
wait-for-infra:
@echo "Waiting for infrastructure services to become healthy..."
@cd $(INFRA_DIR) && \
attempts=$$(( $(INFRA_HEALTH_TIMEOUT) / $(INFRA_HEALTH_INTERVAL) )); \
for i in $$(seq 1 $$attempts); do \
HEALTHY=$$($(DOCKER_CMD) -f docker-compose.yml ps --format '{{.Health}}' 2>/dev/null | grep -c "healthy" || true); \
TOTAL=$$($(DOCKER_CMD) -f docker-compose.yml ps --format '{{.Health}}' 2>/dev/null | grep -c "." || true); \
if [ "$$HEALTHY" = "$$TOTAL" ] && [ "$$TOTAL" -gt 0 ]; then \
echo "All $$TOTAL infrastructure services are healthy"; \
exit 0; \
fi; \
echo "Waiting... ($$HEALTHY/$$TOTAL healthy, attempt $$i/$$attempts)"; \
sleep $(INFRA_HEALTH_INTERVAL); \
done; \
echo "[error] Infrastructure services failed to become healthy after $(INFRA_HEALTH_TIMEOUT)s"; \
cd $(INFRA_DIR) && $(DOCKER_CMD) -f docker-compose.yml ps; \
exit 1
.PHONY: up
up:
$(call print_title,"Starting services")
$(call check_env_files)
@echo "Starting infrastructure services first..."
@cd $(INFRA_DIR) && $(MAKE) up
@$(MAKE) wait-for-infra
@echo "Starting backend components..."
@for dir in $(BACKEND_COMPONENTS); do \
if [ -f "$$dir/docker-compose.yml" ]; then \
echo "Starting services in $$dir..."; \
(cd $$dir && $(MAKE) up) || exit 1; \
fi \
done
@echo "[ok] Services started successfully ✔️"
.PHONY: start
start:
$(call print_title,"Starting existing containers")
@for dir in $(COMPONENTS); do \
if [ -f "$$dir/docker-compose.yml" ]; then \
echo "Starting containers in $$dir..."; \
(cd $$dir && $(DOCKER_CMD) -f docker-compose.yml start $(c)) || exit 1; \
fi; \
done
@echo "[ok] All containers started successfully ✔️"
.PHONY: down
down:
$(call print_title,"Stopping services")
@echo "Stopping components..."
@for dir in $(BACKEND_COMPONENTS); do \
if [ -f "$$dir/docker-compose.yml" ]; then \
echo "Stopping services in $$dir..."; \
(cd $$dir && $(MAKE) down) || exit 1; \
fi \
done
@echo "Stopping infrastructure services..."
@cd $(INFRA_DIR) && $(MAKE) down
@echo "[ok] Services stopped successfully ✔️"
.PHONY: stop
stop:
@for dir in $(COMPONENTS); do \
if [ -f "$$dir/docker-compose.yml" ]; then \
echo "Stopping containers in $$dir..."; \
(cd $$dir && $(MAKE) stop) || exit 1; \
fi; \
done
@echo "[ok] All containers stopped successfully"
.PHONY: restart
restart:
$(call print_title,"Restarting services")
@make down && make up
@echo "[ok] Backend services successfully ✔️"
.PHONY: rebuild-up
rebuild-up:
$(call print_title,"Rebuilding and restarting services")
@echo "Rebuilding infrastructure services..."
@cd $(INFRA_DIR) && ($(DOCKER_CMD) -f docker-compose.yml build --no-cache && $(DOCKER_CMD) -f docker-compose.yml up -d --force-recreate)
@$(MAKE) wait-for-infra
@echo "Rebuilding backend components..."
@for dir in $(BACKEND_COMPONENTS); do \
if [ -f "$$dir/docker-compose.yml" ]; then \
echo "Rebuilding services in $$dir..."; \
(cd $$dir && $(DOCKER_CMD) -f docker-compose.yml build --no-cache && $(DOCKER_CMD) -f docker-compose.yml up -d --force-recreate) || exit 1; \
fi; \
done
@echo "[ok] Services rebuilt and restarted successfully ✔️"
.PHONY: logs
logs:
$(call print_title,"Showing logs for all services")
@for dir in $(COMPONENTS); do \
component_name=$$(basename $$dir); \
if [ -f "$$dir/docker-compose.yml" ]; then \
echo "Logs for component: $$component_name"; \
(cd $$dir && ($(DOCKER_CMD) -f docker-compose.yml logs --tail=50 2>/dev/null || $(DOCKER_CMD) -f docker-compose.yml logs --tail=50)) || exit 1; \
echo ""; \
fi; \
done
.PHONY: logs-api
logs-api:
$(call print_title,"Showing logs for reporter-manager service")
@cd $(MANAGER_DIR) && $(DOCKER_CMD) -f docker-compose.yml logs --tail=100 -f reporter-manager
.PHONY: ps
ps:
$(call print_title,"Listing container status")
@for dir in $(COMPONENTS); do \
if [ -f "$$dir/docker-compose.yml" ]; then \
component_name=$$(basename $$dir); \
echo "--- $$component_name ---"; \
(cd $$dir && $(DOCKER_CMD) -f docker-compose.yml ps) || true; \
echo ""; \
fi; \
done
#-------------------------------------------------------
# Docs Commands
#-------------------------------------------------------
.PHONY: serve-docs
serve-docs:
@echo "Serving Swagger UI at http://localhost:8080"
@docker run --rm -p 8080:8080 \
-e SWAGGER_JSON=/api/swagger.json \
-v $(shell pwd)/components/manager/api:/api \
swaggerapi/swagger-ui
.PHONY: generate-docs
generate-docs:
$(call print_title,"Generating Swagger API documentation")
@if ! command -v swag >/dev/null 2>&1; then \
echo "Installing swag..."; \
go install github.com/swaggo/swag/cmd/swag@latest; \
fi
@swag init -g ./components/manager/cmd/app/main.go -d ./ -o ./components/manager/api --parseDependency --parseInternal
@docker run --rm -v $(ROOT_DIR):/local --user $(shell id -u):$(shell id -g) openapitools/openapi-generator-cli:v5.1.1 generate -i /local/components/manager/api/swagger.json -g openapi-yaml -o /local/components/manager/api
@mv ./components/manager/api/openapi/openapi.yaml ./components/manager/api/openapi.yaml
@rm -rf ./components/manager/api/README.md ./components/manager/api/.openapi-generator* ./components/manager/api/openapi
@if [ -f "$(ROOT_DIR)/scripts/package.json" ]; then \
echo "Installing npm dependencies for validation..."; \
cd $(ROOT_DIR)/scripts && npm install > /dev/null; \
fi
@echo "[ok] Swagger API documentation generated successfully ✔️"
.PHONY: validate-api-docs
validate-api-docs: generate-docs
$(call print_title,"Validating API documentation")
@if [ -f "scripts/validate-api-docs.js" ] && [ -f "$(ROOT_DIR)/scripts/package.json" ]; then \
echo "Validating API documentation structure..."; \
cd $(ROOT_DIR)/scripts && node $(ROOT_DIR)/scripts/validate-api-docs.js; \
echo "Validating API implementations..."; \
cd $(ROOT_DIR)/scripts && node $(ROOT_DIR)/scripts/validate-api-implementations.js; \
echo "[ok] API documentation validation completed ✔️"; \
else \
echo "Validation scripts not found. Skipping validation."; \
fi
#-------------------------------------------------------
# Code Generation Commands
#-------------------------------------------------------
.PHONY: generate
generate:
$(call print_title,"Running code generation")
@go generate ./...
@echo "[ok] Code generation completed ✔️"
.PHONY: generate-mocks
generate-mocks:
$(call print_title,"Generating mock files")
@go generate ./...
@echo "[ok] Mock generation completed ✔️"
#-------------------------------------------------------
# Developer Helper Commands
#-------------------------------------------------------
.PHONY: check-tools
check-tools:
$(call print_title,"Checking required tools")
@err=0; \
for tool in go docker golangci-lint swag mockgen gosec govulncheck gofumpt goimports; do \
if command -v $$tool >/dev/null 2>&1; then \
echo "[ok] $$tool is installed"; \
else \
echo "[missing] $$tool is NOT installed"; \
err=1; \
fi; \
done; \
if [ $$err -eq 1 ]; then \
echo ""; \
echo "Run 'make dev-setup' to install missing tools"; \
exit 1; \
fi; \
echo "[ok] All tools available ✔️"
.PHONY: dev-setup
dev-setup:
$(call print_title,"Setting up development environment")
@echo "Installing development tools..."
@if ! command -v golangci-lint >/dev/null 2>&1; then \
echo "Installing golangci-lint..."; \
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION); \
fi
@if ! command -v swag >/dev/null 2>&1; then \
echo "Installing swag..."; \
go install github.com/swaggo/swag/cmd/swag@latest; \
fi
@if ! command -v mockgen >/dev/null 2>&1; then \
echo "Installing mockgen..."; \
go install go.uber.org/mock/mockgen@v0.6.0; \
fi
@if ! command -v gosec >/dev/null 2>&1; then \
echo "Installing gosec..."; \
go install github.com/securego/gosec/v2/cmd/gosec@latest; \
fi
@if ! command -v govulncheck >/dev/null 2>&1; then \
echo "Installing govulncheck..."; \
go install golang.org/x/vuln/cmd/govulncheck@latest; \
fi
@if ! command -v gofumpt >/dev/null 2>&1; then \
echo "Installing gofumpt..."; \
go install mvdan.cc/gofumpt@latest; \
fi
@if ! command -v goimports >/dev/null 2>&1; then \
echo "Installing goimports..."; \
go install golang.org/x/tools/cmd/goimports@latest; \
fi
@echo "Setting up environment..."
@if [ -f .env.example ] && [ ! -f .env ]; then \
cp .env.example .env; \
echo "Created .env file from template"; \
fi
@make tidy
@make check-tests
@make sec
@echo "[ok] Development environment set up successfully ✔️"
@echo "You're ready to start developing! Here are some useful commands:"
@echo " make build - Build the component"
@echo " make test - Run tests"
@echo " make up - Start services"
@echo " make rebuild-up - Rebuild and restart services during development"