-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
310 lines (261 loc) · 11.2 KB
/
Copy pathMakefile
File metadata and controls
310 lines (261 loc) · 11.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
BINDIR := bin
VERSION := $(shell cat VERSION 2>/dev/null || echo "0.1.0")
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
GIT_DIRTY := $(shell git diff --quiet || echo "-dirty")
BUILD_TIME := $(shell date -u '+%Y-%m-%d_%H:%M:%S')
FULL_VERSION := $(VERSION)$(GIT_DIRTY)
LDFLAGS := -X main.version=$(FULL_VERSION) -X main.buildTime=$(BUILD_TIME) -X main.gitCommit=$(GIT_COMMIT) -s -w
.PHONY: proto sync-proto api build server agent cli clean dev tidy test lint help all tools schema-validator
.PHONY: test test-coverage test-coverage-html test-race test-integration test-all
.PHONY: build-sdks build-sdks-cpp build-sdks-go build-sdks-java build-sdks-js build-sdks-python
.PHONY: build-web build-dashboard build-website dev-dashboard dev-website
.PHONY: version version-sync
.PHONY: clone-sdks clone-dashboard clone-all
# Build all components (server + sdks + web)
all: build build-sdks build-web
# ========== Clone External Dependencies ==========
# Clone SDK repositories (used instead of git submodules)
SDK_REPOS := croupier-sdk-cpp croupier-sdk-go croupier-sdk-java croupier-sdk-js croupier-sdk-python croupier-sdk-csharp
SDK_BASE_URL := git@github.com:cuihairu
clone-sdks:
@echo "[clone] cloning SDK repositories..."
@for repo in $(SDK_REPOS); do \
if [ ! -d "sdks/$$repo" ]; then \
echo "[clone] $$repo"; \
git clone --depth 1 $(SDK_BASE_URL)/$$repo.git sdks/$$repo; \
else \
echo "[skip] $$repo already exists"; \
fi \
done
# Clone dashboard repository
clone-dashboard:
@echo "[clone] cloning dashboard..."
@if [ ! -d "dashboard" ]; then \
echo "[clone] croupier-dashboard"; \
git clone --depth 1 $(SDK_BASE_URL)/croupier-dashboard.git dashboard; \
else \
echo "[skip] dashboard already exists"; \
fi
# Clone all external dependencies
clone-all: clone-sdks clone-dashboard
@echo "[done] all dependencies cloned"
# Sync proto files from remote
sync-proto:
@echo "[sync] updating proto/ from latest..."
@cd proto && git fetch origin && \
if git rev-parse --abbrev-ref HEAD > /dev/null 2>&1; then \
git pull origin $$(git rev-parse --abbrev-ref HEAD); \
else \
git checkout main && git pull origin main; \
fi
@echo "[sync] proto files updated"
# Ensure local protoc plugin exists before running buf
proto: croupier-plugin
@echo "[proto] generating code via buf..."
buf generate proto --template buf.gen.yaml --clean
# Generate API code from .api files (DEPRECATED - go-zero removed)
api:
@echo "[deprecated] API generation via goctl is no longer supported. Use hand-written handlers in internal/api/"
# Build local protoc plugin
.PHONY: croupier-plugin
croupier-plugin:
@echo "[build] protoc-gen-croupier"
@mkdir -p $(BINDIR)
GOFLAGS=-mod=mod go build -o $(BINDIR)/protoc-gen-croupier ./tools/protoc-gen-croupier
server:
@echo "[build] server (all database drivers)"
@mkdir -p $(BINDIR)
GOFLAGS=-mod=mod go build -ldflags "-X github.com/cuihairu/croupier/cmd/server.Version=$(FULL_VERSION) -X github.com/cuihairu/croupier/cmd/server.GitCommit=$(GIT_COMMIT) -X github.com/cuihairu/croupier/cmd/server.BuildTime=$(BUILD_TIME) -X github.com/cuihairu/croupier/internal/svc.ServerVersion=$(FULL_VERSION) -X github.com/cuihairu/croupier/internal/svc.ServerGitCommit=$(GIT_COMMIT) -X github.com/cuihairu/croupier/internal/svc.ServerBuildTime=$(BUILD_TIME) -s -w" -o $(BINDIR)/croupier-server ./cmd/server
.PHONY: server-sqlite
server-sqlite:
@echo "[deprecated] server-sqlite: all database drivers are now included; building regular server"
$(MAKE) server
.PHONY: server-ip2loc
server-ip2loc:
@echo "[deprecated] server-ip2loc: ip2location is runtime-enabled now; building regular server"
$(MAKE) server
.PHONY: server-sqlite-ip2loc
server-sqlite-ip2loc:
@echo "[deprecated] server-sqlite-ip2loc: ip2location is runtime-enabled; building regular sqlite server"
$(MAKE) server-sqlite
agent:
@echo "[build] agent"
@mkdir -p $(BINDIR)
GOFLAGS=-mod=mod go build -ldflags "$(LDFLAGS)" -o $(BINDIR)/croupier-agent ./cmd/agent
build: server agent worker ingest tools
.PHONY: build-ip2loc
build-ip2loc:
@echo "[deprecated] build-ip2loc: ip2location is runtime-enabled; using default build"
$(MAKE) build
tools: schema-validator
schema-validator:
@echo "[build] schema-validator"
@mkdir -p $(BINDIR)
GOFLAGS=-mod=mod go build -ldflags "$(LDFLAGS)" -o $(BINDIR)/schema-validator ./cmd/schema-validator
.PHONY: worker
worker:
@echo "[build] analytics-worker"
@mkdir -p $(BINDIR)
GOFLAGS=-mod=mod go build -ldflags "$(LDFLAGS)" -o $(BINDIR)/analytics-worker ./cmd/analytics-worker
.PHONY: ingest
ingest:
@echo "[build] ingest"
@mkdir -p $(BINDIR)
GOFLAGS=-mod=mod go build -ldflags "$(LDFLAGS)" -o $(BINDIR)/ingest ./cmd/ingest
.PHONY: analytics-spec
analytics-spec:
@echo "[analytics] exporting analytics spec JSON to dashboard/public/analytics-spec.json"
@GOFLAGS=-mod=mod go run ./cmd/analytics-export --configs configs/analytics --out dashboard/public/analytics-spec.json
# ========== SDK Build Targets ==========
build-sdks: build-sdks-cpp build-sdks-go
build-sdks-cpp:
@echo "[sdks] building C++ SDK..."
@cd sdks/cpp && cmake -B build -DCMAKE_BUILD_TYPE=Release -DENABLE_GRPC=ON
@cd sdks/cpp && cmake --build build --parallel
build-sdks-go:
@echo "[sdks] building Go SDK..."
@cd sdks/go && go mod tidy && go build ./...
build-sdks-java:
@echo "[sdks] building Java SDK..."
@cd sdks/java && ./gradlew build -x test
build-sdks-js:
@echo "[sdks] building JavaScript SDK..."
@cd sdks/js && npm ci && npm run build
build-sdks-python:
@echo "[sdks] building Python SDK..."
@cd sdks/python && pip install -e . && python -m pytest
# ========== Web & Docs Build Targets ==========
build-web: build-dashboard build-docs
build-dashboard: submodules
@echo "[web] building dashboard..."
@cd dashboard && npm ci && npm run build
build-docs:
@echo "[docs] building documentation..."
@cd docs && pnpm install --frozen-lockfile && pnpm run build
# ========== Development Targets ==========
dev-dashboard: submodules
@echo "[web] starting dashboard development server..."
@cd dashboard && npm ci && npm run dev
dev-docs:
@echo "[docs] starting VuePress documentation dev server..."
@cd docs && pnpm install --frozen-lockfile && pnpm run dev
# ========== Clean Targets ==========
clean: clean-sdks clean-web
rm -rf $(BINDIR)
rm -rf gen/
clean-sdks:
@echo "[clean] cleaning SDK build artifacts..."
@rm -rf sdks/cpp/build sdks/java/build sdks/js/dist sdks/js/node_modules
@cd sdks/go && go clean -cache -modcache -testcache || true
@cd sdks/python && rm -rf build/ dist/ *.egg-info/ __pycache__/ || true
clean-web:
@echo "[clean] cleaning web and docs build artifacts..."
@rm -rf dashboard/dist dashboard/node_modules
@rm -rf docs/.vuepress/dist docs/.vuepress/.cache docs/.vuepress/.temp docs/node_modules
# ========== Version Management ==========
.PHONY: version version-sync
version:
@echo "Current SDK Version: $$(cat VERSION 2>/dev/null || echo 'VERSION file not found')"
@echo ""
@echo "SDK Versions:"
@echo " JS: $$(grep '"version"' sdks/js/package.json | head -1 | sed 's/.*: "\(.*\)".*/\1/')"
@echo " Python: $$(grep 'version=' sdks/python/setup.py | sed 's/.*version="\(.*\)".*/\1/')"
@echo " Java: $$(grep '^version' sdks/java/build.gradle | sed "s/.*'\(.*\)'.*/\1/")"
@echo " C++: $$(grep -A1 '^project' sdks/cpp/CMakeLists.txt | grep 'VERSION' | awk '{print $$2}')"
@echo " Go: $$(grep 'const Version' sdks/go/version.go 2>/dev/null | sed 's/.*"\(.*\)".*/\1/' || echo 'N/A')"
version-sync:
@echo "[version] Synchronizing all SDK versions..."
@./scripts/sync-sdk-versions.sh
@echo "[version] Updating JS lock file..."
@cd sdks/js && pnpm install --lockfile-only
@echo "✅ Version sync complete. Don't forget to commit changes!"
# ========== Help Target ==========
help:
@echo "Croupier Build System (Monorepo)"
@echo ""
@echo "Core Targets:"
@echo " all - Build server, SDKs, and web components"
@echo " build - Build server components (server, agent, worker, ingest)"
@echo " sync-proto - Sync proto files from remote"
@echo " proto - Generate protobuf code"
@echo ""
@echo "Server Targets:"
@echo " server - Build croupier-server"
@echo " agent - Build croupier-agent (http+grpc core)"
@echo ""
@echo "SDK Targets:"
@echo " build-sdks - Build all SDKs (C++, Go)"
@echo " build-sdks-cpp - Build C++ SDK"
@echo " build-sdks-go - Build Go SDK"
@echo " build-sdks-java - Build Java SDK"
@echo " build-sdks-js - Build JavaScript SDK"
@echo " build-sdks-python- Build Python SDK"
@echo ""
@echo "Web & Docs Targets:"
@echo " build-web - Build web and docs components"
@echo " build-dashboard - Build management dashboard"
@echo " build-docs - Build VuePress documentation"
@echo " dev-dashboard - Start dashboard dev server"
@echo " dev-docs - Start docs dev server"
@echo ""
@echo "Utility Targets:"
@echo " clean - Clean all build artifacts"
@echo " clean-sdks - Clean SDK build artifacts"
@echo " clean-web - Clean web build artifacts"
@echo ""
@echo "Version Management:"
@echo " version - Show current SDK versions"
@echo " version-sync - Sync all SDK versions from VERSION file"
.PHONY: proto-docs
proto-docs:
@echo "[proto] generating docs..."
buf generate proto --template buf.gen.docs.yaml
# ========== Test Targets ==========
# Run all tests
test:
@echo "[test] running unit tests..."
go test -v -short ./...
# Run tests with race detection
test-race:
@echo "[test] running tests with race detection..."
go test -v -race -short ./...
# Run tests with coverage report
test-coverage:
@echo "[test] running tests with coverage..."
go test -coverprofile=coverage.out -covermode=atomic ./...
@echo ""
@echo "Coverage by package:"
@go tool cover -func=coverage.out | grep -E "^github.com/cuihairu/croupier" | \
awk '{print $$2 " " $$NF}' | sort -t' ' -k2 -n
# Generate HTML coverage report
test-coverage-html: test-coverage
@echo "[test] generating HTML coverage report..."
@go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
# Run integration tests (requires external dependencies)
test-integration:
@echo "[test] running integration tests..."
go test -v -tags=integration ./...
# Run all tests including integration
test-all: test test-integration
@echo "[test] all tests completed"
# Check test coverage against threshold (80%)
test-coverage-check:
@echo "[test] checking coverage threshold (80%)..."
@go test -coverprofile=coverage.out -covermode=atomic ./... > /dev/null 2>&1
@total=$$(go tool cover -func=coverage.out | grep total | awk '{print $$3}' | sed 's/%//'); \
if [ $$(echo "$$total < 80.0" | bc) -eq 1 ]; then \
echo "❌ Coverage $$total% is below 80% threshold"; \
exit 1; \
else \
echo "✅ Coverage $$total% meets 80% threshold"; \
fi
# Run tests for specific package
test-package:
@echo "[test] running tests for package $(PACKAGE)..."
go test -v -coverprofile=$(PACKAGE)_coverage.out -covermode=atomic ./$(PACKAGE)...
# Run tests and generate coverage report for CI/CD
test-ci:
@echo "[test] running CI tests..."
go test -v -race -coverprofile=coverage.out -covermode=atomic -json ./... > test-report.json 2>&1
@go tool cover -func=coverage.out | tail -1