From eb2ca4fb36a6c716ff8d0de879c7417c4fcca150 Mon Sep 17 00:00:00 2001 From: bodymindarts Date: Thu, 9 Nov 2023 09:59:53 +0100 Subject: [PATCH] ci: top level bats --- .github/workflows/bats.yml | 22 ++++++++++++++++++++++ bats/ci_setup_suite.bash | 20 ++++++++++++++++++++ bats/core/api/public.bats | 9 --------- dev/Tiltfile | 4 ++-- dev/tilt.bzl | 2 +- toolchains/workspace-pnpm/macros.bzl | 4 ++-- 6 files changed, 47 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/bats.yml create mode 100644 bats/ci_setup_suite.bash diff --git a/.github/workflows/bats.yml b/.github/workflows/bats.yml new file mode 100644 index 0000000000..70cb07e7c4 --- /dev/null +++ b/.github/workflows/bats.yml @@ -0,0 +1,22 @@ +name: "Bats test" + +on: + pull_request: + branches: [main] + +jobs: + integration: + name: Bats tests + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - uses: actions/checkout@v3 + - name: Install Nix + uses: DeterminateSystems/nix-installer-action@v4 + - name: Run the Magic Nix Cache + uses: DeterminateSystems/magic-nix-cache-action@v2 + - name: Buck2 build + run: nix develop -c buck2 build core/api core/api-keys apps/dashboard apps/consent + - name: Run bats tests + run: | + nix develop -c bats --setup-suite-file bats/ci_setup_suite.bash -t bats/core/api diff --git a/bats/ci_setup_suite.bash b/bats/ci_setup_suite.bash new file mode 100644 index 0000000000..03f2312466 --- /dev/null +++ b/bats/ci_setup_suite.bash @@ -0,0 +1,20 @@ +#!/bin/bash + +export REPO_ROOT=$(git rev-parse --show-toplevel) +source "${REPO_ROOT}/bats/helpers/setup-and-teardown.bash" + +TILT_PID_FILE=$REPO_ROOT/bats/.tilt_pid + +setup_suite() { + background buck2 run //dev:up -- --bats=True > "${REPO_ROOT}/bats/.e2e-tilt.log" + echo $! > "$TILT_PID_FILE" + await_api_is_up +} + +teardown_suite() { + if [[ -f "$TILT_PID_FILE" ]]; then + kill "$(cat "$TILT_PID_FILE")" > /dev/null || true + fi + + buck2 run //dev:down +} diff --git a/bats/core/api/public.bats b/bats/core/api/public.bats index 0e1ac49508..fedee39b5e 100644 --- a/bats/core/api/public.bats +++ b/bats/core/api/public.bats @@ -2,15 +2,6 @@ load "../../helpers/_common.bash" -setup_file() { - start_services "api" - await_api_is_up -} - -teardown_file() { - stop_services -} - @test "public: can query globals" { exec_graphql 'anon' 'globals' network="$(graphql_output '.data.globals.network')" diff --git a/dev/Tiltfile b/dev/Tiltfile index b47dda8fc1..8d8aad6e56 100644 --- a/dev/Tiltfile +++ b/dev/Tiltfile @@ -1,8 +1,8 @@ config.define_string_list("test") -config.define_string_list("to-run", args = True) +config.define_bool("bats") cfg = config.parse() -is_ci=("ci" in sys.argv) +is_ci=("ci" in sys.argv) or cfg.get("bats", False) def _buck2_dep_inputs(target): cmd = [ diff --git a/dev/tilt.bzl b/dev/tilt.bzl index 9b66ea3e82..0305c605f3 100644 --- a/dev/tilt.bzl +++ b/dev/tilt.bzl @@ -32,7 +32,7 @@ subcmd="$1" tiltfile="$2" args=("${@:3}") -tilt "$subcmd" --file "$rootpath"/"$tiltfile" -- "${args[@]}" +exec tilt "$subcmd" --file "$rootpath"/"$tiltfile" -- "${args[@]}" """, is_executable = True) run_cmd_args = cmd_args([ diff --git a/toolchains/workspace-pnpm/macros.bzl b/toolchains/workspace-pnpm/macros.bzl index 75a2cf794d..d3af87e16b 100644 --- a/toolchains/workspace-pnpm/macros.bzl +++ b/toolchains/workspace-pnpm/macros.bzl @@ -899,7 +899,7 @@ cd "$rootpath/$npm_package_path" if [ "$install_node_modules" = "True" ]; then pnpm install fi -pnpm run --report-summary "$npm_run_command" +exec pnpm run --report-summary "$npm_run_command" """, is_executable = True) args = cmd_args([script, str(ctx.attrs.local_node_modules), ctx.label.package, ctx.attrs.command]) args.hidden([ctx.attrs.deps]) @@ -927,7 +927,7 @@ cd "$rootpath/$npm_package_path" if [ "$install_node_modules" = "True" ]; then pnpm install fi -pnpm run --report-summary "$npm_run_command" +exec pnpm run --report-summary "$npm_run_command" """, is_executable = True) args = cmd_args([script, str(ctx.attrs.local_node_modules), ctx.label.package, ctx.attrs.command]) args.hidden([ctx.attrs.deps])