-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
291 lines (252 loc) · 10.5 KB
/
Makefile
File metadata and controls
291 lines (252 loc) · 10.5 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
# =============================================================================
# Makefile - Enterprise API Contracts
# =============================================================================
# This Makefile provides commands for managing the API contracts repository:
# - Code generation for multiple languages
# - Linting and validation
# - Building and testing clients
# - Documentation generation
#
# Rust is the PRIMARY language for this project.
# =============================================================================
.PHONY: help setup install clean generate lint format test build check breaking deps update-deps validate add-service
.DEFAULT_GOAL := help
# =============================================================================
# Help
# =============================================================================
help: ## Show this help message
@echo "Enterprise API Contracts - Available Commands"
@echo ""
@echo "🚀 Setup:"
@echo " make setup - Initialize development environment"
@echo " make install - Install all dependencies (buf, rust, go, python, node)"
@echo " make deps - Download proto dependencies"
@echo " make update-deps - Update proto dependencies"
@echo " make add-service - Interactive tool to add a new service package"
@echo " make sync-workspaces - Sync workspace configs with discovered modules"
@echo ""
@echo "🔨 Generation:"
@echo " make generate - Generate all clients (rust, python, typescript)"
@echo " make generate-rust - Generate Rust client only (PRIMARY)"
@echo " make generate-python - Generate Python client only"
@echo " make generate-ts - Generate TypeScript client only"
@echo " make generate-docs - Generate documentation only"
@echo ""
@echo "✅ Quality:"
@echo " make lint - Lint proto files"
@echo " make format - Format proto files"
@echo " make validate - Run all validation checks"
@echo " make breaking - Check for breaking changes"
@echo " make check - Run lint + breaking"
@echo ""
@echo "🏗️ Build:"
@echo " make build - Build all clients"
@echo " make build-rust - Build Rust client (PRIMARY)"
@echo " make build-python - Build Python client"
@echo " make build-ts - Build TypeScript client"
@echo ""
@echo "🧪 Test:"
@echo " make test - Run all tests"
@echo " make test-rust - Test Rust client"
@echo " make test-python - Test Python client"
@echo " make test-ts - Test TypeScript client"
@echo ""
@echo "🧹 Maintenance:"
@echo " make clean - Clean generated files"
@echo " make clean-all - Clean everything (including dependencies)"
@echo ""
# =============================================================================
# Setup & Installation
# =============================================================================
setup: ## Initialize development environment
@echo "🚀 Setting up development environment..."
@chmod +x scripts/*.sh
@if [ -f scripts/setup.sh ]; then \
./scripts/setup.sh; \
else \
echo "⚠️ Setup script not found"; \
exit 1; \
fi
install: ## Install all required dependencies
@echo "📦 Installing dependencies..."
@echo ""
@echo "Checking for buf..."
@command -v buf >/dev/null 2>&1 || \
(echo "❌ buf not found. Installing..." && \
curl -sSL "https://github.com/bufbuild/buf/releases/latest/download/buf-$$(uname -s)-$$(uname -m)" \
-o /tmp/buf && sudo mv /tmp/buf /usr/local/bin/buf && sudo chmod +x /usr/local/bin/buf)
@echo "✅ buf installed: $$(buf --version)"
@echo ""
@echo "Checking for Rust..."
@command -v cargo >/dev/null 2>&1 || \
(echo "❌ Rust not found. Install from https://rustup.rs" && exit 1)
@echo "✅ Rust installed: $$(rustc --version)"
@echo ""
@echo "✅ All core dependencies installed!"
deps: ## Download proto dependencies
@echo "📥 Downloading proto dependencies..."
@buf dep update proto
update-deps: ## Update proto dependencies
@echo "🔄 Updating proto dependencies..."
@buf dep update proto
add-service: ## Interactive tool to add a new service package
@if [ -f scripts/add_service.sh ]; then \
./scripts/add_service.sh; \
else \
echo "⚠️ add_service.sh script not found"; \
exit 1; \
fi
sync-workspaces: ## Synchronize workspace configurations with discovered modules
@echo "🔄 Synchronizing workspace configurations..."
@if [ -f scripts/sync_workspaces.sh ]; then \
./scripts/sync_workspaces.sh; \
else \
echo "⚠️ sync_workspaces.sh script not found"; \
exit 1; \
fi
# =============================================================================
# Code Generation
# =============================================================================
generate: ## Generate all clients
@echo "🔨 Generating all clients..."
@if [ -z "$$(find proto -name '*.proto' 2>/dev/null | grep -v '.gitkeep')" ]; then \
echo "⚠️ No proto files found. Add proto files to proto/ directory first."; \
echo " Example: Create proto/core/v1/tenant.proto"; \
else \
if [ -f scripts/generate_clients.sh ]; then \
./scripts/generate_clients.sh; \
else \
buf generate && echo "✅ All clients generated successfully!"; \
fi \
fi
generate-rust: ## Generate Rust client only (PRIMARY)
@echo "🦀 Generating Rust client..."
@if [ -f scripts/generate_rust.sh ]; then \
./scripts/generate_rust.sh; \
else \
buf generate; \
fi
generate-python: ## Generate Python client only
@echo "🐍 Generating Python client..."
@if [ -f scripts/generate_python.sh ]; then \
./scripts/generate_python.sh; \
else \
buf generate; \
fi
generate-ts: ## Generate TypeScript client only
@echo "📘 Generating TypeScript client..."
@if [ -f scripts/generate_ts.sh ]; then \
./scripts/generate_ts.sh; \
else \
buf generate; \
fi
generate-docs: ## Generate documentation only
@echo "📚 Generating documentation..."
@buf generate --include-imports
# =============================================================================
# Quality Checks
# =============================================================================
lint: ## Lint proto files
@echo "🔍 Linting proto files..."
@if [ -z "$$(find proto -name '*.proto' 2>/dev/null | grep -v '.gitkeep')" ]; then \
echo "⚠️ No proto files to lint"; \
else \
buf lint proto && echo "✅ Lint passed!"; \
fi
format: ## Format proto files
@echo "🎨 Formatting proto files..."
@if [ -z "$$(find proto -name '*.proto' 2>/dev/null | grep -v '.gitkeep')" ]; then \
echo "⚠️ No proto files to format"; \
else \
buf format -w proto && echo "✅ Files formatted!"; \
fi
breaking: ## Check for breaking changes against main branch
@echo "🔍 Checking for breaking changes..."
@if [ -z "$$(find proto -name '*.proto' 2>/dev/null | grep -v '.gitkeep')" ]; then \
echo "⚠️ No proto files to check"; \
else \
buf breaking proto --against '.git#branch=main,subdir=proto' || \
(echo "⚠️ Breaking changes detected or no baseline found" && exit 0); \
fi
validate: lint breaking validate-structure ## Run all validation checks
validate-structure: ## Validate client structure matches proto structure
@echo "🔍 Validating client structure..."
@if [ -f scripts/validate_structure.sh ]; then \
./scripts/validate_structure.sh; \
else \
echo "⚠️ Validation script not found"; \
fi
check: validate ## Alias for validate
# =============================================================================
# Build
# =============================================================================
build: generate build-rust ## Build all clients (Rust is primary)
build-rust: ## Build Rust client (PRIMARY)
@echo "🦀 Building Rust client..."
@if [ -f "clients/rust/Cargo.toml" ]; then \
cd clients/rust && cargo build --release && echo "✅ Rust build complete!"; \
else \
echo "⚠️ Rust client not found. Run 'make setup' first."; \
fi
build-python: ## Build Python distribution packages (.whl files)
@echo "🐍 Building Python distribution packages..."
@if [ -f "scripts/build_python.py" ]; then \
python3 scripts/build_python.py; \
else \
echo "⚠️ Build script not found."; \
exit 1; \
fi
dist-python: build-python ## Alias for build-python
build-ts: ## Build TypeScript client
@echo "📘 Building TypeScript client..."
@if [ -f "clients/typescript/package.json" ]; then \
cd clients/typescript && npm install && npm run build && echo "✅ TypeScript build complete!"; \
else \
echo "⚠️ TypeScript client not found. Run 'make setup' first."; \
fi
# =============================================================================
# Test
# =============================================================================
test: test-rust ## Run tests (Rust is primary)
test-rust: ## Test Rust client (PRIMARY)
@echo "🦀 Testing Rust client..."
@if [ -f "clients/rust/Cargo.toml" ]; then \
cd clients/rust && cargo test && echo "✅ Rust tests passed!"; \
else \
echo "⚠️ Rust client not found."; \
fi
test-python: ## Test Python client
@echo "🐍 Testing Python client..."
@if [ -f "clients/python/pyproject.toml" ]; then \
cd clients/python && python3 -m pytest && echo "✅ Python tests passed!"; \
else \
echo "⚠️ Python client not found."; \
fi
test-ts: ## Test TypeScript client
@echo "📘 Testing TypeScript client..."
@if [ -f "clients/typescript/package.json" ]; then \
cd clients/typescript && npm test && echo "✅ TypeScript tests passed!"; \
else \
echo "⚠️ TypeScript client not found."; \
fi
# =============================================================================
# Clean
# =============================================================================
clean: ## Clean generated files
@echo "🧹 Cleaning generated files..."
@rm -rf clients/rust/proto clients/rust/target
@rm -rf clients/python/proto clients/python/dist clients/python/build clients/python/*.egg-info
@rm -rf clients/typescript/proto clients/typescript/dist clients/typescript/node_modules
@rm -rf docs/api/*.md docs/api/*.html docs/openapi/
@echo "✅ Clean complete!"
clean-all: clean ## Clean everything including dependencies
@echo "🧹 Deep cleaning..."
@rm -rf clients/rust/Cargo.lock
@rm -rf clients/typescript/package-lock.json
@rm -rf clients/go/go.sum
@echo "✅ Deep clean complete!"
# =============================================================================
# CI/CD
# =============================================================================
ci: deps lint breaking generate build test ## Run full CI pipeline
@echo "✅ CI pipeline complete!"