Diffinery

codician/diffinerypublic

Open-source, agent-first GitHub and GitHub Actions alternative that runs on your own Cloudflare account: git hosting, pull requests, code review and drop-in GitHub Actions YAML on Workers, Durable Objects, R2 and Containers.

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 @@
11 #!/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.
58 #
69 # Usage: DIFFINERY=https://diffinery.com TOKEN=... diffinery-wait-runs.sh owner/repo sha [minutes]
710 set -euo pipefail
811 repo=$1 sha=$2 minutes=${3:-60}
912 api() { curl -fsS --retry 3 "$DIFFINERY/api/v3/repos/$repo$1" -H "Authorization: Bearer $TOKEN"; }
13+unrelated='["workflow_dispatch", "schedule", "repository_dispatch"]'
1014
1115 deadline=$(( $(date +%s) + minutes * 60 ))
1216 settled=0
1317 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")
1520 total=$(jq '.workflow_runs | length' <<<"$runs")
1621 pending=$(jq '[.workflow_runs[] | select(.status != "completed")] | length' <<<"$runs")
1722 if [ "$total" -gt 0 ] && [ "$pending" = 0 ]; then
@@ -29,6 +34,7 @@
2934 sleep 15
3035 done
3136
37+jq -r --argjson u "$unrelated" '.workflow_runs[] | select(.event as $e | $u | index($e)) | "skipped \(.name) [\(.event)]: \(.status) \(.html_url)"' <<<"$all"
3238 failed=0
3339 for id in $(jq -r '.workflow_runs[].id' <<<"$runs"); do
3440 run=$(api "/actions/runs/$id")