-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathMakefile
More file actions
311 lines (235 loc) · 9.78 KB
/
Makefile
File metadata and controls
311 lines (235 loc) · 9.78 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
.PHONY: lint test test.license.check
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/...
COMPOSE=docker compose -f docker-compose.dev.yml
#
# 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:
@touch agent/.env
@if [ -d "tmp/screenshots" ]; then rm -rf tmp/screenshots; fi
@mkdir -p tmp/screenshots
$(COMPOSE) build
$(COMPOSE) run --rm app go mod download
$(MAKE) db.create DB_NAME=superplane_test
$(MAKE) db.migrate DB_NAME=superplane_test
test.start:
$(COMPOSE) up -d
sleep 5
test.down:
$(COMPOSE) down --remove-orphans
test.e2e.setup:
$(MAKE) test.setup
$(COMPOSE) exec app bash -c "cd web_src && npm ci"
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.license.check:
bash ./scripts/license-check.sh
test.watch:
$(GOTESTSUM) --packages="$(PKG_TEST_PACKAGES)" --watch -- -p 1
test.shell:
$(COMPOSE) run --rm -e DB_NAME=superplane_test -v $(PWD)/tmp/screenshots:/app/test/screenshots app /bin/bash
setup.playwright:
$(COMPOSE) exec app bash -c "bash scripts/docker/retry.sh 6 2s go install github.com/playwright-community/playwright-go/cmd/playwright@v0.5200.1"
$(COMPOSE) exec app bash -c "if [ -d /app/tmp/ms-playwright ] && [ \"$(ls -A /app/tmp/ms-playwright 2>/dev/null)\" ]; then echo \"Playwright browsers cache present, skipping install\"; else bash scripts/docker/retry.sh 6 2s playwright install chromium-headless-shell --with-deps; fi"
#
# Code formatting
#
format.go:
$(COMPOSE) exec app bash -c "find . -name '*.go' -not -path './tmp/*' -print0 | xargs -0 gofmt -s -w"
format.go.check:
$(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) dev.setup.app
$(MAKE) dev.setup.agent
$(MAKE) db.create DB_NAME=superplane_dev
$(MAKE) db.migrate DB_NAME=superplane_dev
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) db.create DB_NAME=superplane_dev
$(MAKE) db.migrate DB_NAME=superplane_dev
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.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)
dev.agent.console:
$(COMPOSE) exec agent uv run python -m repl.main --interactive --canvas-id "$(CANVAS_ID)" --start-repl-web
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.build.app:
$(COMPOSE) exec app go build cmd/server/main.go
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
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) db.create DB_NAME=superplane_dev
$(MAKE) db.create DB_NAME=superplane_test
$(MAKE) db.migrate DB_NAME=superplane_dev
$(MAKE) db.migrate DB_NAME=superplane_test
#
# Protobuf compilation
#
gen:
$(MAKE) pb.gen
$(MAKE) openapi.spec.gen
$(MAKE) openapi.client.gen
$(MAKE) openapi.web.client.gen
$(MAKE) format.go
$(MAKE) format.js
$(MAKE) gen.components.docs
gen.components.docs:
rm -rf docs/components
go run scripts/generate_components_docs.go
gen.components.local.update: gen.components.docs
rm -rf ../docs/src/content/docs/components
cp -R docs/components ../docs/src/content/docs/components
MODULES := authorization,organizations,integrations,secrets,users,groups,roles,me,configuration,components,triggers,widgets,blueprints,canvases,service_accounts
REST_API_MODULES := authorization,organizations,integrations,secrets,users,groups,roles,me,configuration,components,triggers,widgets,blueprints,canvases,service_accounts
pb.gen:
$(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)
openapi.spec.gen:
$(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 --rm \
-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
openapi.web.client.gen:
rm -rf web_src/src/api-client
$(COMPOSE) run --rm --no-deps app bash -c "cd web_src && npm run generate:api"
#
# Image and CLI build
#
cli.build:
$(COMPOSE) run --rm --no-deps -e GOOS=$(OS) -e GOARCH=$(ARCH) app bash -c 'go build -o build/cli cmd/cli/main.go'
cli.build.m1:
$(MAKE) cli.build OS=darwin ARCH=arm64
IMAGE?=superplane
IMAGE_TAG?=$(shell git rev-list -1 HEAD -- .)
REGISTRY_HOST?=ghcr.io/superplanehq
image.build:
DOCKER_DEFAULT_PLATFORM=linux/amd64 docker build -f Dockerfile --target runner --build-arg BASE_URL=$(BASE_URL) --progress plain -t $(IMAGE):$(IMAGE_TAG) .
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)
#
# Tag creation
#
tag.create.patch:
./release/create_tag.sh patch
tag.create.minor:
./release/create_tag.sh minor