forked from juspay/superposition
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
408 lines (343 loc) · 12.6 KB
/
Copy pathmakefile
File metadata and controls
408 lines (343 loc) · 12.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
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
SMITHY_BUILD_SRC := smithy/output/source
SMITHY_CLIENT_DIR := clients/generated/smithy
IMAGE_NAME ?= context-aware-config
DOCKER_DNS ?= localhost
SHELL := /usr/bin/env bash
FEATURES ?= ssr
FE_FEATURES ?= hydrate
CARGO_FLAGS := --color always --no-default-features
EXCLUDE_PACKAGES := experimentation_client_integration_example superposition_sdk
FMT_EXCLUDE_PACKAGES_REGEX := $(shell echo "$(EXCLUDE_PACKAGES)" | sed "s/ /|/g")
LINT_FLAGS := --workspace --all-targets --all-features $(addprefix --exclude ,$(EXCLUDE_PACKAGES)) --no-deps
COMPONENT_NAME_FLAGS :=
CARGO_TARGET_DIR := $(shell cargo metadata --no-deps --format-version 1 | jq -r .target_directory)
# Get all workspace members and filter out excluded ones
#
define get_workspace_members
cargo metadata --format-version 1 --no-deps | \
jq -r '.workspace_members[]' | \
awk -F '#' '{print $$1;}' | awk -F '/' '{print $$NF;}' | \
grep -v -E '$(FMT_EXCLUDE_PACKAGES_REGEX)'
endef
WORKSPACE_MEMBERS := $(shell $(get_workspace_members))
# Create the package flags for cargo fmt
FMT_PACKAGE_FLAGS := $(addprefix -p ,$(WORKSPACE_MEMBERS))
LEPTOS_PACKAGES := $(addprefix crates/,$(WORKSPACE_MEMBERS))
WASM_PACK_MODE ?= --dev
HAS_DOCKER := $(shell command -v docker > /dev/null; echo $$?)
HAS_PODMAN := $(shell command -v podman > /dev/null; echo $$?)
ifeq ($(HAS_DOCKER),0)
DOCKER := docker
else ifeq ($(HAS_PODMAN),0)
DOCKER := podman
export PODMAN_COMPOSE_WARNING_LOGS = false
else
$(error "Neither docker nor podman found, please install one of them.")
endif
COMPOSE := $(DOCKER) compose
define read-container-name
yq -r '.services.$(1).container_name' docker-compose.yaml
endef
define check-container
$(DOCKER) ps | grep $(1) 2>&1 > /dev/null; echo $$?
endef
DB_CONTAINER_NAME = $(shell $(call read-container-name,postgres))
DB_UP = $(shell $(call check-container,$(DB_CONTAINER_NAME)))
LSTACK_CONTAINER_NAME = $(shell $(call read-container-name,localstack))
LSTACK_UP = $(shell $(call check-container,$(LSTACK_CONTAINER_NAME)))
export SMITHY_MAVEN_REPOS = https://repo1.maven.org/maven2|https://sandbox.assets.juspay.in/smithy/m2
.PHONY: amend \
amend-no-edit \
backend \
build \
check \
cleanup \
clients \
commit \
db \
db-init \
default \
env-file \
fmt \
frontend \
get-password \
grafana-local \
kill \
legacy_db_setup \
leptosfmt \
lint \
lint-fix \
local-docs-view \
localstack \
migration \
node-dependencies \
provider-template \
run \
run_legacy \
schema-file \
setup \
setup-clients \
smithy-api-docs \
smithy-build \
smithy-clean \
smithy-clean-build \
smithy-clients \
smithy-updates \
superposition \
superposition-example \
superposition_dev \
superposition_legacy \
tailwind \
test \
test-js-provider \
test-kotlin-provider \
test-py-provider \
test-rust-provider \
uniffi-bindings \
validate-aws-connection \
validate-psql-connection
env-file:
@if ! [ -e .env ]; then \
echo ".env missing, copying .env.example as .env" && \
cp .env.example .env; \
fi
db:
ifndef CI
ifeq ($(DB_UP),1)
$(COMPOSE) up -d postgres
endif
else
@echo "Skipping postgres container-setup in CI."
endif
@echo "Verifying postgres readiness..."
@while ! pg_isready -h $(DOCKER_DNS) -p 5432; do sleep 0.5; done
localstack:
ifndef CI
ifeq ($(LSTACK_UP),1)
$(COMPOSE) up -d localstack
endif
else
@echo "Skipping localstack container-setup in CI."
endif
@echo "Verifying localstack readiness..."
@while ! aws --no-cli-pager --endpoint-url=http://$(DOCKER_DNS):4566 --region=ap-south-1 sts get-caller-identity; do \
sleep 0.5; \
done
db-init:
set -a; . .env; set +a; psql "$$DATABASE_URL" -f superposition.sql
cleanup:
-$(DOCKER) rm -f $$($(DOCKER) container ls --filter name=^superposition -a -q)
-$(DOCKER) rmi -f $$($(DOCKER) images | grep $(DB_CONTAINER_NAME) | cut -f 10 -d " ")
migration: cleanup db
diesel migration run --locked-schema --config-file=crates/superposition_types/src/database/diesel.toml
$(COMPOSE) down
legacy_db_setup:
grep 'DATABASE_URL=' .env | sed -e 's/DATABASE_URL=//' | xargs ./scripts/legacy-db-setup.sh
validate-aws-connection:
aws --no-cli-pager --endpoint-url=http://$(DOCKER_DNS):4566 --region=ap-south-1 sts get-caller-identity
validate-psql-connection:
pg_isready -h $(DOCKER_DNS) -p 5432
node-dependencies:
npm ci
SETUP_DEPS = env-file db
ifdef CI
SETUP_DEPS += db-init
endif
setup: $(SETUP_DEPS) node-dependencies setup-clients
setup-clients:
cd clients/javascript/sdk && npm ci &&\
npm run build:cjs &&\
npm run build:types &&\
npm run build:es
cd tests && bun install
clients: smithy-clients setup-clients
kill:
-@pkill -f $(CARGO_TARGET_DIR)/debug/superposition &
get-password:
export DB_PASSWORD=`./docker-compose/localstack/get_db_password.sh` && echo $$DB_PASSWORD
superposition: CARGO_FLAGS += --features='$(FEATURES)'
superposition:
cargo build $(CARGO_FLAGS) --bin superposition
@cd $(CARGO_TARGET_DIR) && ln -s ../node_modules node_modules || true
superposition-example:
cargo run --bin cac-demo-app
superposition_legacy: CARGO_FLAGS += --features='$(FEATURES)
superposition_legacy: CARGO_FLAGS += superposition_types/disable_db_data_validation
superposition_legacy: CARGO_FLAGS += context_aware_config/disable_db_data_validation
superposition_legacy: CARGO_FLAGS += experimentation_platform/disable_db_data_validation'
superposition_legacy:
cargo build $(CARGO_FLAGS) --bin superposition
superposition_dev: CARGO_FLAGS += --features='$(FEATURES)'
superposition_dev:
# export DB_PASSWORD=`./docker-compose/localstack/get_db_password.sh`
cargo watch -x 'run $(CARGO_FLAGS) --bin superposition'
frontend:
cd crates/frontend && \
wasm-pack build --target web $(WASM_PACK_MODE) --no-default-features --features '$(FE_FEATURES)'
cd crates/frontend && \
npx tailwindcss -i ./styles/tailwind.css -o ./pkg/style.css
-rm -rf $(CARGO_TARGET_DIR)/site
mkdir -p $(CARGO_TARGET_DIR)/site/pkg
mv crates/frontend/pkg $(CARGO_TARGET_DIR)/site/
cp -a crates/frontend/assets/. $(CARGO_TARGET_DIR)/site/
backend: CARGO_FLAGS += --features='$(FEATURES)' --color always
backend:
-rm -rf $(CARGO_TARGET_DIR)/node_modules
npm --prefix ./crates/context_aware_config/ ci
mv crates/context_aware_config/node_modules $(CARGO_TARGET_DIR)/
cargo build $(CARGO_FLAGS)
build: frontend backend
run: kill db frontend superposition
@$(CARGO_TARGET_DIR)/debug/superposition
%_run: kill db frontend superposition
@RUST_LOG=$* $(CARGO_TARGET_DIR)/debug/superposition
run_legacy: kill build db superposition_legacy
@$(CARGO_TARGET_DIR)/debug/superposition
test: WASM_PACK_MODE=--profiling
test: setup frontend superposition
cargo test
@echo "Running superposition"
@$(CARGO_TARGET_DIR)/debug/superposition &
@echo "Awaiting superposition boot..."
## FIXME Curl doesn't retry.
@curl --silent --retry 10 \
--connect-timeout 2 \
--retry-all-errors \
'http://localhost:8080/health' 2>&1 > /dev/null
cd tests && bun test:clean
-@pkill -f $(CARGO_TARGET_DIR)/debug/superposition &
## npm run test
## FIXME Broken as requires hardcoded 'org_id'. Current test setup doesn't create
## deterministic 'org_id'.
# cd $(SMITHY_CLIENT_DIR)/ts && npm ci && npm test
tailwind:
cd crates/frontend && npx tailwindcss -i ./styles/tailwind.css -o ./pkg/style.css --watch
smithy-clean:
rm -rf smithy/output
smithy-build:
cd smithy && smithy build
smithy-clean-build: smithy-clean smithy-build
smithy-clients: smithy-build
## Moving the Java client like this as smithy publishes it as a java project.
## Probably want to use that to publish it ourselves in the future.
rm -rf clients/java/sdk/src/main/java
mkdir -p clients/java/sdk/src/main/java
cp -r $(SMITHY_BUILD_SRC)/java-client-codegen/*\
clients/java/sdk/src/main/java
git restore clients/java/sdk/src/main/java/io/juspay/superposition/client/auth/BasicAuthIdentityResolver.java
git restore clients/java/sdk/src/main/java/io/juspay/superposition/client/auth/BearerTokenIdentityResolver.java
rm -rf clients/python/sdk
mkdir -p clients/python/sdk
cp -r $(SMITHY_BUILD_SRC)/python-client-codegen/*\
clients/python/sdk
git restore clients/python/sdk/superposition_sdk/auth_helpers.py
git restore clients/python/sdk/AUTH_README.md
rm -rf clients/haskell/sdk
mkdir -p clients/haskell/sdk
cp -r $(SMITHY_BUILD_SRC)/haskell-client-codegen/*\
clients/haskell/sdk
rm -rf clients/javascript/sdk
mkdir -p clients/javascript/sdk
git restore clients/javascript/sdk/README.md
cp -r $(SMITHY_BUILD_SRC)/typescript-client-codegen/*\
clients/javascript/sdk
git restore clients/javascript/sdk/LICENSE
rm -rf crates/superposition_sdk
mkdir -p crates/superposition_sdk
git restore crates/superposition_sdk/README.md
git restore crates/superposition_sdk/CHANGELOG.md
cp -r $(SMITHY_BUILD_SRC)/rust-client-codegen/*\
crates/superposition_sdk
@for d in $(SMITHY_BUILD_SRC)/*-client-codegen; do \
[ -d "$$d" ] || continue; \
[[ "$$d" =~ "java" || "$$d" =~ "haskell" || "$$d" =~ "python" || "$$d" =~ "typescript" || "$$d" =~ "rust" ]] && continue; \
name=$$(basename "$$d" -client-codegen); \
mkdir -p "$(SMITHY_CLIENT_DIR)/$$name"; \
cp -r "$$d"/* "$(SMITHY_CLIENT_DIR)/$$name"; \
done
git restore clients/python/sdk/README.md
git restore LICENSE
git apply smithy/patches/*.patch
# API Documentation targets
smithy-api-docs: smithy-build
rm -rf docs/docs/api
mkdir -p docs/docs/api
cp $(SMITHY_BUILD_SRC)/openapi/Superposition.openapi.json docs/docs/api/
cd docs && npm ci && npm run openapi-docs
smithy-updates: smithy-clients smithy-api-docs
leptosfmt:
leptosfmt $(LEPTOS_FMT_FLAGS) $(LEPTOS_PACKAGES)
# Note: Run make from the repository root for correct path exclusions!
lint-fix: LINT_FLAGS += --fix --allow-dirty --allow-staged
lint-fix: COMPONENT_NAME_FLAGS = --fix
lint-fix: lint
check: FMT_FLAGS += --check
check: LEPTOS_FMT_FLAGS += --check
check: LINT_FLAGS += -- -Dwarnings
check: fmt leptosfmt lint
# Target to run cargo fmt on filtered packages
fmt:
@echo "Running cargo fmt on packages: $(WORKSPACE_MEMBERS)"
cargo fmt $(FMT_PACKAGE_FLAGS)
lint:
cargo clippy $(LINT_FLAGS)
@./scripts/check_component_names.sh $(COMPONENT_NAME_FLAGS)
commit: check
git commit $(COMMIT_FLAGS)
amend: COMMIT_FLAGS += --amend
amend: commit
amend-no-edit: COMMIT_FLAGS += --no-edit
amend-no-edit: amend
grafana-local:
cd grafana && $(COMPOSE) up
local-docs-view: smithy-api-docs
cd docs && npm start
default: dev-build frontend
schema-file:
diesel migration run --config-file=crates/superposition_types/src/database/diesel.toml
diesel print-schema > crates/superposition_types/src/database/schema.rs
git apply crates/superposition_types/src/database/schema.patch
diesel print-schema --schema superposition > crates/superposition_types/src/database/superposition_schema.rs
git apply crates/superposition_types/src/database/superposition_schema.patch
git apply crates/superposition_types/src/database/schema-timestamp-migration.patch
OS := $(shell uname -s)
ifeq ($(OS),Darwin)
LIB_EXTENSION := dylib
else ifeq ($(OS),Linux)
LIB_EXTENSION := so
else ifneq (,$(findstring MINGW,$(OS)))
LIB_EXTENSION := dll
else ifneq (,$(findstring CYGWIN,$(OS)))
LIB_EXTENSION := dll
else
$(error Unsupported OS type: $(OS))
endif
uniffi-bindings:
cargo build --package superposition_core --lib --release
cargo run --bin uniffi-bindgen generate --library $(CARGO_TARGET_DIR)/release/libsuperposition_core.$(LIB_EXTENSION) --language kotlin --out-dir clients/java/bindings/src/main/kotlin
cargo run --bin uniffi-bindgen generate --library $(CARGO_TARGET_DIR)/release/libsuperposition_core.$(LIB_EXTENSION) --language python --out-dir clients/python/bindings/superposition_bindings
git apply uniffi/patches/*.patch
provider-template: setup superposition
@$(CARGO_TARGET_DIR)/debug/superposition &
@echo "Awaiting superposition boot..."
@curl --silent --retry 10 \
--connect-timeout 2 \
--retry-all-errors \
'http://localhost:8080/health' 2>&1 > /dev/null
test-js-provider: provider-template
cd clients/javascript/provider-sdk-tests && npm ci
bash ./scripts/setup_provider_binaries.sh js
node clients/javascript/provider-sdk-tests/index.js
-@pkill -f $(CARGO_TARGET_DIR)/debug/superposition
test-py-provider: provider-template
bash ./scripts/setup_provider_binaries.sh py
cd clients/python/provider-sdk-tests && VERSION=1.0.0 uv sync
VERSION=1.0.0 uv run --directory clients/python/provider-sdk-tests python main.py
-@pkill -f $(CARGO_TARGET_DIR)/debug/superposition
test-kotlin-provider: provider-template
bash ./scripts/setup_provider_binaries.sh kotlin
cd clients/java && ./gradlew :provider-sdk-tests:run
-@pkill -f $(CARGO_TARGET_DIR)/debug/superposition
test-rust-provider: provider-template
cargo test --package superposition_provider --test integration_test -- --nocapture --ignored
-@pkill -f $(CARGO_TARGET_DIR)/debug/superposition