Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
325 lines (255 loc) · 13.6 KB
/
Copy pathMakefile
File metadata and controls
325 lines (255 loc) · 13.6 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
# Copyright 2025 The ThunderID Authors
# SPDX-License-Identifier: Apache-2.0
# Constants
VERSION_FILE=version.txt
VERSION=$(shell cat $(VERSION_FILE))
BINARY_NAME=thunderid
PRODUCT_NAME=ThunderID
export WITHOUT_CONSENT ?= false
# Tools
PROJECT_DIR := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))/backend
PROJECT_BIN_DIR := $(PROJECT_DIR)/bin
TOOL_BIN ?= $(PROJECT_BIN_DIR)/tools
GOLANGCI_LINT ?= $(TOOL_BIN)/golangci-lint
MOCKERY ?= $(TOOL_BIN)/mockery
I18N_EXTRACTOR ?= $(TOOL_BIN)/i18n-extractor
# Tools under tools/. Each is its own Go module with its own Go directive, and `go install`
# compiles a linter with whatever Go is on PATH. golangci-lint refuses to run when the Go it was
# built with is older than the module it is linting, so each tool installs its linter into its own
# bin directory rather than sharing the backend's, where a binary built by the backend's job would
# carry the backend's Go version.
TOOLS_DIR := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))/tools
CLI_DIR := $(TOOLS_DIR)/cli
CLI_TOOL_BIN ?= $(CLI_DIR)/bin/tools
CLI_GOLANGCI_LINT ?= $(CLI_TOOL_BIN)/golangci-lint
I18N_EXTRACTOR_DIR := $(TOOLS_DIR)/i18n-extractor
I18N_EXTRACTOR_TOOL_BIN ?= $(I18N_EXTRACTOR_DIR)/bin/tools
I18N_EXTRACTOR_GOLANGCI_LINT ?= $(I18N_EXTRACTOR_TOOL_BIN)/golangci-lint
CLI_E2E_DIR := $(realpath $(dir $(abspath $(lastword $(MAKEFILE_LIST)))))/tests/e2e-cli
# Tools versions
GOLANGCI_LINT_VERSION ?= v2.14.0
MOCKERY_VERSION ?= v3.8.0
MOCKERY_XTOOLS_VERSION ?= v0.51.0
$(TOOL_BIN):
mkdir -p $(TOOL_BIN)
$(CLI_TOOL_BIN):
mkdir -p $(CLI_TOOL_BIN)
$(I18N_EXTRACTOR_TOOL_BIN):
mkdir -p $(I18N_EXTRACTOR_TOOL_BIN)
all: prepare clean build_with_coverage build
backend: prepare clean build_with_coverage build_backend
prepare:
chmod +x build.sh
clean:
./build.sh clean $(OS) $(ARCH)
build: build_frontend build_backend package_samples
build_backend:
./build.sh build_backend $(OS) $(ARCH)
build_cp_backend:
./build.sh build_cp_backend $(OS) $(ARCH)
build_frontend:
./build.sh build_frontend
build_docs:
./build.sh build_docs
package_samples:
./build.sh package_samples
test:
./build.sh test $(OS) $(ARCH)
test_unit:
./build.sh test_unit $(OS) $(ARCH)
test_integration:
./build.sh test_integration "$(OS)" "$(ARCH)" "$(RUN)" "$(PACKAGE)"
# Runs tests/integration/controlplane against the Control Plane binary (build_cp_backend), swapped
# into the distribution build_backend packages.
test_integration_cp:
INTEGRATION_PLANE=control ./build.sh test_integration "$(OS)" "$(ARCH)" "$(RUN)" "$(PACKAGE)"
build_with_coverage:
@echo "================================================================"
@echo "Building with coverage for unit and integration tests..."
@echo "================================================================"
./build.sh test_unit $(OS) $(ARCH)
ENABLE_COVERAGE=true ./build.sh build_backend $(OS) $(ARCH)
./build.sh build_frontend
./build.sh test_integration $(OS) $(ARCH) "$(RUN)" "$(PACKAGE)"
./build.sh merge_coverage $(OS) $(ARCH)
@echo "================================================================"
build_with_coverage_only:
@echo "================================================================"
@echo "Building with coverage instrumentation (unit tests only)..."
@echo "================================================================"
./build.sh test_unit $(OS) $(ARCH)
ENABLE_COVERAGE=true ./build.sh build_backend $(OS) $(ARCH)
@echo "================================================================"
run:
./build.sh run $(OS) $(ARCH)
run_backend:
./build.sh run_backend $(OS) $(ARCH)
debug_backend:
./build.sh debug_backend $(OS) $(ARCH)
run_frontend:
./build.sh run_frontend $(OS) $(ARCH)
run_docs:
./build.sh run_docs
docker-build:
docker build -t $(BINARY_NAME):$(VERSION) .
docker-build-latest:
docker build -t $(BINARY_NAME):latest .
docker-build-multiarch:
docker buildx build --platform linux/amd64,linux/arm64 -t $(BINARY_NAME):$(VERSION) .
docker-build-multiarch-latest:
docker buildx build --platform linux/amd64,linux/arm64 -t $(BINARY_NAME):latest .
docker-build-multiarch-push:
docker buildx build --platform linux/amd64,linux/arm64 -t $(BINARY_NAME):$(VERSION) -t $(BINARY_NAME):latest --push .
lint: lint_backend lint_frontend
tools_build:
./build.sh tools_build
tools_test:
./build.sh tools_test
tools_lint: $(CLI_GOLANGCI_LINT) $(I18N_EXTRACTOR_GOLANGCI_LINT)
./build.sh tools_lint
tools_build_cli:
./build.sh tools_build_cli
tools_test_cli:
./build.sh tools_test_cli
tools_lint_cli: $(CLI_GOLANGCI_LINT)
./build.sh tools_lint_cli
tools_build_i18n_extractor:
./build.sh tools_build_i18n_extractor
tools_test_i18n_extractor:
./build.sh tools_test_i18n_extractor
tools_lint_i18n_extractor: $(I18N_EXTRACTOR_GOLANGCI_LINT)
./build.sh tools_lint_i18n_extractor
tools_test_cli_e2e:
cd $(CLI_E2E_DIR) && pnpm install --frozen-lockfile && pnpm test
tools_checks_cli: tools_lint_cli tools_test_cli
tools_checks: tools_lint tools_test
lint_docs:
@command -v vale >/dev/null 2>&1 || (echo "vale is not installed. See https://vale.sh/docs/vale-cli/installation/ for installation instructions." && exit 1)
vale docs/
lint_backend: check_i18n golangci-lint
cd backend && $(GOLANGCI_LINT) run ./...
lint_frontend:
pnpm install --frozen-lockfile && pnpm build:frontend && pnpm lint
generate_i18n: install-i18n-extractor
@echo "Extracting i18n messages from backend source code..."
cd backend && $(I18N_EXTRACTOR) -source ./internal,./pkg/thunderidengine -output ./internal/system/i18n/core/defaults.go
@echo "i18n defaults generated successfully"
check_i18n: install-i18n-extractor
@echo "Checking i18n messages..."
@cd backend && $(I18N_EXTRACTOR) -source ./internal,./pkg/thunderidengine -output ../defaults.check.go > /dev/null
@diff -u backend/internal/system/i18n/core/defaults.go defaults.check.go > /dev/null || (echo "i18n generated file is out of sync. Please run 'make generate_i18n'" && rm defaults.check.go && exit 1)
@rm defaults.check.go
@echo "i18n messages are up to date"
mockery: install-mockery
cd backend && $(MOCKERY) --config .mockery.public.yml
cd backend && $(MOCKERY) --config .mockery.private.yml
verify_mocks: mockery
@if [ -n "$$(git status --porcelain --untracked-files=all -- backend/tests/mocks ':(glob)backend/internal/**/*_mock_test.go')" ]; then \
echo "Mock files have been regenerated and differ from what is committed."; \
echo "Please review and commit the changes before pushing:"; \
git status --porcelain --untracked-files=all -- backend/tests/mocks ':(glob)backend/internal/**/*_mock_test.go'; \
exit 1; \
fi
@echo "All mock files are up to date."
format_check:
pnpm install --frozen-lockfile
pnpm format:check
test_frontend:
pnpm install --frozen-lockfile
cd frontend && pnpm build:packages
cd frontend/apps/console && pnpm test
cd frontend/apps/gate && pnpm test
security_audit:
cd frontend && pnpm audit --audit-level=high
cd tests/e2e && npm audit --audit-level=high
test_e2e:
chmod +x tests/e2e/run-e2e.sh
tests/e2e/run-e2e.sh
pr_checks: verify_mocks lint format_check tools_checks test_unit test_frontend test_integration build_backend build_frontend package_samples
help:
@echo "Makefile targets:"
@echo " all - Clean, build, and test the project."
@echo " backend - Clean, build, and test only the backend."
@echo " clean - Remove build artifacts."
@echo " build - Build $(PRODUCT_NAME) (backend + frontend + samples)."
@echo " build_backend - Build the backend Go application."
@echo " build_frontend - Build the frontend applications."
@echo " build_docs - Build the documentation."
@echo " package_samples - Package sample applications."
@echo " test_unit - Run unit tests."
@echo " test_integration - Run integration tests. Use RUN= for test filter, PACKAGE= for package filter."
@echo " test_integration_cp - Run the Control Plane integration tests. Needs build_backend and build_cp_backend first."
@echo " build_with_coverage - Build with coverage flags, run unit and integration tests, and generate combined coverage report."
@echo " build_with_coverage_only - Build with coverage instrumentation (unit tests only, no integration tests)."
@echo " test - Run all tests (unit and integration)."
@echo " run - Build and run the $(PRODUCT_NAME) server locally."
@echo " run_backend - Build and run the $(PRODUCT_NAME) backend locally."
@echo " debug_backend - Build and run the $(PRODUCT_NAME) backend locally in debug mode."
@echo " run_frontend - Build and run the frontend applications locally."
@echo " run_docs - Run the documentation development server with live reload."
@echo " docker-build - Build single-arch Docker image with version tag."
@echo " docker-build-latest - Build single-arch Docker image with latest tag."
@echo " docker-build-multiarch - Build multi-arch Docker image with version tag."
@echo " docker-build-multiarch-latest - Build multi-arch Docker image with latest tag."
@echo " docker-build-multiarch-push - Build and push multi-arch images to registry."
@echo " tools_build - Build all tool binaries (CLI + i18n-extractor + npm tools)."
@echo " tools_test - Run tests for all tools."
@echo " tools_lint - Run linting on all tools."
@echo " tools_build_cli - Cross-compile the CLI for all supported platforms."
@echo " tools_test_cli - Run CLI unit tests."
@echo " tools_lint_cli - Run golangci-lint on the CLI code."
@echo " tools_checks - Lint and test every tool (part of pr_checks)."
@echo " tools_checks_cli - Run the CLI lint and unit tests."
@echo " tools_test_cli_e2e - Run the CLI end-to-end suite against a real release."
@echo " tools_build_i18n_extractor - Build the i18n-extractor binary."
@echo " tools_test_i18n_extractor - Run i18n-extractor tests."
@echo " tools_lint_i18n_extractor - Run golangci-lint on the i18n-extractor code."
@echo " lint - Run linting on backend and frontend code."
@echo " lint_backend - Run golangci-lint on the backend code."
@echo " lint_frontend - Run ESLint on the frontend code."
@echo " lint_docs - Run Vale style linting on the documentation (requires vale)."
@echo " mockery - Generate mocks for unit tests using mockery."
@echo " verify_mocks - Regenerate and verify mock files are in sync with interfaces."
@echo " format_check - Check frontend code formatting with Prettier."
@echo " test_frontend - Run frontend unit tests (console + gate apps)."
@echo " security_audit - Run dependency security audit on frontend and E2E deps (simplified; CI applies additional ignore rules)."
@echo " test_e2e - Start server, import declarative resources, start sample app, and run Playwright E2E tests."
@echo " pr_checks - Run all checks that CI performs on pull requests."
@echo " generate_i18n - Extract i18n messages and generate defaults.go."
@echo " help - Show this help message."
.PHONY: all prepare clean build build_backend build_cp_backend build_frontend build_docs package_samples run
.PHONY: docker-build docker-build-latest docker-build-multiarch
.PHONY: docker-build-multiarch-latest docker-build-multiarch-push
.PHONY: test_unit test_integration test_integration_cp build_with_coverage build_with_coverage_only test
.PHONY: help go_install_tool
.PHONY: lint lint_backend lint_frontend lint_docs golangci-lint mockery install-mockery
.PHONY: tools_build tools_test tools_lint tools_build_cli tools_test_cli tools_lint_cli
.PHONY: tools_build_i18n_extractor tools_test_i18n_extractor tools_lint_i18n_extractor
.PHONY: tools_test_cli_e2e tools_checks_cli tools_checks
.PHONY: verify_mocks format_check test_frontend security_audit test_e2e pr_checks
.PHONY: run_backend debug_backend run_frontend run_docs
define go_install_tool
cd /tmp && \
GOBIN=$(TOOL_BIN) go install $(2)@$(3)
endef
golangci-lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT): $(TOOL_BIN)
$(call go_install_tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
$(CLI_GOLANGCI_LINT): $(CLI_TOOL_BIN)
cd /tmp && GOBIN=$(CLI_TOOL_BIN) go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
$(I18N_EXTRACTOR_GOLANGCI_LINT): $(I18N_EXTRACTOR_TOOL_BIN)
cd /tmp && GOBIN=$(I18N_EXTRACTOR_TOOL_BIN) go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
install-mockery: $(MOCKERY)
# mockery $(MOCKERY_VERSION) pins a golang.org/x/tools that can't read Go 1.27.2 export data, so it
# is built in a throwaway module with a newer x/tools.
$(MOCKERY): $(TOOL_BIN)
tmp=$$(mktemp -d) && cd $$tmp && go mod init mockery-build >/dev/null 2>&1 && \
GOFLAGS= go get github.com/vektra/mockery/v3@$(MOCKERY_VERSION) golang.org/x/tools@$(MOCKERY_XTOOLS_VERSION) && \
GOFLAGS= GOBIN=$(TOOL_BIN) go install github.com/vektra/mockery/v3 && \
rm -rf $$tmp
install-i18n-extractor: $(I18N_EXTRACTOR)
$(I18N_EXTRACTOR): $(TOOL_BIN)
@echo "Running unit tests for i18n-extractor..."
cd tools/i18n-extractor && go test -v .
@echo "Building i18n-extractor..."
cd tools/i18n-extractor && go build -o $(I18N_EXTRACTOR) .