Skip to content

Commit

Permalink
build: add test-integration github action
Browse files Browse the repository at this point in the history
  • Loading branch information
vindard committed Nov 23, 2023
1 parent 1512272 commit 892ecbf
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -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
76 changes: 76 additions & 0 deletions bats/ci_start_integration_deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/bash

export REPO_ROOT=$(git rev-parse --show-toplevel)

setup_deps() {
echo "Starting dev dependencies"
buck2 run //dev:up > "${REPO_ROOT}/bats/.e2e-tilt.log" 2>&1 &

echo "Waiting for api server..."
await_api_is_up

echo "Waiting for api-keys server..."
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 150 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 150 1 api_keys_is_up
}

retry() {
local attempts=$1
shift
local delay=$1
shift
local i

echo "Running: $@"
for ((i = 0; i < attempts; i++)); do
"$@"
run_status="$?"
echo "Attempt #: $i"

if [[ "$run_status" -eq 0 ]]; then
echo "Success"
return 0
fi
sleep "$delay"
done

echo "Command \"$*\" failed $attempts times."
exit 1
}

setup_deps
1 change: 1 addition & 0 deletions bats/output.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Status: 1; i: 13

0 comments on commit 892ecbf

Please sign in to comment.