-
Notifications
You must be signed in to change notification settings - Fork 176
Expand file tree
/
Copy pathMakefile
More file actions
449 lines (349 loc) · 15.1 KB
/
Makefile
File metadata and controls
449 lines (349 loc) · 15.1 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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
.PHONY: lint test test.coverage test.license.check test.agent.unit test.agent.setup test.setup test.e2e.ui.setup gen.setup gen.setup.backend gen.setup.ui gen.setup.agent check.generated.artifacts compose.setup
DB_NAME=superplane
DB_PASSWORD=the-cake-is-a-lie
BASE_URL?=https://app.superplane.com
export BUILDKIT_PROGRESS ?= plain
PKG_TEST_PACKAGES := ./pkg/...
E2E_TEST_PACKAGES := ./test/e2e/...
AGENT_TEST_TARGETS ?= tests
COMPOSE=docker compose -f docker-compose.dev.yml
DOCKER_RUN_AS_CURRENT_USER=docker run --rm --user $(shell id -u):$(shell id -g)
GENERATED_ARTIFACT_PATHS := pkg/protos pkg/openapi_client web_src/src/api-client agent/src/superplaneapi api/swagger/superplane.swagger.json agent/src/usage_pb2.py agent/src/private/agents_pb2.py agent/src/private/agents_pb2_grpc.py
#
# Long sausage command to run tests with gotestsum
#
# - starts a docker container for unit tests
# - mounts tmp/screenshots
# - exports junit report
# - sets parallelism to 1
#
GOTESTSUM=$(COMPOSE) run --rm -e DB_NAME=superplane_test -v $(PWD)/tmp/screenshots:/app/test/screenshots app gotestsum --format short --junitfile junit-report.xml
#
# Targets for test environment
#
lint:
$(COMPOSE) exec app revive -formatter friendly -config lint.toml -exclude ./tmp/... ./...
tidy:
$(COMPOSE) exec app go mod tidy
test.setup.build:
@touch agent/.env
@if [ -d "tmp/screenshots" ]; then rm -rf tmp/screenshots; fi
@mkdir -p tmp/screenshots
$(COMPOSE) build --pull
$(COMPOSE) run --rm app go mod download
$(MAKE) gen.setup.backend
$(MAKE) test.e2e.ui.setup
test.setup:
$(MAKE) test.setup.build
$(MAKE) test.setup.db
$(MAKE) test.start
test.setup.db:
$(MAKE) db.create DB_NAME=superplane_test
$(MAKE) db.migrate DB_NAME=superplane_test
$(MAKE) -C agent db.create DB_NAME=agents_test DB_PASSWORD=$(DB_PASSWORD)
$(MAKE) -C agent db.migrate DB_NAME=agents_test DB_PASSWORD=$(DB_PASSWORD)
test.start:
$(COMPOSE) up -d --wait
test.down:
$(COMPOSE) down --remove-orphans
test.e2e.setup:
$(MAKE) test.setup
test.e2e.ui.setup:
$(MAKE) openapi.web.client.gen
test.e2e:
$(COMPOSE) exec app gotestsum --format short --junitfile junit-report.xml --rerun-fails=3 --rerun-fails-max-failures=1 --packages="$(E2E_TEST_PACKAGES)" -- -p 1
test.e2e.autoparallel:
$(COMPOSE) exec -e INDEX -e TOTAL app bash -lc "cd /app && bash scripts/test_e2e_autoparallel.sh"
test.e2e.single:
bash ./scripts/vscode_run_tests.sh line $(FILE) $(LINE)
test:
$(GOTESTSUM) --packages="$(PKG_TEST_PACKAGES)" -- -p 1
test.coverage:
$(GOTESTSUM) --packages="$(PKG_TEST_PACKAGES)" -- -p 1 -coverprofile=coverage-go.out -covermode=atomic
$(COMPOSE) run --rm app go tool cover -func=coverage-go.out | grep '^total:'
test.coverage.check:
$(MAKE) test.coverage
$(MAKE) check.coverage.go
test.coverage.baseline.update:
$(MAKE) test.coverage
$(MAKE) check.coverage.go.baseline.update
test.license.check:
$(MAKE) gen.setup.backend
bash ./scripts/license-check.sh
test.watch:
$(GOTESTSUM) --packages="$(PKG_TEST_PACKAGES)" --watch -- -p 1
# Subset: CASES=comma-separated names from agent/evals/cases.py (optional).
test.agent.evals:
$(COMPOSE) exec $(if $(CASES),-e CASES=$(CASES),) agent uv run python -m evals.runner $(AGENT_EVAL_RUNNER_ARGS)
test.agent.setup:
@touch agent/.env
$(COMPOSE) build app agent
$(MAKE) gen.setup.agent
$(COMPOSE) up -d db
sleep 5
$(MAKE) -C agent db.create DB_NAME=agents_test DB_PASSWORD=$(DB_PASSWORD)
$(MAKE) -C agent db.migrate DB_NAME=agents_test DB_PASSWORD=$(DB_PASSWORD)
test.agent.unit:
$(COMPOSE) run --rm -e DB_NAME=agents_test agent uv run --group dev python -m pytest $(AGENT_TEST_TARGETS)
test.shell:
$(COMPOSE) run --rm -e DB_NAME=superplane_test -v $(PWD)/tmp/screenshots:/app/test/screenshots app /bin/bash
#
# Code formatting
#
format.go:
$(COMPOSE) exec app bash -c "find . -name '*.go' -not -path './tmp/*' -print0 | xargs -0 gofmt -s -w"
check.format.go:
$(COMPOSE) exec app bash -c "find . -name '*.go' -not -path './tmp/*' -print0 | xargs -0 gofmt -s -l | tee /dev/stderr | if read; then exit 1; else exit 0; fi"
format.js:
cd web_src && npm run format
format.js.check:
cd web_src && npm run format:check
#
# Targets for dev environment
#
dev.setup:
@touch agent/.env
$(COMPOSE) build
$(COMPOSE) pull
$(MAKE) gen.setup
$(MAKE) dev.setup.app
$(MAKE) dev.setup.agent
$(MAKE) db.create DB_NAME=superplane_dev
$(MAKE) db.migrate DB_NAME=superplane_dev
$(MAKE) -C agent db.create DB_NAME=agents_dev DB_PASSWORD=$(DB_PASSWORD)
$(MAKE) -C agent db.migrate DB_NAME=agents_dev DB_PASSWORD=$(DB_PASSWORD)
dev.setup.app:
$(COMPOSE) run --rm app go mod download
$(COMPOSE) run --rm app go build cmd/server/main.go
dev.setup.agent:
$(COMPOSE) run --rm agent uv sync --frozen || $(COMPOSE) run --rm agent uv sync
dev.setup.no.cache:
rm -rf tmp
$(COMPOSE) down -v --remove-orphans
$(COMPOSE) build --no-cache
$(MAKE) gen.setup
$(MAKE) db.create DB_NAME=superplane_dev
$(MAKE) db.migrate DB_NAME=superplane_dev
$(MAKE) -C agent db.create DB_NAME=agents_dev DB_PASSWORD=$(DB_PASSWORD)
$(MAKE) -C agent db.migrate DB_NAME=agents_dev DB_PASSWORD=$(DB_PASSWORD)
dev.start.fg:
$(COMPOSE) up
dev.start:
$(COMPOSE) up -d
@bash ./scripts/wait-for-app
dev.start.ephemeral:
bash ./scripts/ephemeral/start-caddy.sh $(BASE_URL)
bash ./scripts/ephemeral/setup-env.sh $(BASE_URL)
$(COMPOSE) up -d
dev.logs:
$(COMPOSE) logs -f
dev.logs.app:
$(COMPOSE) logs -f app
dev.logs.otel:
$(COMPOSE) logs -f otel
dev.logs.agent:
$(COMPOSE) logs -f agent
dev.down:
$(COMPOSE) down --remove-orphans
dev.console:
$(COMPOSE) run --rm app /bin/bash
dev.db:
$(COMPOSE) run --rm app sh -c 'PGPASSWORD=$(DB_PASSWORD) psql -h db -p 5432 -U postgres -d superplane_dev'
dev.db.console:
$(MAKE) db.console DB_NAME=superplane_dev
dev.pr.clean.checkout:
bash ./scripts/clean-pr-checkout $(PR)
check.example.payloads:
$(COMPOSE) run --rm app bash -c "go run scripts/check_example_payloads.go"
check.db.structure:
bash ./scripts/verify_db_structure_clean.sh
check.db.migrations:
bash ./scripts/verify_no_future_migrations.sh
check.build.ui:
$(COMPOSE) exec app bash -c "cd web_src && npm run build"
check.lint.ui:
$(COMPOSE) exec app bash -c "cd web_src && npm run lint:budget"
check.lint.ui.knip:
$(COMPOSE) exec app bash -c "cd web_src && npm ci && npm run lint:knip"
check.lint.ui.baseline.update:
$(COMPOSE) exec app bash -c "cd web_src && npm run lint:baseline:update"
check.build.app:
$(COMPOSE) exec app go build cmd/server/main.go
check.generated.artifacts:
@tracked="$$(git ls-files -- $(GENERATED_ARTIFACT_PATHS))"; \
if [ -n "$$tracked" ]; then \
echo "Tracked generated artifacts found:"; \
echo "$$tracked"; \
exit 1; \
fi
check.coverage.go:
go run ./scripts/check_go_coverage_budget.go --profile coverage-go.out
check.coverage.go.baseline.update:
go run ./scripts/check_go_coverage_budget.go --profile coverage-go.out --update-baseline
storybook:
$(COMPOSE) exec app /bin/bash -c "cd web_src && npm install && npm run storybook"
ui.setup:
npm install
ui.start:
npm run storybook
#
# Database target helpers
#
db.create:
-$(COMPOSE) run --rm -e PGPASSWORD=the-cake-is-a-lie app psql -h db -p 5432 -U postgres -c 'ALTER DATABASE template1 REFRESH COLLATION VERSION';
-$(COMPOSE) run --rm -e PGPASSWORD=the-cake-is-a-lie app psql -h db -p 5432 -U postgres -c 'ALTER DATABASE postgres REFRESH COLLATION VERSION';
-$(COMPOSE) run --rm -e PGPASSWORD=the-cake-is-a-lie app createdb -h db -p 5432 -U postgres $(DB_NAME)
$(COMPOSE) run --rm -e PGPASSWORD=the-cake-is-a-lie app psql -h db -p 5432 -U postgres $(DB_NAME) -c 'CREATE EXTENSION IF NOT EXISTS "uuid-ossp";'
db.migration.create:
$(COMPOSE) run --rm app mkdir -p db/migrations
$(COMPOSE) run --rm app migrate create -ext sql -dir db/migrations $(NAME)
ls -lah db/migrations/*$(NAME)*
db.data_migration.create:
$(COMPOSE) run --rm app mkdir -p db/data_migrations
$(COMPOSE) run --rm app migrate create -ext sql -dir db/data_migrations $(NAME)
ls -lah db/data_migrations/*$(NAME)*
db.migrate:
rm -f db/structure.sql
$(COMPOSE) run --rm --user $$(id -u):$$(id -g) app migrate -source file://db/migrations -database postgres://postgres:$(DB_PASSWORD)@db:5432/$(DB_NAME)?sslmode=disable up
$(COMPOSE) run --rm --user $$(id -u):$$(id -g) app migrate -source file://db/data_migrations -database postgres://postgres:$(DB_PASSWORD)@db:5432/$(DB_NAME)?sslmode=disable\&x-migrations-table=data_migrations up
# echo dump schema to db/structure.sql
$(COMPOSE) run --rm --user $$(id -u):$$(id -g) -e PGPASSWORD=$(DB_PASSWORD) app bash -c "pg_dump --schema-only --no-privileges --restrict-key abcdef123 --no-owner -h db -p 5432 -U postgres -d $(DB_NAME)" > db/structure.sql
$(COMPOSE) run --rm --user $$(id -u):$$(id -g) -e PGPASSWORD=$(DB_PASSWORD) app bash -c "pg_dump --data-only --restrict-key abcdef123 --table schema_migrations -h db -p 5432 -U postgres -d $(DB_NAME)" >> db/structure.sql
$(COMPOSE) run --rm --user $$(id -u):$$(id -g) -e PGPASSWORD=$(DB_PASSWORD) app bash -c "pg_dump --data-only --restrict-key abcdef123 --table data_migrations -h db -p 5432 -U postgres -d $(DB_NAME)" >> db/structure.sql
db.migrate.all:
$(MAKE) db.migrate DB_NAME=superplane_dev
$(MAKE) db.migrate DB_NAME=superplane_test
$(MAKE) -C agent db.create DB_NAME=agents_dev DB_PASSWORD=$(DB_PASSWORD)
$(MAKE) -C agent db.create DB_NAME=agents_test DB_PASSWORD=$(DB_PASSWORD)
$(MAKE) -C agent db.migrate DB_NAME=agents_dev DB_PASSWORD=$(DB_PASSWORD)
$(MAKE) -C agent db.migrate DB_NAME=agents_test DB_PASSWORD=$(DB_PASSWORD)
db.console:
$(COMPOSE) run --rm --user $$(id -u):$$(id -g) -e PGPASSWORD=the-cake-is-a-lie app psql -h db -p 5432 -U postgres $(DB_NAME)
db.delete:
$(COMPOSE) run --rm --user $$(id -u):$$(id -g) --rm -e PGPASSWORD=$(DB_PASSWORD) app dropdb -h db -p 5432 -U postgres $(DB_NAME)
db.recreate.all.dangerous:
$(MAKE) dev.down
-$(MAKE) db.delete DB_NAME=superplane_dev
-$(MAKE) db.delete DB_NAME=superplane_test
-$(MAKE) -C agent db.delete DB_NAME=agents_dev DB_PASSWORD=$(DB_PASSWORD)
-$(MAKE) -C agent db.delete DB_NAME=agents_test DB_PASSWORD=$(DB_PASSWORD)
$(MAKE) db.create DB_NAME=superplane_dev
$(MAKE) db.create DB_NAME=superplane_test
$(MAKE) -C agent db.create DB_NAME=agents_dev DB_PASSWORD=$(DB_PASSWORD)
$(MAKE) -C agent db.create DB_NAME=agents_test DB_PASSWORD=$(DB_PASSWORD)
$(MAKE) db.migrate DB_NAME=superplane_dev
$(MAKE) db.migrate DB_NAME=superplane_test
$(MAKE) -C agent db.migrate DB_NAME=agents_dev DB_PASSWORD=$(DB_PASSWORD)
$(MAKE) -C agent db.migrate DB_NAME=agents_test DB_PASSWORD=$(DB_PASSWORD)
#
# Protobuf compilation
#
gen.setup:
$(MAKE) pb.gen
$(MAKE) openapi.spec.gen
$(MAKE) openapi.client.gen
$(MAKE) openapi.web.client.gen
$(MAKE) openapi.python.client.gen
gen.setup.backend:
$(MAKE) pb.gen
$(MAKE) openapi.spec.gen
$(MAKE) openapi.client.gen
gen.setup.ui:
$(MAKE) openapi.spec.gen
$(MAKE) openapi.web.client.gen
gen.setup.agent:
$(MAKE) pb.gen
$(MAKE) openapi.spec.gen
$(MAKE) openapi.python.client.gen
gen:
$(MAKE) gen.setup
$(MAKE) format.go
$(MAKE) format.js
$(MAKE) gen.components.docs
gen.components.docs:
rm -rf docs/components
go run scripts/generate_components_docs.go
check.components.docs:
rm -rf docs/components
$(COMPOSE) run --rm app bash -c "go run scripts/generate_components_docs.go"
git diff --exit-code docs/components
MODULES := authorization,organizations,integrations,secrets,users,groups,roles,me,configuration,components,triggers,widgets,blueprints,canvases,service_accounts,agents,usage,private/agents
REST_API_MODULES := authorization,organizations,integrations,secrets,users,groups,roles,me,configuration,components,triggers,widgets,blueprints,canvases,service_accounts,agents
compose.setup:
@touch agent/.env
pb.gen:
$(MAKE) compose.setup
$(COMPOSE) run --rm --no-deps app /app/scripts/protoc.sh $(MODULES)
$(COMPOSE) run --rm --no-deps app /app/scripts/protoc_gateway.sh $(REST_API_MODULES)
$(COMPOSE) run --rm --no-deps agent bash -lc "cd /app/agent && uv run --with grpcio-tools bash /app/scripts/protoc_python.sh"
$(COMPOSE) run --rm --no-deps --user $(shell id -u):$(shell id -g) app bash -lc "find pkg/protos -name '*.go' -print0 | xargs -0 gofmt -s -w"
openapi.spec.gen:
$(MAKE) compose.setup
$(COMPOSE) run --rm --no-deps app /app/scripts/protoc_openapi_spec.sh $(REST_API_MODULES)
openapi.client.gen:
rm -rf pkg/openapi_client
$(DOCKER_RUN_AS_CURRENT_USER) \
-v ${PWD}:/local openapitools/openapi-generator-cli:v7.13.0 generate \
-i /local/api/swagger/superplane.swagger.json \
-g go \
-o /local/pkg/openapi_client \
--additional-properties=packageName=openapi_client,enumClassPrefix=true,isGoSubmodule=true,withGoMod=false
rm -rf pkg/openapi_client/test
rm -rf pkg/openapi_client/docs
rm -rf pkg/openapi_client/api
rm -rf pkg/openapi_client/.travis.yml
rm -rf pkg/openapi_client/README.md
rm -rf pkg/openapi_client/git_push.sh
$(COMPOSE) run --rm --no-deps --user $(shell id -u):$(shell id -g) app bash -lc "find pkg/openapi_client -name '*.go' -print0 | xargs -0 gofmt -s -w"
openapi.web.client.gen:
$(MAKE) compose.setup
rm -rf web_src/src/api-client
$(COMPOSE) run --rm --no-deps --user $(shell id -u):$(shell id -g) app bash -lc "export HOME=/tmp && export NPM_CONFIG_CACHE=/tmp/.npm && cd web_src && npm ci && npm run generate:api && npx prettier --write 'src/api-client/**/*.{ts,tsx}'"
openapi.python.client.gen:
rm -rf agent/src/superplaneapi
$(DOCKER_RUN_AS_CURRENT_USER) \
-v ${PWD}:/local openapitools/openapi-generator-cli:v7.13.0 generate \
-i /local/api/swagger/superplane.swagger.json \
-g python \
-o /local/agent/src/superplaneapi \
--package-name superplaneapi \
--additional-properties=packageName=superplaneapi,projectName=superplaneapi,generateSourceCodeOnly=true
cp -R agent/src/superplaneapi/superplaneapi/. agent/src/superplaneapi/
rm -rf agent/src/superplaneapi/superplaneapi
rm -rf agent/src/superplaneapi/docs
rm -rf agent/src/superplaneapi/test
rm -rf agent/src/superplaneapi/.openapi-generator
#
# Image and CLI build
#
CLI_VERSION ?= $(shell git describe --tags --abbrev=0 2>/dev/null || echo "dev")
cli.build:
$(MAKE) gen.setup.backend
$(COMPOSE) run --rm --no-deps -e GOOS=$(OS) -e GOARCH=$(ARCH) app bash -c 'go build -ldflags "-X github.com/superplanehq/superplane/pkg/cli.Version=$(CLI_VERSION)" -o build/cli cmd/cli/main.go'
cli.build.m1:
$(MAKE) cli.build OS=darwin ARCH=arm64
IMAGE?=superplane
AGENT_IMAGE?=superplane-agent
IMAGE_TAG?=$(shell git rev-list -1 HEAD -- .)
REGISTRY_HOST?=ghcr.io/superplanehq
image.build:
$(MAKE) gen.setup
DOCKER_DEFAULT_PLATFORM=linux/amd64 docker build -f Dockerfile --target runner --build-arg BASE_URL=$(BASE_URL) --progress plain -t $(IMAGE):$(IMAGE_TAG) .
agent.image.build:
$(MAKE) gen.setup.agent
DOCKER_DEFAULT_PLATFORM=linux/amd64 docker build -f agent/Dockerfile --target runner --progress plain -t $(AGENT_IMAGE):$(IMAGE_TAG) agent
image.auth:
@printf "%s" "$(GITHUB_TOKEN)" | docker login ghcr.io -u superplanehq --password-stdin
image.push:
docker tag $(IMAGE):$(IMAGE_TAG) $(REGISTRY_HOST)/$(IMAGE):$(IMAGE_TAG)
docker push $(REGISTRY_HOST)/$(IMAGE):$(IMAGE_TAG)
agent.image.push:
docker tag $(AGENT_IMAGE):$(IMAGE_TAG) $(REGISTRY_HOST)/$(AGENT_IMAGE):$(IMAGE_TAG)
docker push $(REGISTRY_HOST)/$(AGENT_IMAGE):$(IMAGE_TAG)
#
# Tag creation
#
tag.create.patch:
./release/create_tag.sh patch
tag.create.minor:
./release/create_tag.sh minor