mirror of
https://github.com/kamilchodola/wait-for-workflow-action.git
synced 2026-03-11 18:13:50 -05:00
Add better logging
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user