-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
272 lines (222 loc) · 9.44 KB
/
Makefile
File metadata and controls
272 lines (222 loc) · 9.44 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
# ============================================================================
# Synapse: Doc-First Event Processing
# ============================================================================
# A masterful Makefile for spec-driven development
#
# Usage:
# make help Show all available targets
# make setup One-time setup for new clones
# make generate Regenerate code from specs
# make test Run all tests
# make run Start the server
# ============================================================================
.PHONY: help setup generate build test test-short test-conformance test-pipeline \
run clean lint fmt vet validate-specs diagrams docker-up docker-down \
deps tidy coverage benchmark
# Colors for pretty output
CYAN := \033[36m
GREEN := \033[32m
YELLOW := \033[33m
RED := \033[31m
RESET := \033[0m
BOLD := \033[1m
# ============================================================================
# HELP
# ============================================================================
help: ## Show this help message
@echo ""
@echo "$(BOLD)Synapse: Doc-First Event Processing$(RESET)"
@echo "======================================"
@echo ""
@echo "$(CYAN)Quick Start:$(RESET)"
@echo " make setup → First-time setup (deps + generate)"
@echo " make test → Run all tests"
@echo " make run → Start the server"
@echo ""
@echo "$(CYAN)Available targets:$(RESET)"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
awk 'BEGIN {FS = ":.*?## "}; {printf " $(GREEN)%-18s$(RESET) %s\n", $$1, $$2}'
@echo ""
# ============================================================================
# SETUP & DEPENDENCIES
# ============================================================================
setup: deps generate ## One-time setup for new clones
@echo "$(GREEN)✓ Setup complete!$(RESET)"
@echo ""
@echo "Next steps:"
@echo " make test → Run tests"
@echo " make run → Start server"
deps: ## Download Go dependencies
@echo "$(CYAN)→ Downloading dependencies...$(RESET)"
@go mod download
@go mod tidy
@echo "$(GREEN)✓ Dependencies ready$(RESET)"
tidy: ## Tidy go.mod and go.sum
@go mod tidy
# ============================================================================
# CODE GENERATION
# ============================================================================
generate: ## Regenerate code from OpenAPI & AsyncAPI specs
@echo "$(CYAN)→ Generating code from specs...$(RESET)"
@go run ./cmd/synctl
@$(MAKE) fmt-generated
@echo "$(GREEN)✓ Code generated$(RESET)"
fmt-generated: ## Format generated code
@gofmt -w ./internal/generated/
# ============================================================================
# BUILD
# ============================================================================
build: ## Build the synapse binary
@echo "$(CYAN)→ Building synapse...$(RESET)"
@go build -o bin/synapse ./cmd/synapse
@echo "$(GREEN)✓ Built: bin/synapse$(RESET)"
build-synctl: ## Build the code generator
@echo "$(CYAN)→ Building synctl...$(RESET)"
@go build -o bin/synctl ./cmd/synctl
@echo "$(GREEN)✓ Built: bin/synctl$(RESET)"
build-all: build build-synctl ## Build all binaries
# ============================================================================
# TESTING
# ============================================================================
test: ## Run all tests (requires Docker)
@echo "$(CYAN)→ Running all tests...$(RESET)"
@go test ./... -v -count=1
@echo "$(GREEN)✓ All tests passed$(RESET)"
test-short: ## Run fast tests only (no Docker)
@echo "$(CYAN)→ Running short tests...$(RESET)"
@go test ./... -short -v
@echo "$(GREEN)✓ Short tests passed$(RESET)"
test-conformance: ## Run conformance tests only
@echo "$(CYAN)→ Running conformance tests...$(RESET)"
@go test ./internal/conformance/... -v -count=1
@echo "$(GREEN)✓ Conformance tests passed$(RESET)"
test-pipeline: ## Run pipeline integration tests
@echo "$(CYAN)→ Running pipeline tests...$(RESET)"
@go test ./internal/pipeline/... -v -count=1
@echo "$(GREEN)✓ Pipeline tests passed$(RESET)"
coverage: ## Run tests with coverage report
@echo "$(CYAN)→ Running tests with coverage...$(RESET)"
@go test ./... -coverprofile=coverage.out -covermode=atomic
@go tool cover -html=coverage.out -o coverage.html
@echo "$(GREEN)✓ Coverage report: coverage.html$(RESET)"
benchmark: ## Run benchmarks
@echo "$(CYAN)→ Running benchmarks...$(RESET)"
@go test ./... -bench=. -benchmem
# ============================================================================
# CODE QUALITY
# ============================================================================
lint: fmt vet ## Run all linters (fmt + vet)
@echo "$(GREEN)✓ Lint complete$(RESET)"
fmt: ## Format all Go code
@echo "$(CYAN)→ Formatting code...$(RESET)"
@gofmt -w .
vet: ## Run go vet
@echo "$(CYAN)→ Running go vet...$(RESET)"
@go vet ./...
check: lint test-short ## Quick check (lint + short tests)
@echo "$(GREEN)✓ Quick check passed$(RESET)"
# ============================================================================
# SPECIFICATION VALIDATION
# ============================================================================
validate-specs: validate-openapi validate-asyncapi ## Validate all specs
validate-openapi: ## Validate OpenAPI specification
@echo "$(CYAN)→ Validating OpenAPI spec...$(RESET)"
@if command -v vacuum > /dev/null; then \
vacuum lint openapi/openapi.yaml; \
else \
echo "$(YELLOW)⚠ vacuum not installed, skipping OpenAPI validation$(RESET)"; \
echo " Install: go install github.com/daveshanley/vacuum@latest"; \
fi
validate-asyncapi: ## Validate AsyncAPI specification
@echo "$(CYAN)→ Validating AsyncAPI spec...$(RESET)"
@if command -v asyncapi > /dev/null; then \
asyncapi validate asyncapi/asyncapi.yaml; \
else \
echo "$(YELLOW)⚠ asyncapi CLI not installed, skipping AsyncAPI validation$(RESET)"; \
echo " Install: npm install -g @asyncapi/cli"; \
fi
# ============================================================================
# RUN
# ============================================================================
run: ## Run the synapse server
@echo "$(CYAN)→ Starting Synapse server...$(RESET)"
@go run ./cmd/synapse
run-dev: ## Run with hot reload (requires air)
@if command -v air > /dev/null; then \
air; \
else \
echo "$(YELLOW)⚠ air not installed$(RESET)"; \
echo " Install: go install github.com/cosmtrek/air@latest"; \
$(MAKE) run; \
fi
# ============================================================================
# DIAGRAMS
# ============================================================================
diagrams: ## Generate architecture diagrams
@echo "$(CYAN)→ Generating diagrams...$(RESET)"
@cd scripts && \
if [ ! -d "venv" ]; then \
python3 -m venv venv && \
./venv/bin/pip install -q diagrams; \
fi && \
./venv/bin/python generate_all.py
@echo "$(GREEN)✓ Diagrams generated in scripts/output/$(RESET)"
# ============================================================================
# DOCKER (for local infrastructure)
# ============================================================================
docker-up: ## Start local infrastructure (NATS, Postgres, Redis)
@echo "$(CYAN)→ Starting infrastructure...$(RESET)"
@docker compose up -d
@echo "$(GREEN)✓ Infrastructure running$(RESET)"
@echo " NATS: nats://localhost:4222"
@echo " Postgres: postgres://localhost:5432"
@echo " Redis: redis://localhost:6379"
docker-down: ## Stop local infrastructure
@echo "$(CYAN)→ Stopping infrastructure...$(RESET)"
@docker compose down
@echo "$(GREEN)✓ Infrastructure stopped$(RESET)"
docker-logs: ## Show infrastructure logs
@docker compose logs -f
# ============================================================================
# CLEANUP
# ============================================================================
clean: ## Clean build artifacts
@echo "$(CYAN)→ Cleaning...$(RESET)"
@rm -rf bin/
@rm -f coverage.out coverage.html
@rm -rf scripts/venv/
@echo "$(GREEN)✓ Clean$(RESET)"
clean-generated: ## Remove generated code (use with caution)
@echo "$(YELLOW)→ Removing generated code...$(RESET)"
@rm -f internal/generated/*.gen.go
@echo "$(GREEN)✓ Generated code removed$(RESET)"
# ============================================================================
# WORKFLOW SHORTCUTS
# ============================================================================
all: setup test build ## Full build pipeline
@echo "$(GREEN)✓ All done!$(RESET)"
dev: generate test-short run ## Development cycle: generate → test → run
ci: deps generate lint test ## CI pipeline
@echo "$(GREEN)✓ CI passed$(RESET)"
# ============================================================================
# INFO
# ============================================================================
info: ## Show project information
@echo ""
@echo "$(BOLD)Synapse: Doc-First Event Processing$(RESET)"
@echo "======================================"
@echo ""
@echo "$(CYAN)Specs:$(RESET)"
@echo " OpenAPI: openapi/openapi.yaml"
@echo " AsyncAPI: asyncapi/asyncapi.yaml"
@echo ""
@echo "$(CYAN)Generated Code:$(RESET)"
@ls -la internal/generated/*.gen.go 2>/dev/null || echo " (not yet generated - run 'make generate')"
@echo ""
@echo "$(CYAN)Workflow:$(RESET)"
@echo " 1. Edit specs (openapi/ or asyncapi/)"
@echo " 2. make generate"
@echo " 3. Implement handlers"
@echo " 4. make test-conformance"
@echo ""
.DEFAULT_GOAL := help