|
2 | 2 | # Lists recently completed tend CI runs. |
3 | 3 | # |
4 | 4 | # Fetches runs started in the past 3 hours, then filters to only those that |
5 | | -# are completed and whose updatedAt is within the past 2 hours. This |
6 | | -# two-step approach is needed because `gh run list --created` filters by |
7 | | -# *start* time, not *end* time — a run started 2h ago may have just |
| 5 | +# are completed and whose updatedAt falls within a 1-hour completion window. |
| 6 | +# This two-step approach is needed because `gh run list --created` filters |
| 7 | +# by *start* time, not *end* time — a run started 2h ago may have just |
8 | 8 | # finished, and a run started 50min ago may still be running. |
9 | 9 | # |
10 | | -# The 2h completion window absorbs GitHub Actions cron delay. Hourly |
11 | | -# review-reviewers runs (cron `47 * * * *`) routinely fire 20–40 min late |
12 | | -# during peak hours, producing gaps of 80–100 min between consecutive |
13 | | -# cycles. A tighter 1h cutoff drops everything older than the previous |
14 | | -# cycle's expected start, silently hiding runs that landed in the delay |
15 | | -# slack. The 2h cutoff covers all observed gaps with margin; the small |
16 | | -# re-analysis overlap between cycles is cheap because gist entries are |
17 | | -# keyed by run ID. |
| 10 | +# Window anchor: when invoked under a scheduled workflow with a simple |
| 11 | +# hourly cron (`MM * * * *`), the completion window is anchored to the most |
| 12 | +# recent intended cron tick instead of `now`. Consecutive cycles then tile |
| 13 | +# exactly: [intended-1h, intended], then [intended, intended+1h]. Without |
| 14 | +# this, GHA scheduler delay (20-40 min during peak hours) shifts each |
| 15 | +# cycle's window relative to actual start time and drops runs that finished |
| 16 | +# in the slack between consecutive actual starts. For non-schedule events |
| 17 | +# or non-hourly crons, falls back to a now-anchored 1h window. |
18 | 18 | # |
19 | 19 | # Environment variables: |
20 | 20 | # TARGET_REPO - Query a different repo (default: current repo) |
@@ -45,8 +45,30 @@ for prefix in "${PREFIXES[@]}"; do |
45 | 45 | WORKFLOWS+=("${matches[@]}") |
46 | 46 | done |
47 | 47 |
|
48 | | -CREATED_SINCE=$(date -d '3 hours ago' +%Y-%m-%dT%H:%M:%S) |
49 | | -COMPLETED_AFTER=$(date -d '2 hours ago' +%s) |
| 48 | +# Detect a simple hourly cron (e.g. "47 * * * *") from the workflow event |
| 49 | +# payload so we can anchor the window to the most recent intended tick. |
| 50 | +cron_minute="" |
| 51 | +if [ -f "${GITHUB_EVENT_PATH:-}" ]; then |
| 52 | + schedule=$(jq -r '.schedule // empty' "$GITHUB_EVENT_PATH" 2>/dev/null || true) |
| 53 | + if [[ "$schedule" =~ ^([0-9]+)\ \*\ \*\ \*\ \*$ ]]; then |
| 54 | + cron_minute="${BASH_REMATCH[1]}" |
| 55 | + fi |
| 56 | +fi |
| 57 | + |
| 58 | +if [ -n "$cron_minute" ]; then |
| 59 | + this_hour_tick=$(date -u -d "$(date -u +%Y-%m-%dT%H:00:00) $cron_minute minutes" +%s) |
| 60 | + now_ts=$(date -u +%s) |
| 61 | + if [ "$now_ts" -lt "$this_hour_tick" ]; then |
| 62 | + intended=$((this_hour_tick - 3600)) |
| 63 | + else |
| 64 | + intended=$this_hour_tick |
| 65 | + fi |
| 66 | + COMPLETED_AFTER=$((intended - 3600)) |
| 67 | + CREATED_SINCE=$(date -u -d "@$((intended - 10800))" +%Y-%m-%dT%H:%M:%S) |
| 68 | +else |
| 69 | + CREATED_SINCE=$(date -d '3 hours ago' +%Y-%m-%dT%H:%M:%S) |
| 70 | + COMPLETED_AFTER=$(date -d '1 hour ago' +%s) |
| 71 | +fi |
50 | 72 |
|
51 | 73 | all_runs="[]" |
52 | 74 |
|
|
0 commit comments