Add better logging

This commit is contained in:
Kamil Chodoła
2023-04-26 17:50:27 +02:00
committed by GitHub
parent b43d4b4ab9
commit 93c577ffd2

View File

@@ -16,28 +16,36 @@ else
REF="refs/heads/$REF"
fi
echo " Workflow ID: $workflow_id"
echo " Organization: ${ORG_NAME}"
echo " Repository: ${REPO_NAME}"
echo " Reference: $REF"
echo " Maximum wait time: ${max_wait_minutes} minutes"
# Wait for the workflow to be triggered
echo "⏳ Waiting for the workflow to be triggered..."
while true; do
run_id=$(curl -s -H "Accept: application/vnd.github+json" -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/${ORG_NAME}/${REPO_NAME}/actions/workflows/${workflow_id}/runs" | \
jq -r --arg ref "$(echo "$REF" | sed 's/refs\/heads\///')" --arg current_time "$current_time" \
'.workflow_runs[] | select(.head_branch == $ref and .created_at >= $current_time) | .id')
if [ -n "$run_id" ]; then
echo "🎉 Workflow triggered! Run ID: $run_id"
break
fi
# Increment the counter and check if the maximum waiting time is reached
counter=$((counter + 1))
if [ $((counter * 30)) -ge $((max_wait_minutes * 60)) ]; then
echo "Maximum waiting time for the workflow to be triggered has been reached. Exiting."
echo "Maximum waiting time for the workflow to be triggered has been reached. Exiting."
exit 1
fi
echo "Waiting for the workflow to be triggered..."
sleep 30
done
# Wait for the triggered workflow to complete and check its conclusion
echo "⌛ Waiting for the workflow to complete..."
while true; do
run_data=$(curl -s -H "Accept: application/vnd.github+json" -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/${ORG_NAME}/${REPO_NAME}/actions/runs/$run_id")
@@ -46,13 +54,12 @@ while true; do
if [ "$status" = "completed" ]; then
conclusion=$(echo "$run_data" | jq -r '.conclusion')
if [ "$conclusion" != "success" ]; then
echo "The workflow has not completed successfully. Exiting."
echo "The workflow has not completed successfully. Exiting."
exit 1
else
echo "The workflow completed successfully! Exiting."
echo "The workflow completed successfully! Exiting."
break
fi
fi
echo "Waiting for the workflow to complete..."
sleep 30
done