-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
229 lines (206 loc) · 9.49 KB
/
Makefile
File metadata and controls
229 lines (206 loc) · 9.49 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
# Tracer Makefile
# Component-specific variables
SERVICE_NAME := tracer
GOLANGCI_LINT_VERSION := v2.10.1
BIN_DIR := ./.bin
ARTIFACTS_DIR := ./artifacts
POSTGRES_SERVICE ?= tracer-postgres
# Ensure artifacts directory exists
$(shell mkdir -p $(ARTIFACTS_DIR))
# Test reports directory (used by mk/tests.mk)
TEST_REPORTS_DIR ?= ./reports
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 \
)
# Include shared color definitions and utility functions
include pkg/shell/makefile_colors.mk
include pkg/shell/makefile_utils.mk
# Include modular makefiles
include mk/database.mk
include mk/docker.mk
include mk/docs.mk
include mk/quality.mk
include mk/security.mk
include mk/tests.mk
#-------------------------------------------------------
# Core Commands
#-------------------------------------------------------
.PHONY: help
help:
@echo ""
@echo "$(BOLD)Plugin Service Commands$(NC)"
@echo ""
@echo "$(BOLD)Core Commands:$(NC)"
@echo " make help - Display this help message"
@echo " make build - Build the binary to .bin/tracer"
@echo " make test - Run all tests"
@echo " make clean - Clean build artifacts"
@echo " make run - Run the application with .env config"
@echo ""
@echo "$(BOLD)Test Suite Aliases:$(NC)"
@echo " make test-unit - Run Go unit tests"
@echo " make test-integration - Run integration tests with testcontainers (RUN=<test>)"
@echo " make test-e2e - Run E2E BDD tests (resets DB, runs Godog scenarios)"
@echo " make test-all - Run all tests (unit + integration)"
@echo " make test-bench - Run benchmark tests (BENCH=pattern, BENCH_PKG=./path)"
@echo ""
@echo "$(BOLD)Coverage Commands:$(NC)"
@echo " make coverage-unit - Run unit tests with coverage report (PKG=./path, uses .ignorecoverunit)"
@echo " make coverage-integration - Run integration tests with coverage report (PKG=./path)"
@echo " make coverage - Run all coverage targets (unit + integration)"
@echo ""
@echo "$(BOLD)Code Quality Commands:$(NC)"
@echo " make lint - Run linting tools"
@echo " make format - Format code with go fmt"
@echo " make generate - Generate code (mocks, etc.)"
@echo " make tidy - Clean unused dependencies (go mod tidy)"
@echo " make update-deps - Update all deps to latest versions"
@echo " make sec - Run security checks (gosec + govulncheck)"
@echo " make sec SARIF=1 - Run security checks with SARIF output"
@echo ""
@echo "$(BOLD)Docker Commands:$(NC)"
@echo " make up - Start services with Docker Compose"
@echo " make down - Stop services with Docker Compose"
@echo " make start - Start existing containers"
@echo " make stop - Stop running containers"
@echo " make restart - Restart all containers"
@echo " make logs - Show logs for all services"
@echo " make logs-api - Show logs for plugin service"
@echo " make ps - List container status"
@echo " make rebuild-up - Rebuild and restart services during development"
@echo ""
@echo "$(BOLD)Database Commands:$(NC)"
@echo " make migrate - Apply all pending migrations"
@echo " make migrate-down - Rollback last migration"
@echo " make migrate-down-all - Rollback all migrations (5s confirmation, FORCE=1 to skip)"
@echo " make migrate-version - Show current migration version"
@echo " make migrate-force VERSION=N - Force set migration version (use with caution)"
@echo " make seed - Load development seed data"
@echo " make seed-down - Remove development seed data"
@echo ""
@echo "$(BOLD)Tracer-Specific Commands:$(NC)"
@echo " make generate-docs - Generate Swagger API documentation"
@echo " make verify-api-docs - Verify API documentation coverage"
@echo " make validate-api-docs - Validate API documentation"
@echo ""
@echo "$(BOLD)Test Tooling:$(NC)"
@echo " make tools - Install test tools (gotestsum)"
@echo " make wait-for-services - Wait for backend services to be healthy"
@echo ""
@echo "$(BOLD)Test Parameters (env vars for test-* targets):$(NC)"
@echo " TEST_TRACER_URL - default: http://localhost:8080"
@echo " TEST_HEALTH_WAIT - default: 60"
@echo " LOW_RESOURCE - 0|1 (default: 0) - reduces parallelism for CI"
@echo " RETRY_ON_FAIL - 0|1 (default: 0)"
@echo " E2E_SERVER - default: http://localhost:8080 (E2E target URL)"
@echo " E2E_API_KEY - default: dev_api_key_32chars_change_in_prod"
@echo " E2E_SKIP_RESET - 0|1 (default: 0) - skip Docker volume reset"
@echo ""
@echo "$(BOLD)Developer Helper Commands:$(NC)"
@echo " make dev-setup - Set up development environment"
@echo ""
#-------------------------------------------------------
# Git Hook Commands
#-------------------------------------------------------
.PHONY: setup-git-hooks
setup-git-hooks:
$(call title1,"Installing and configuring git hooks")
@sh ./scripts/setup-git-hooks.sh
@echo "$(GREEN)$(BOLD)[ok]$(NC) Git hooks installed successfully$(GREEN) ✔️$(NC)"
.PHONY: check-hooks
check-hooks:
$(call title1,"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 "$(RED)Git hook $$hook_name is not installed$(NC)"; \
err=1; \
else \
echo "$(GREEN)Git hook $$hook_name is installed$(NC)"; \
fi; \
done; \
if [ $$err -eq 0 ]; then \
echo "$(GREEN)$(BOLD)[ok]$(NC) All git hooks are properly installed$(GREEN) ✔️$(NC)"; \
else \
echo "$(RED)$(BOLD)[error]$(NC) Some git hooks are missing. Run 'make setup-git-hooks' to fix.$(RED) ❌$(NC)"; \
exit 1; \
fi
.PHONY: check-envs
check-envs:
$(call title1,"Checking if github hooks are installed and secret env files are not exposed")
@sh ./scripts/check-envs.sh
@echo "$(GREEN)$(BOLD)[ok]$(NC) Environment check completed$(GREEN) ✔️$(NC)"
#-------------------------------------------------------
# Setup Commands
#-------------------------------------------------------
.PHONY: set-env
set-env:
$(call title1,"Setting up environment files")
@if [ -f ".env.example" ] && [ ! -f ".env" ]; then \
echo "$(CYAN)Creating .env in plugin from .env.example$(NC)"; \
cp ".env.example" ".env"; \
elif [ ! -f ".env.example" ]; then \
echo "$(YELLOW)Warning: No .env.example found in plugin$(NC)"; \
else \
echo "$(GREEN).env already exists in plugin$(NC)"; \
fi
@echo "$(GREEN)$(BOLD)[ok]$(NC) Environment files set up successfully$(GREEN) ✔️$(NC)"
#-------------------------------------------------------
# Build Commands
#-------------------------------------------------------
.PHONY: build
build:
$(call title1,"Building component")
@mkdir -p $(BIN_DIR)
@CGO_ENABLED=0 go build -ldflags="-s -w" -o $(BIN_DIR)/$(SERVICE_NAME) ./cmd/app
@echo "$(GREEN)$(BOLD)[ok]$(NC) Build completed successfully - binary at $(BIN_DIR)/$(SERVICE_NAME)$(GREEN) ✔️$(NC)"
#-------------------------------------------------------
# Clean Commands
#-------------------------------------------------------
.PHONY: clean
clean:
$(call title1,"Cleaning build artifacts")
@rm -rf $(BIN_DIR)/* $(ARTIFACTS_DIR)/*
@echo "$(GREEN)$(BOLD)[ok]$(NC) Artifacts cleaned successfully$(GREEN) ✔️$(NC)"
#-------------------------------------------------------
# Developer Helper Commands
#-------------------------------------------------------
.PHONY: dev-setup
dev-setup:
$(call title1,"Setting up development environment")
@echo "$(CYAN)Installing development tools...$(NC)"
@if ! command -v golangci-lint >/dev/null 2>&1; then \
echo "$(YELLOW)Installing golangci-lint v2...$(NC)"; \
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 "$(YELLOW)Installing swag...$(NC)"; \
go install github.com/swaggo/swag/cmd/swag@latest; \
fi
@if ! command -v mockgen >/dev/null 2>&1; then \
echo "$(YELLOW)Installing mockgen...$(NC)"; \
go install go.uber.org/mock/mockgen@v0.5.2; \
fi
@if ! command -v gosec >/dev/null 2>&1; then \
echo "$(YELLOW)Installing gosec...$(NC)"; \
go install github.com/securego/gosec/v2/cmd/gosec@latest; \
fi
@echo "$(CYAN)Setting up environment...$(NC)"
@if [ -f .env.example ] && [ ! -f .env ]; then \
cp .env.example .env; \
echo "$(GREEN)Created .env file from template$(NC)"; \
fi
@make tidy
@make check-tests
@make sec
@echo "$(GREEN)$(BOLD)[ok]$(NC) Development environment set up successfully$(GREEN) ✔️$(NC)"
@echo "$(CYAN)You're ready to start developing! Here are some useful commands:$(NC)"
@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"