From 310d1e6b2d49127e969b6d90812b1ca9969cde26 Mon Sep 17 00:00:00 2001 From: Toby Sullivan Date: Mon, 11 Apr 2022 12:52:50 -0700 Subject: [PATCH] Filter runs locally instead of via API query param The Github API can return stale results when the event param is used. --- entrypoint.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 372a1c0..ffb2f91 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -21,9 +21,15 @@ function find_workflow { while [[ true ]] do counter=$(( $counter + 1 )) - workflow=$(curl -s "https://api.github.com/repos/${INPUT_OWNER}/${INPUT_REPO}/actions/runs?event=repository_dispatch" \ + all_runs=$(curl -s "https://api.github.com/repos/${INPUT_OWNER}/${INPUT_REPO}/actions/runs" \ -H "Accept: application/vnd.github.v3+json" \ - -H "Authorization: Bearer ${INPUT_TOKEN}" | jq '.workflow_runs[0]') + -H "Authorization: Bearer ${INPUT_TOKEN}" | jq '.workflow_runs' ) + + # Github's API is eventually consistent when filtering by event. The API + # can return stale results when using the `event` filter on the API query. + # Filter runs locally to work around this. + dispatch_runs=$( echo $(echo $all_runs | jq 'map(select(.event=="repository_dispatch"))') ) + workflow=$( echo $(echo $dispatch_runs | jq '.[0]') ) wtime=$( echo $(echo $workflow | jq '.created_at') | cut -c13-20 ) atime=$(date -u +%T)