From e075f5c5f19e911b1c0babbc0fde688cf958ff9d Mon Sep 17 00:00:00 2001 From: Jeffrey Limnardy Date: Mon, 9 Sep 2024 19:21:14 +0200 Subject: [PATCH] chore: Fix rerun failing workflow (#1418) --- hack/await_workflow.sh | 47 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/hack/await_workflow.sh b/hack/await_workflow.sh index 824883fc2..0b04a55cd 100755 --- a/hack/await_workflow.sh +++ b/hack/await_workflow.sh @@ -9,12 +9,13 @@ set -o pipefail # prevents errors in a pipeline from being masked # Variables (you need to set these) REPO_OWNER="kyma-project" REPO_NAME="telemetry-manager" -WORKFLOW_NAME="Build Image" +CHECK_NAME="Build-Image-Success" -# retry until workflow conclusion is success and status is completed +# retry until check is found and status is completed # timeout after 15 minutes TIMEOUT=900 +QUERY_INTERVAL=10 START_TIME=$SECONDS @@ -22,48 +23,49 @@ found=false status="" conclusion="" -until [[ $status == "completed" ]]; do +until [[ $found == true && $status == "completed" ]]; do # Wait for timeout if (( SECONDS - START_TIME > TIMEOUT )); then - echo "Timeout reached: Workflow not found within $(( TIMEOUT/60 )) minutes" + echo "Timeout reached: Check not finished within $(( TIMEOUT/60 )) minutes" exit 1 fi - echo "Waiting for workflow: $WORKFLOW_NAME" + echo "Waiting for check: $CHECK_NAME" - # Get the latest workflow run status + # Get the latest check run status response=$(curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer $GITHUB_TOKEN" \ -H "X-GitHub-Api-Version: 2022-11-28" \ - https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/actions/runs) + https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/commits/$COMMIT_SHA/check-runs) - # Check if .workflow_runs exists and is not null - if [ "$(echo "$response" | jq -r '.workflow_runs')" == "null" ]; then + # Check if .check_runs exists and is not null + if [ "$(echo "$response" | jq -r '.check_runs')" == "null" ]; then echo "$response" exit 1 fi # Extract all head_sha and status from response and put it into an array - workflows=$(echo $response | jq -c '.workflow_runs[] | {name, head_sha, status, conclusion}') + checks=$(echo "$response" | jq -c '.check_runs[] | {name, head_sha, status, conclusion}') # Iterate over the JSON objects - while IFS= read -r workflow; do - workflow_name=$(echo "$workflow" | jq -r '.name') - head_sha=$(echo "$workflow" | jq -r '.head_sha') - status=$(echo "$workflow" | jq -r '.status') - conclusion=$(echo "$workflow" | jq -r '.conclusion') + while IFS= read -r check; do + check_name=$(echo "$check" | jq -r '.name') + head_sha=$(echo "$check" | jq -r '.head_sha') + status=$(echo "$check" | jq -r '.status') + conclusion=$(echo "$check" | jq -r '.conclusion') - if [[ "$head_sha" == "$COMMIT_SHA" && "$workflow_name" == "$WORKFLOW_NAME" ]]; then + if [[ "$head_sha" == "$COMMIT_SHA" && "$check_name" == "$CHECK_NAME" ]]; then found=true break fi - done <<< "$workflows" + done <<< "$checks" if [ "$found" = false ]; then - echo "Workflow not found" - exit 1 + echo "Check not yet found." + sleep $QUERY_INTERVAL + continue fi # Output the results @@ -72,12 +74,11 @@ until [[ $status == "completed" ]]; do echo "Conclusion: $conclusion" echo "" - sleep 10 done -if [ $conclusion != "success" ]; then - echo "Workflow $status with conclusion: $conclusion" +if [ "$conclusion" != "success" ]; then + echo "Check $status with conclusion: $conclusion" exit 1 fi -echo "Workflow '$WORKFLOW_NAME' $status with conclusion: $conclusion" \ No newline at end of file +echo "Check '$CHECK_NAME' $status with conclusion: $conclusion" \ No newline at end of file