Skip to content

Commit 61965f9

Browse files
Filter for workflows that have started after the trigger time
1 parent acf30ba commit 61965f9

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

.github/workflows/test_reusable_workflow.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ jobs:
5656

5757
run: |
5858
echo "Triggering ${{ inputs.workflow_file }} in ${{ inputs.target_repo }} on ref ${{ inputs.ref }}..."
59+
export TRIGGER_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
60+
echo "TRIGGER_TIME=$TRIGGER_TIME" >> $GITHUB_ENV
5961
6062
curl -s -o /dev/null -w "%{http_code}" -X POST \
6163
-H "Accept: application/vnd.github+json" \
@@ -79,15 +81,21 @@ jobs:
7981
echo "Waiting up to $WAIT_TIMEOUT seconds for workflow run to appear..."
8082
8183
WAIT_ITER=$((WAIT_TIMEOUT / POLL_FREQ))
82-
sleep 10 # Sleep for a while to get the new workflow started
84+
sleep 3 # Sleep for a while to get the new workflow started
8385
for ((i=0; i<WAIT_ITER; i++)); do
8486
set +e
8587
8688
RESPONSE=$(curl -s -H "Authorization: Bearer $GH_TOKEN" \
8789
"https://api.github.com/repos/$OWNER/$REPO/actions/workflows/$WORKFLOW_FILE/runs?branch=$REF&event=workflow_dispatch")
8890
89-
RUN_ID=$(echo "$RESPONSE" | jq -r '.workflow_runs | sort_by(.created_at) | last | .id' 2>/dev/null)
90-
91+
RUN_ID=$(echo "$RESPONSE" | jq -r --arg trigger_time "$TRIGGER_TIME" '
92+
if (.workflow_runs | type == "array") then
93+
.workflow_runs
94+
| map(select(.created_at > $trigger_time))
95+
| sort_by(.created_at)
96+
| last
97+
| .id
98+
else empty end')
9199
set -e
92100
93101
if [[ "$RUN_ID" != "null" && -n "$RUN_ID" ]]; then

0 commit comments

Comments
 (0)