From 14190d610db34aecfa96231ac6c6261f54d1ed1e Mon Sep 17 00:00:00 2001 From: vindard <17693119+vindard@users.noreply.github.com> Date: Thu, 23 Nov 2023 14:19:56 -0400 Subject: [PATCH] build: add test-integration github action --- .github/workflows/integration.yml | 23 +++++++++++ bats/ci_start_integration_deps.sh | 69 +++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 .github/workflows/integration.yml create mode 100755 bats/ci_start_integration_deps.sh diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml new file mode 100644 index 00000000000..f061296dc9a --- /dev/null +++ b/.github/workflows/integration.yml @@ -0,0 +1,23 @@ +name: "Integration test" + +on: + pull_request: + branches: [main] + +jobs: + integration: + name: Integration 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 ./bats/ci_start_integration_deps.sh + - name: Run integration tests + run: | + nix develop -c buck2 test //core/api:test-integration diff --git a/bats/ci_start_integration_deps.sh b/bats/ci_start_integration_deps.sh new file mode 100755 index 00000000000..2aa9ff5a1da --- /dev/null +++ b/bats/ci_start_integration_deps.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +export REPO_ROOT=$(git rev-parse --show-toplevel) + +setup_deps() { + buck2 run //dev:up > "${REPO_ROOT}/bats/.e2e-tilt.log" 2>&1 & + await_api_is_up + await_api_keys_is_up +} + +await_api_is_up() { + exec_globals() { + raw_query="query Globals { + globals { + network + nodesIds + } + }" + query=$(echo $raw_query | tr '\n' ' ' | sed 's/"/\\"/g') + + OATHKEEPER_PROXY="localhost:4455" + gql_route="graphql" + + curl -s \ + -X POST \ + -H "Content-Type: application/json" \ + -d "{\"query\": \"$query\"}" \ + "${OATHKEEPER_PROXY}/${gql_route}" + } + + server_is_up() { + network="$(exec_globals | jq -r '.data.globals.network')" + [[ "${network}" = "regtest" ]] || return 1 + } + + retry 300 1 server_is_up || exit 1 +} + +await_api_keys_is_up() { + api_keys_is_up() { + curl localhost:5397/auth/check > /dev/null 2>&1 || return 1 + } + + retry 300 1 api_keys_is_up +} + +retry() { + local attempts=$1 + shift + local delay=$1 + shift + local i + + for ((i = 0; i < attempts; i++)); do + "$@" + run_status="$?" + echo "Status: $run_status; i: $i" > "${REPO_ROOT}/bats/output.log" 2>&1 & + + if [[ "$run_status" -eq 0 ]]; then + return 0 + fi + sleep "$delay" + done + + echo "Command \"$*\" failed $attempts times." + exit 1 +} + +setup_deps