Sync: wait only for the Diffinery runs a push started (#48)
Manual, scheduled and repository_dispatch runs on the pushed sha are listed as skipped instead of waited for, so a long dispatched run on main no longer holds main's sync queue. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ruyx3Qr4jYrZEpPi466deb
Canberk Demirci authored · GitHub committed signed1 parent f67cee5commit d4d788160e4a360f49b30b7d98b8c2157c9f0e4fBrowse files
1 file changed+10−4
modifiedscripts/diffinery-wait-runs.sh+10−4View file
| @@ -1,17 +1,22 @@ | ||
| 1 | 1 | #!/usr/bin/env bash |
| 2 | -# Waits for every Diffinery Actions run on a commit (including runs that other runs | |
| 3 | -# start, like workflow_run followers) and prints each run and job. Prints the logs of | |
| 4 | -# failed jobs and exits non-zero if any run did not succeed. | |
| 2 | +# Waits for every Diffinery Actions run that pushing a commit started (push and | |
| 3 | +# pull_request runs, and the workflow_run followers they start) and prints each run and | |
| 4 | +# job. Prints the logs of failed jobs and exits non-zero if any run did not succeed. | |
| 5 | +# Runs that someone started by hand or on a schedule while that commit was the branch | |
| 6 | +# head (workflow_dispatch, schedule, repository_dispatch) share its sha but not the push, | |
| 7 | +# so they are listed as skipped and not waited for. | |
| 5 | 8 | # |
| 6 | 9 | # Usage: DIFFINERY=https://diffinery.com TOKEN=... diffinery-wait-runs.sh owner/repo sha [minutes] |
| 7 | 10 | set -euo pipefail |
| 8 | 11 | repo=$1 sha=$2 minutes=${3:-60} |
| 9 | 12 | api() { curl -fsS --retry 3 "$DIFFINERY/api/v3/repos/$repo$1" -H "Authorization: Bearer $TOKEN"; } |
| 13 | +unrelated='["workflow_dispatch", "schedule", "repository_dispatch"]' | |
| 10 | 14 | |
| 11 | 15 | deadline=$(( $(date +%s) + minutes * 60 )) |
| 12 | 16 | settled=0 |
| 13 | 17 | while :; do |
| 14 | - runs=$(api "/actions/runs?head_sha=$sha&per_page=100") | |
| 18 | + all=$(api "/actions/runs?head_sha=$sha&per_page=100") | |
| 19 | + runs=$(jq --argjson u "$unrelated" '.workflow_runs |= map(select(.event as $e | $u | index($e) | not))' <<<"$all") | |
| 15 | 20 | total=$(jq '.workflow_runs | length' <<<"$runs") |
| 16 | 21 | pending=$(jq '[.workflow_runs[] | select(.status != "completed")] | length' <<<"$runs") |
| 17 | 22 | if [ "$total" -gt 0 ] && [ "$pending" = 0 ]; then |
| @@ -29,6 +34,7 @@ | ||
| 29 | 34 | sleep 15 |
| 30 | 35 | done |
| 31 | 36 | |
| 37 | +jq -r --argjson u "$unrelated" '.workflow_runs[] | select(.event as $e | $u | index($e)) | "skipped \(.name) [\(.event)]: \(.status) \(.html_url)"' <<<"$all" | |
| 32 | 38 | failed=0 |
| 33 | 39 | for id in $(jq -r '.workflow_runs[].id' <<<"$runs"); do |
| 34 | 40 | run=$(api "/actions/runs/$id") |