From d3f928a06210a30e938e5c6fa6da060dce044878 Mon Sep 17 00:00:00 2001 From: Ryan Lewis Date: Fri, 17 May 2024 17:22:11 -0700 Subject: [PATCH] wait for server shell script --- .github/workflows/ci-frontend-a11y.yml | 6 +++++- frontend/bin/wait-for-server.sh | 30 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 frontend/bin/wait-for-server.sh diff --git a/.github/workflows/ci-frontend-a11y.yml b/.github/workflows/ci-frontend-a11y.yml index 4347327f3..a9ac3f016 100644 --- a/.github/workflows/ci-frontend-a11y.yml +++ b/.github/workflows/ci-frontend-a11y.yml @@ -41,7 +41,11 @@ jobs: run: npm run dev & - name: Wait for server to be ready - run: npx wait-on http://localhost:3000 --timeout 60000 --log-level verbose + run: | + # Ensure the server wait script is executable + chmod +x ./wait-for-server.sh + ./wait-for-server.sh + shell: bash - name: Run pa11y-ci run: npm run test:pa11y 2>&1 | tee pa11y_output.txt diff --git a/frontend/bin/wait-for-server.sh b/frontend/bin/wait-for-server.sh new file mode 100644 index 000000000..bbaeeaee8 --- /dev/null +++ b/frontend/bin/wait-for-server.sh @@ -0,0 +1,30 @@ +# wait-for-server.sh + +#!/bin/bash +set -e + +# Color formatting for readability +GREEN='\033[0;32m' +RED='\033[0;31m' +NO_COLOR='\033[0m' + +MAX_WAIT_TIME=800 # seconds, adjust as necessary +WAIT_TIME=0 + +echo "Waiting for server to become ready..." + +# Use curl to check the server health endpoint +until curl --output /dev/null --silent --head --fail http://localhost:3000; +do + printf '.' + sleep 5 + + WAIT_TIME=$(($WAIT_TIME + 5)) + if [ $WAIT_TIME -gt $MAX_WAIT_TIME ] + then + echo -e "${RED}ERROR: Server did not become ready within ${MAX_WAIT_TIME} seconds.${NO_COLOR}" + exit 1 + fi +done + +echo -e "${GREEN}Server is ready after ~${WAIT_TIME} seconds.${NO_COLOR}"