-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
228 lines (214 loc) · 8.43 KB
/
Makefile
File metadata and controls
228 lines (214 loc) · 8.43 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
.PHONY: help clean clean-all stop-apiserver test test-angular test-react publish publish-dry-run update-version angular react .check-apiserver .install-playwright
# Default target
help:
@echo "Usage: make <version>"
@echo " make <framework> <version>"
@echo ""
@echo "Examples:"
@echo " make 1.34 # Build and test both Angular and React"
@echo " make angular 1.34 # Build and test Angular only"
@echo " make react 1.34 # Build and test React only"
@echo " PUBLISH=true make angular 1.34 # Build, test, and publish Angular"
@echo ""
@echo "This will:"
@echo " 1. Start kube-apiserver v<version> in a Docker container"
@echo " 2. Update package.json versions to <version>.0-angular and <version>.0-react"
@echo " 3. Fetch OpenAPI v3 specs from https://localhost:6443/openapi/v3"
@echo " 4. Generate TypeScript clients for Angular and React using orval"
@echo " 5. Build packages"
@echo " 6. Run integration tests"
@echo " 7. Stop Docker containers"
@echo " 8. Publish to npm (if PUBLISH=true)"
@echo ""
@echo "Other targets:"
@echo " clean - Remove generated code and built artifacts"
@echo " clean-all - Clean everything including Docker containers and specs"
@echo " stop-apiserver - Stop the running kube-apiserver container"
@echo " test - Run all integration tests and stop Docker containers when done"
@echo " test-angular - Run Angular integration tests only"
@echo " test-react - Run React integration tests only"
@echo " publish - Publish packages to npm"
@echo " publish-dry-run - Test publish without actually publishing to npm"
@echo " update-version - Update package.json versions (make update-version VERSION=1.34)"
# Stop any running kube-apiserver container
stop-apiserver:
@echo "Stopping kube-apiserver and etcd containers..."
@docker compose down 2>/dev/null || true
# Clean generated files and built artifacts
clean:
@echo "Cleaning generated files and built artifacts..."
@rm -rf angular/src/generated react/src/generated angular/dist react/dist
@rm -f angular/src/index.ts react/src/index.ts
@rm -f openapi-specs/_merged.json openapi-specs/_merge-config.json
@echo "✓ Cleaned generated code and dist directories"
# Clean everything including specs and Docker containers
clean-all: clean stop-apiserver
@echo "Cleaning OpenAPI specs..."
@rm -rf openapi-specs
@echo "✓ Full cleanup complete"
# Internal function to check apiserver (starts it if not running)
.check-apiserver:
@if ! docker ps | grep -q k8s-apiserver; then \
echo "kube-apiserver is not running, starting it..."; \
K8S_VERSION=1.35 docker compose up -d || exit 1; \
echo "Waiting for kube-apiserver to be ready..."; \
sleep 30; \
fi
@echo "✓ kube-apiserver is running"
# Internal function to install Playwright
.install-playwright:
@echo "Installing Playwright browsers (if needed)..."
@npx playwright install chromium --with-deps > /dev/null 2>&1 || true
@echo "✓ Playwright browsers ready"
# Run Angular integration tests
test-angular:
@echo "Running Angular integration tests..."
@$(MAKE) .check-apiserver
@$(MAKE) .install-playwright
@echo ""
@echo "Cleaning up any orphaned servers on port 4200..."
@pkill -f "serve -l 4200" 2>/dev/null || true
@sleep 1
@echo "Starting test server on port 4200..."
@cd angular-tests && npx serve -l 4200 --no-request-logging --no-clipboard . > /tmp/angular-test-server.log 2>&1 & \
SERVER_PID=$$!; \
sleep 3; \
yarn --cwd angular-tests run test || TEST_FAILED=1; \
kill $$SERVER_PID 2>/dev/null || true; \
if [ "$$TEST_FAILED" = "1" ]; then \
echo "✗ Tests failed (see /tmp/angular-test-server.log)"; \
exit 1; \
fi; \
echo "✓ Angular tests passed!"
# Run React integration tests
test-react:
@echo "Running React integration tests..."
@$(MAKE) .check-apiserver
@$(MAKE) .install-playwright
@echo ""
@echo "Cleaning up any orphaned servers on port 3000..."
@pkill -f "serve -l 3000" 2>/dev/null || true
@sleep 1
@echo "Starting test server on port 3000..."
@cd react-tests && npx serve -l 3000 . > /tmp/react-test-server.log 2>&1 & \
SERVER_PID=$$!; \
sleep 3; \
yarn --cwd react-tests run test || TEST_FAILED=1; \
kill $$SERVER_PID 2>/dev/null || true; \
if [ "$$TEST_FAILED" = "1" ]; then \
echo "✗ Tests failed (see /tmp/react-test-server.log)"; \
exit 1; \
fi; \
echo "✓ React tests passed!"
# Run all integration tests
test: test-angular test-react
@echo ""
@echo "✓ All integration tests passed!"
@echo ""
@echo "Stopping Docker containers..."
@$(MAKE) stop-apiserver
@echo "✓ Docker containers stopped"
# Publish packages to npm
publish:
@node scripts/publish.js
# Dry-run publish (shows what would be published without actually publishing)
publish-dry-run:
@node scripts/publish.js --dry-run
# Update package versions to match k8s version
update-version:
@if [ -z "$(VERSION)" ]; then \
echo "Error: VERSION not specified"; \
echo "Usage: make update-version VERSION=1.34"; \
exit 1; \
fi
@node scripts/update-versions.js $(VERSION)
# Pattern rule for framework-specific version targets (e.g., make angular 1.34)
angular react:
@if [ -z "$(filter-out $@,$(MAKECMDGOALS))" ]; then \
echo "Error: Version required after framework name"; \
echo "Usage: make $@ <version>"; \
echo "Example: make $@ 1.34"; \
exit 1; \
fi
@VERSION=$(filter-out $@,$(MAKECMDGOALS)); \
if echo "$$VERSION" | grep -qE '^[0-9]+\.[0-9]+$$'; then \
echo "Building $@ for Kubernetes v$$VERSION..."; \
$(MAKE) stop-apiserver; \
mkdir -p openapi-specs; \
echo "Starting etcd and kube-apiserver with docker compose..."; \
K8S_VERSION=$$VERSION docker compose up -d || (echo "Failed to start services. Version v$$VERSION.0 may not exist."; exit 1); \
echo "Waiting for kube-apiserver to be ready..."; \
sleep 30; \
echo "Updating package version to $$VERSION.0-$@..."; \
$(MAKE) update-version VERSION=$$VERSION; \
echo "Fetching OpenAPI specs from kube-apiserver..."; \
yarn fetch-specs; \
echo "Generating $@ client..."; \
yarn --cwd $@ run generate; \
echo "Building $@ package..."; \
yarn --cwd $@ run build; \
echo "Running $@ tests..."; \
$(MAKE) test-$@; \
echo "Stopping Docker containers..."; \
$(MAKE) stop-apiserver; \
echo ""; \
echo "✓ Done! $@ client generated for Kubernetes v$$VERSION"; \
echo ""; \
if [ "$(PUBLISH)" = "true" ]; then \
echo "Publishing $@ to npm (PUBLISH=true)..."; \
FRAMEWORK=$@ $(MAKE) publish; \
else \
echo "Skipping publish (set PUBLISH=true to publish)"; \
echo ""; \
echo "To publish manually:"; \
echo " FRAMEWORK=$@ make publish-dry-run # Preview"; \
echo " FRAMEWORK=$@ make publish # Publish"; \
fi; \
else \
echo "Error: Invalid version '$$VERSION'"; \
echo "Use 'make help' for usage information"; \
exit 1; \
fi
# Pattern rule to handle version targets (e.g., make 1.34)
# Also ignores version argument when used with framework targets
%:
@if [ "$@" != "$(firstword $(MAKECMDGOALS))" ] && (echo "$(firstword $(MAKECMDGOALS))" | grep -qE '^(angular|react)$$'); then \
: ; \
elif echo "$@" | grep -qE '^[0-9]+\.[0-9]+$$'; then \
echo "Starting kube-apiserver v$@..."; \
$(MAKE) stop-apiserver; \
mkdir -p openapi-specs; \
echo "Starting etcd and kube-apiserver with docker compose..."; \
K8S_VERSION=$@ docker compose up -d || (echo "Failed to start services. Version v$@.0 may not exist."; exit 1); \
echo "Waiting for kube-apiserver to be ready..."; \
sleep 30; \
echo "Updating package versions to $@.0-angular and $@.0-react..."; \
$(MAKE) update-version VERSION=$@; \
echo "Fetching OpenAPI specs from kube-apiserver..."; \
yarn fetch-specs; \
echo "Generating client libraries..."; \
yarn --cwd angular run generate && yarn --cwd react run generate; \
echo "Building packages..."; \
yarn build; \
echo "Running tests..."; \
$(MAKE) test; \
echo "Stopping Docker containers..."; \
$(MAKE) stop-apiserver; \
echo ""; \
echo "✓ Done! Client libraries generated for Kubernetes v$@"; \
echo ""; \
if [ "$(PUBLISH)" = "true" ]; then \
echo "Publishing to npm (PUBLISH=true)..."; \
$(MAKE) publish; \
else \
echo "Skipping publish (set PUBLISH=true to publish)"; \
echo ""; \
echo "To publish manually:"; \
echo " make publish-dry-run # Preview"; \
echo " make publish # Publish"; \
fi; \
else \
echo "Error: Invalid target '$@'"; \
echo "Use 'make help' for usage information"; \
exit 1; \
fi