-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
justfile
195 lines (155 loc) · 6.82 KB
/
justfile
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
set positional-arguments := true
set shell := ["bash", "-c"]
default:
just --list
build:
cargo build --release --all-targets
audit:
cargo audit
audit-fix:
cargo audit fix
format:
cargo fmt --check
npx --yes prettier --check .
! command -v nix || nix fmt -- --check .
alias fmt := format
fix:
cargo clippy --all-targets --no-deps --fix --allow-no-vcs
cargo fmt
just fix-format
! command -v nix || nix fmt
fix-format:
npx --yes prettier --write .
run-local-with-shell:
#!/usr/bin/env bash
cargo run --bin custom-connector | ts "custom-connector:" &
OTLP_ENDPOINT=http://localhost:4317 \
cargo run --bin dev-auth-webhook | ts "dev-auth-webhook:" &
RUST_LOG=DEBUG cargo run --bin ddn-engine-local-dev -- \
--otlp-endpoint http://localhost:4317 \
--authn-config-path static/auth/auth_config.json \
--metadata-path static/sample-schema.json \
--expose-internal-errors | ts "engine: " &
wait
# start all the docker deps for running tests (not engine)
start-docker-test-deps:
# start connectors and wait for health
docker compose -f ci.docker-compose.yaml up --wait auth_hook postgres postgres_connector custom_connector custom_connector_no_relationships custom_connector_ndc_v01
# start all the docker run time deps for the engine
start-docker-run-deps:
# start auth_hook and jaeger
docker compose up --wait jaeger
# starts engine locally using dependencies from docker compose
start-engine:
docker compose up --wait postgres postgres_connector auth_hook jaeger
METADATA_PATH=static/docker_schema.json \
AUTHN_CONFIG_PATH=static/auth/auth_config.json \
OTLP_ENDPOINT=http://localhost:4317 \
cargo run --bin ddn-engine-local-dev
# pull / build all docker deps
docker-refresh: stop-docker
docker compose -f ci.docker-compose.yaml pull postgres_connector
docker compose -f ci.docker-compose.yaml build custom_connector
alias refresh-docker := docker-refresh
# stop all the docker deps
stop-docker:
docker compose -f ci.docker-compose.yaml down -v
docker compose down -v
# run the tests using local engine (once)
test *ARGS: start-docker-test-deps
#!/usr/bin/env bash
if command -v cargo-nextest; then
COMMAND=(cargo nextest run)
else
COMMAND=(cargo test)
fi
COMMAND+=(--no-fail-fast "$@")
echo "${COMMAND[*]}"
"${COMMAND[@]}"
# run a watch process that runs the tests locally
watch: start-docker-test-deps start-docker-run-deps
RUST_LOG=DEBUG \
cargo watch -i "**/*.snap.new" \
-x 'nextest run --no-fail-fast' \
-x 'clippy --no-deps' \
-x 'run --bin ddn-engine-local-dev -- \
--otlp-endpoint http://localhost:4317 \
--authn-config-path static/auth/auth_config.json \
--metadata-path static/sample-schema.json \
--expose-internal-errors'
# check the code is fine
lint:
cargo clippy --all-targets --no-deps
! command -v nix || nix flake check
# ensure we don't have unused dependencies:
machete:
cargo machete --with-metadata
# update golden tests
update-golden-files: start-docker-test-deps
UPDATE_GOLDENFILES=1 just test
just fix-format
update-custom-connector-schema-in-test-metadata:
docker compose -f ci.docker-compose.yaml up --build --wait custom_connector custom_connector_no_relationships
just update-schema-in-test-metadata "8102" "v0.2"
just update-schema-in-test-metadata "8103" "v0.2"
docker compose -f ci.docker-compose.yaml down
update-postgres-schema-in-test-metadata:
docker compose -f ci.docker-compose.yaml up --build --wait postgres postgres_connector
just update-schema-in-test-metadata "8080" "v0.1"
docker compose -f ci.docker-compose.yaml down
update-schema-in-test-metadata PORT NDC_VERSION: && fix-format
#!/usr/bin/env bash
set -e
capabilities_file=$(mktemp)
curl http://localhost:{{ PORT }}/capabilities | jq > $capabilities_file
trap 'rm -f "$capabilities_file"' EXIT
schema_file=$(mktemp)
curl http://localhost:{{ PORT }}/schema | jq > $schema_file
trap 'rm -f "$schema_file"' EXIT
ndc_version="{{ NDC_VERSION }}"
# Should only be tests that actually talk to the running connector and therefore must be up to date
test_directories=(./crates/engine/tests/execute)
find "${test_directories[@]}" -name '*.json' -print0 |
while IFS= read -r -d '' file; do
# Check if the file actually contains a custom connector DataConnectorLink
if jq -e '
(. | type == "object") and has("subgraphs") and (.subgraphs | length > 0) and (.subgraphs[] | has("objects") and (.objects | length > 0))
and any(.subgraphs[].objects[]; .kind == "DataConnectorLink" and .definition.url.singleUrl.value == "http://localhost:{{ PORT }}")' "$file" >/dev/null; then
# Update its schema, capabilities and version
jq --slurpfile newCapabilities "$capabilities_file" --slurpfile newSchema "$schema_file" --arg ndcVersion "$ndc_version" '
(.subgraphs[].objects[] | select(.kind == "DataConnectorLink" and .definition.url.singleUrl.value == "http://localhost:{{ PORT }}").definition.schema)
|= (.capabilities = $newCapabilities[0] | .schema = $newSchema[0] | .version = $ndcVersion)
' $file \
| sponge $file
echo "Updated $file"
else
echo "Skipping $file: Does not appear to be a metadata file with a matching connector"
fi
done
# ensures metadata objects in test json have their properties ordered as kind, version, then definition
reorder-json-in-test-metadata: && fix-format
#!/usr/bin/env bash
set -e
# Should only be folders that contain json metadata tests
test_directories=(./crates/engine/tests/execute ./crates/metadata-resolve/tests)
find "${test_directories[@]}" -name '*.json' -print0 |
while IFS= read -r -d '' file; do
# Check if the file actually contains metadata
if jq -e '(. | type == "object") and has("subgraphs") and (.subgraphs | length > 0) and (.subgraphs[] | has("objects") and (.objects | length > 0))' "$file" >/dev/null; then
# Reformat each metadata object so that kind, version, and definition properties come first
jq '.subgraphs[].objects |= map({ kind: .kind, version: .version, definition: .definition } + .)' $file \
| sponge $file
echo "Updated $file"
else
echo "Skipping $file: Does not appear to be a metadata file"
fi
done
# run the engine using schema from tests
run METADATA_PATH="static/sample-schema.json": start-docker-test-deps start-docker-run-deps
RUST_LOG=DEBUG cargo run --bin ddn-engine-local-dev -- \
--otlp-endpoint http://localhost:4317 \
--authn-config-path static/auth/auth_config.json \
--metadata-path {{ METADATA_PATH }} \
--expose-internal-errors \
--export-traces-stdout \
--unstable-feature enable-open-dd-pipeline-for-graphql