From 2036473ea3a9ae0a93a8d8e6cce65a297b5b4947 Mon Sep 17 00:00:00 2001 From: Friedrich Date: Tue, 12 Dec 2023 09:41:23 +0100 Subject: [PATCH] Refactor verify script (#313) * format and relplace backticks * add retry --- scripts/verify-status.sh | 45 ++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/scripts/verify-status.sh b/scripts/verify-status.sh index a9381f99..ae82c441 100755 --- a/scripts/verify-status.sh +++ b/scripts/verify-status.sh @@ -3,15 +3,42 @@ echo "Checking status of POST Jobs for Eventing-Manager" REF_NAME="${1:-"main"}" +TIMEOUT_TIME="${2:-120}" +INTERVAL_TIME="${3:-3}" + +# Generate job Status URL STATUS_URL="https://api.github.com/repos/kyma-project/eventing-manager/commits/${REF_NAME}/status" -fullstatus=`curl -L -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" ${STATUS_URL} | head -n 2 ` -sleep 10 -echo $fullstatus +function retry { + local start_time=$(date +%s) + # Get status result + local statusresult=$(curl -L -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" ${STATUS_URL}) + # Get overall state + local fullstatus=$(echo $statusresult | jq '.state' | tr -d '"') + + while [ "$fullstatus" == "pending" ]; do + current_time=$(date +%s) + elapsed_time=$((current_time - start_time)) + + if [ $elapsed_time -ge $TIMEOUT_TIME ]; then + echo "Timeout reached. Exiting." + exit 1 + fi + + echo "Status is 'pending'. Retrying in $interval seconds..." + sleep $INTERVAL_TIME + done + + # Show overall state to user + echo "$statusresult" -if [[ "$fullstatus" == *"success"* ]]; then - echo "All jobs succeeded" -else - echo "Jobs failed or pending - Check Prow status" - exit 1 -fi \ No newline at end of file + if [ "$fullstatus" == "success" ]; then + echo "Success!" + elif [ "$fullstatus" == "failed" ]; then + echo "Failure! Exiting with an error." + exit 1 + else + echo "Invalid result: $result" + exit 1 + fi +}