From 96c47bbd0f945a8fb4a06cc75c5dfa01377334d1 Mon Sep 17 00:00:00 2001 From: Arvin <17693119+vindard@users.noreply.github.com> Date: Wed, 7 Feb 2024 12:25:18 -0400 Subject: [PATCH] ci: wrap tilt ci tests in script to handle logs (#3933) * ci: wrap tilt ci tests in script to handle logs * ci: add tiltfile upload to integration gh action * ci: handle ci-only changes in integration action * refactor: rename test resources in tilt for easier filtering * chore: rename integration action test step --- .github/workflows/buck2-test.yaml | 2 ++ .github/workflows/integration-test.yml | 17 ++++++++++++++--- ci/apps/app-template.lib.yml | 2 +- ci/core/pipeline.yml | 2 +- dev/Tiltfile | 20 ++++++++++---------- dev/bin/tilt-ci.sh | 20 ++++++++++++++++++++ 6 files changed, 48 insertions(+), 15 deletions(-) create mode 100755 dev/bin/tilt-ci.sh diff --git a/.github/workflows/buck2-test.yaml b/.github/workflows/buck2-test.yaml index 95b0afdedc..445260ddad 100644 --- a/.github/workflows/buck2-test.yaml +++ b/.github/workflows/buck2-test.yaml @@ -27,6 +27,8 @@ jobs: LABELS=($(jq -r '.[]' < labels.json)) if [ ${#LABELS[@]} -eq 0 ]; then LABELS=("${DEFAULT_LABELS[@]}") + elif [ ${#LABELS[@]} -eq 1 ] && [ "${LABELS[0]}" = "ci" ]; then + LABELS=("${DEFAULT_LABELS[@]}") fi for LABEL in "${LABELS[@]}"; do diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index c0d7a36383..cebb73bd6f 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -31,18 +31,29 @@ jobs: LABELS=($(jq -r '.[]' < labels.json)) if [ ${#LABELS[@]} -eq 0 ]; then LABELS=("${DEFAULT_LABELS[@]}") + elif [ ${#LABELS[@]} -eq 1 ] && [ "${LABELS[0]}" = "ci" ]; then + LABELS=("${DEFAULT_LABELS[@]}") fi for LABEL in "${LABELS[@]}"; do case "$LABEL" in dashboard|consent|pay|core|admin-panel) - ARGS+=" --test $LABEL" + ARGS+=" $LABEL" ;; esac done echo "Prepared args: $ARGS" echo "args=$ARGS" >> "$GITHUB_OUTPUT" - - name: Tilt CI + - name: Build/start deps and run tests via tilt if: steps.prepare_args.outputs.args != '' - run: nix develop -c xvfb-run tilt --file dev/Tiltfile ci -- ${{ steps.prepare_args.outputs.args }} + run: nix develop -c xvfb-run ./dev/bin/tilt-ci.sh ${{ steps.prepare_args.outputs.args }} + - name: Rename Tilt log + if: always() + run: mv dev/.e2e-tilt.log dev/e2e-tilt.log + - name: Upload Tilt log + if: always() + uses: actions/upload-artifact@v2 + with: + name: Tilt log + path: dev/e2e-tilt.log diff --git a/ci/apps/app-template.lib.yml b/ci/apps/app-template.lib.yml index 544d9ed808..a0fb11c501 100644 --- a/ci/apps/app-template.lib.yml +++ b/ci/apps/app-template.lib.yml @@ -100,7 +100,7 @@ plan: #@ params["GOOGLE_CREDENTIALS"] = "((staging-gcp-creds.creds_json))" #@ params["SSH_PRIVATE_KEY"] = "((staging-ssh.ssh_private_key))" #@ params["SSH_PUB_KEY"] = "((staging-ssh.ssh_public_key))" -#@ params["CMD"] = "tilt --file dev/Tiltfile ci -- --test " + app +#@ params["CMD"] = "./dev/bin/tilt-ci.sh " + app name: #@ tilt_integration_test_name(app) serial: true plan: diff --git a/ci/core/pipeline.yml b/ci/core/pipeline.yml index 71cdbbe43b..cc8879cfec 100644 --- a/ci/core/pipeline.yml +++ b/ci/core/pipeline.yml @@ -121,7 +121,7 @@ jobs: - #@ build_edge_image(component) #@ end - #@ build_edge_image("api", sub_file = "migrate") - - #@ on_nix_host("core-bundle-integration-tests", "api", "tilt --file dev/Tiltfile ci -- --test core") + - #@ on_nix_host("core-bundle-integration-tests", "api", "./dev/bin/tilt-ci.sh core") - #@ on_nix_host("core-bundle-bats-tests", "api", "bats --setup-suite-file bats/ci_setup_suite.bash -t bats/core/**") - name: release-core-bundle plan: diff --git a/dev/Tiltfile b/dev/Tiltfile index 0e781310ea..2637b4c7f4 100644 --- a/dev/Tiltfile +++ b/dev/Tiltfile @@ -9,11 +9,11 @@ PAY_TEST_LABEL = "pay" ADMIN_PANEL_TEST_LABEL = "admin-panel" TEST_RESOURCES = { - CORE_TEST_LABEL: "api-test", - CONSENT_TEST_LABEL: "consent-test", - DASHBOARD_TEST_LABEL: "dashboard-test", - PAY_TEST_LABEL: "pay-test", - ADMIN_PANEL_TEST_LABEL: "admin-panel-test" + CORE_TEST_LABEL: "test-api", + CONSENT_TEST_LABEL: "test-consent", + DASHBOARD_TEST_LABEL: "test-dashboard", + PAY_TEST_LABEL: "test-pay", + ADMIN_PANEL_TEST_LABEL: "test-admin-panel" } is_ci=("ci" in sys.argv) or cfg.get("bats", False) @@ -148,7 +148,7 @@ local_resource( consent_test_target = "//apps/consent:test-integration" local_resource( - "consent-test", + "test-consent", labels = ["test"], auto_init = is_ci and CONSENT_TEST_LABEL in cfg.get("test", []), cmd = "buck2 test {}".format(consent_test_target), @@ -161,7 +161,7 @@ local_resource( dashboard_test_target = "//apps/dashboard:test-integration" local_resource( - "dashboard-test", + "test-dashboard", labels = ["test"], auto_init = is_ci and DASHBOARD_TEST_LABEL in cfg.get("test", []), cmd = "buck2 test {}".format(dashboard_test_target), @@ -174,7 +174,7 @@ local_resource( pay_test_target = "//apps/pay:test-integration" local_resource( - "pay-test", + "test-pay", labels = ["test"], auto_init = is_ci and PAY_TEST_LABEL in cfg.get("test", []), cmd = "buck2 test {}".format(pay_test_target), @@ -187,7 +187,7 @@ local_resource( admin_panel_test_target = "//apps/admin-panel:test-integration" local_resource( - "admin-panel-test", + "test-admin-panel", labels = ["test"], auto_init = is_ci and ADMIN_PANEL_TEST_LABEL in cfg.get("test", []), cmd = "buck2 test {}".format(admin_panel_test_target), @@ -592,7 +592,7 @@ for service in docker_groups["integration"]: api_test_target = "//core/api:test-integration" local_resource( - "api-test", + "test-api", labels = ["test"], auto_init = is_ci and CORE_TEST_LABEL in cfg.get("test", []), cmd = "buck2 test {}".format(api_test_target), diff --git a/dev/bin/tilt-ci.sh b/dev/bin/tilt-ci.sh new file mode 100755 index 0000000000..ae3b539c6f --- /dev/null +++ b/dev/bin/tilt-ci.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +REPO_ROOT=$(git rev-parse --show-toplevel) + +ARGS_STRING="" +for app in "$@"; do + ARGS_STRING+=" --test $app" +done +IFS=' ' read -r -a ARGS <<< "$ARGS_STRING" + +tilt --file "${REPO_ROOT}/dev/Tiltfile" ci -- "${ARGS[@]}" \ + | tee "${REPO_ROOT}/dev/.e2e-tilt.log" \ + | grep -- '^\s*test-.* │' +status=${PIPESTATUS[0]} + +if [[ $status -eq 0 ]]; then + echo "Tilt CI passed" +fi + +exit "$status"