graphql-engine/v3/justfile

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

181 lines
6.2 KiB
Makefile
Raw Normal View History

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
Run `cargo fmt` in CI (#431) <!-- Thank you for submitting this PR! :) --> ## Description When I run `cargo fmt` on my branches, it makes more diff than I want. This PR fixes that by adding `just format` / `just fmt`, and adding it to a CI job. <!-- Questions to consider answering: 1. What user-facing changes are being made? 2. What are issues related to this PR? (Consider adding `(close #<issue-no>)` to the PR title) 3. What is the conceptual design behind this PR? 4. How can this PR be tested/verified? 5. Does the PR have limitations? 6. Does the PR introduce breaking changes? --> ## Changelog - Add a changelog entry (in the "Changelog entry" section below) if the changes in this PR have any user-facing impact. See [changelog guide](https://github.com/hasura/graphql-engine-mono/wiki/Changelog-Guide). - If no changelog is required ignore/remove this section and add a `no-changelog-required` label to the PR. ### Product _(Select all products this will be available in)_ - [ ] community-edition - [ ] cloud <!-- product : end : DO NOT REMOVE --> ### Type <!-- See changelog structure: https://github.com/hasura/graphql-engine-mono/wiki/Changelog-Guide#structure-of-our-changelog --> _(Select only one. In case of multiple, choose the most appropriate)_ - [ ] highlight - [ ] enhancement - [ ] bugfix - [ ] behaviour-change - [ ] performance-enhancement - [ ] security-fix <!-- type : end : DO NOT REMOVE --> ### Changelog entry <!-- - Add a user understandable changelog entry - Include all details needed to understand the change. Try including links to docs or issues if relevant - For Highlights start with a H4 heading (#### <entry title>) - Get the changelog entry reviewed by your team --> _Replace with changelog entry_ <!-- changelog-entry : end : DO NOT REMOVE --> <!-- changelog : end : DO NOT REMOVE --> V3_GIT_ORIGIN_REV_ID: e31e352f27b9ad0129c3759fead051b1a8d86758
2024-04-02 18:08:38 +03:00
format:
cargo fmt --check
npx --yes prettier --check .
! command -v nix || nix fmt -- --check .
Run `cargo fmt` in CI (#431) <!-- Thank you for submitting this PR! :) --> ## Description When I run `cargo fmt` on my branches, it makes more diff than I want. This PR fixes that by adding `just format` / `just fmt`, and adding it to a CI job. <!-- Questions to consider answering: 1. What user-facing changes are being made? 2. What are issues related to this PR? (Consider adding `(close #<issue-no>)` to the PR title) 3. What is the conceptual design behind this PR? 4. How can this PR be tested/verified? 5. Does the PR have limitations? 6. Does the PR introduce breaking changes? --> ## Changelog - Add a changelog entry (in the "Changelog entry" section below) if the changes in this PR have any user-facing impact. See [changelog guide](https://github.com/hasura/graphql-engine-mono/wiki/Changelog-Guide). - If no changelog is required ignore/remove this section and add a `no-changelog-required` label to the PR. ### Product _(Select all products this will be available in)_ - [ ] community-edition - [ ] cloud <!-- product : end : DO NOT REMOVE --> ### Type <!-- See changelog structure: https://github.com/hasura/graphql-engine-mono/wiki/Changelog-Guide#structure-of-our-changelog --> _(Select only one. In case of multiple, choose the most appropriate)_ - [ ] highlight - [ ] enhancement - [ ] bugfix - [ ] behaviour-change - [ ] performance-enhancement - [ ] security-fix <!-- type : end : DO NOT REMOVE --> ### Changelog entry <!-- - Add a user understandable changelog entry - Include all details needed to understand the change. Try including links to docs or issues if relevant - For Highlights start with a H4 heading (#### <entry title>) - Get the changelog entry reviewed by your team --> _Replace with changelog entry_ <!-- changelog-entry : end : DO NOT REMOVE --> <!-- changelog : end : DO NOT REMOVE --> V3_GIT_ORIGIN_REV_ID: e31e352f27b9ad0129c3759fead051b1a8d86758
2024-04-02 18:08:38 +03:00
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 engine -- \
--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 postgres postgres_connector custom_connector custom_connector_ndc_v01 auth_hook
# start all the docker run time deps for the engine
start-docker-run-deps:
# start auth_hook and jaeger
docker compose up --wait auth_hook jaeger
# 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 test \
-x 'clippy --no-deps' \
-x 'run --bin engine -- \
--otlp-endpoint http://localhost:4317 \
--authn-config-path static/auth/auth_config.json \
--metadata-path static/sample-schema.json \
--unstable-feature enable-subscriptions \
--unstable-feature enable-json-api \
--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 cargo test
just fix-format
update-custom-connector-schema-in-test-metadata:
docker compose -f ci.docker-compose.yaml up --build --wait custom_connector
just update-schema-in-test-metadata "8102" "v0.2"
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"
update-schema-in-test-metadata PORT NDC_VERSION: && fix-format
#!/usr/bin/env bash
set -e
new_capabilities=$(curl http://localhost:{{ PORT }}/capabilities | jq)
new_schema=$(curl http://localhost:{{ PORT }}/schema | jq)
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 --argjson newCapabilities "$new_capabilities" --argjson newSchema "$new_schema" --arg ndcVersion "$ndc_version" '
(.subgraphs[].objects[] | select(.kind == "DataConnectorLink" and .definition.url.singleUrl.value == "http://localhost:{{ PORT }}").definition.schema)
|= (.capabilities = $newCapabilities | .schema = $newSchema | .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
docker compose -f ci.docker-compose.yaml down
# 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 engine -- \
--otlp-endpoint http://localhost:4317 \
--authn-config-path static/auth/auth_config.json \
--metadata-path {{ METADATA_PATH }} \
--unstable-feature enable-subscriptions \
--unstable-feature enable-json-api \
--expose-internal-errors