Skip to content

Commit e8ede9c

Browse files
Fix CI check: evaluate only latest run per workflow, not all runs
When falling back to the workflow runs API, checking all runs would incorrectly block a PR where a workflow failed and was successfully re-run. Group by workflow name and take the highest run_number as the authoritative result for each workflow. Same wording fix applied to AI agent instructions (Step 2 CI check).
1 parent 04c6679 commit e8ede9c

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

.github/workflows/dependabot-major-merge.yml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,31 +113,37 @@ jobs:
113113
114114
if [ "$TOTAL" -eq 0 ]; then
115115
echo "No check-runs found — falling back to workflow runs API (common for Dependabot PRs)..."
116-
WORKFLOW_RUNS=$(gh api \
116+
ALL_RUNS=$(gh api \
117117
"/repos/${{ github.repository }}/actions/runs?head_sha=$PR_SHA&per_page=100" \
118118
--jq '[.workflow_runs[] | select(.name != "Dependabot major-version auto-merge")]')
119-
WF_TOTAL=$(echo "$WORKFLOW_RUNS" | jq 'length')
120-
echo "Found $WF_TOTAL workflow run(s) via actions/runs API."
119+
WF_TOTAL=$(echo "$ALL_RUNS" | jq 'length')
120+
echo "Found $WF_TOTAL total workflow run(s) via actions/runs API."
121121
122122
if [ "$WF_TOTAL" -eq 0 ]; then
123123
echo "::error::No CI results found via either API — refusing to merge without CI signals."
124124
exit 1
125125
fi
126126
127-
WF_PENDING=$(echo "$WORKFLOW_RUNS" | jq '[.[] | select(.status != "completed")] | length')
128-
WF_FAILED=$(echo "$WORKFLOW_RUNS" | jq '[.[] | select(.status == "completed" and .conclusion != "success" and .conclusion != "skipped")] | length')
127+
# Take only the latest run per workflow (highest run_number), so a
128+
# successful re-run after an earlier failure isn't blocked by the old failure.
129+
LATEST_RUNS=$(echo "$ALL_RUNS" | jq '[group_by(.name)[] | sort_by(.run_number) | last]')
130+
LATEST_TOTAL=$(echo "$LATEST_RUNS" | jq 'length')
131+
echo "Evaluating $LATEST_TOTAL latest run(s) (one per workflow)."
132+
133+
WF_PENDING=$(echo "$LATEST_RUNS" | jq '[.[] | select(.status != "completed")] | length')
134+
WF_FAILED=$(echo "$LATEST_RUNS" | jq '[.[] | select(.status == "completed" and .conclusion != "success" and .conclusion != "skipped")] | length')
129135
130136
if [ "$WF_PENDING" -gt 0 ]; then
131137
echo "::error::$WF_PENDING workflow run(s) are still pending — refusing to merge."
132-
echo "$WORKFLOW_RUNS" | jq '[.[] | select(.status != "completed")] | .[].name'
138+
echo "$LATEST_RUNS" | jq '[.[] | select(.status != "completed")] | .[].name'
133139
exit 1
134140
fi
135141
if [ "$WF_FAILED" -gt 0 ]; then
136142
echo "::error::$WF_FAILED workflow run(s) did not succeed — refusing to merge."
137-
echo "$WORKFLOW_RUNS" | jq '[.[] | select(.conclusion != "success" and .conclusion != "skipped")] | .[] | {name, conclusion}'
143+
echo "$LATEST_RUNS" | jq '[.[] | select(.conclusion != "success" and .conclusion != "skipped")] | .[] | {name, conclusion}'
138144
exit 1
139145
fi
140-
echo "✅ All $WF_TOTAL workflow run(s) passed (via actions/runs API)."
146+
echo "✅ All $LATEST_TOTAL latest workflow run(s) passed (via actions/runs API)."
141147
else
142148
FAILED=$(echo "$CHECK_RUNS" | jq '[.[] | select(.conclusion != "success" and .conclusion != "skipped" and .conclusion != null)] | length')
143149
PENDING=$(echo "$CHECK_RUNS" | jq '[.[] | select(.conclusion == null)] | length')

.github/workflows/dependabot-major-review.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ For each candidate PR, perform the following checks in order. If any check fails
9696
- Single package: "Bump <package> from <old> to <new>" — parse semver, only proceed if major version increased OR if this is a multi-package PR
9797
- Multi-package: "Bump <package> in <path>" with a branch name containing `/multi-` — these have multiple packages updated together and `fetch-metadata` returns null for `update-type`. **Always process these** regardless of version increment — the AI must analyze the diff to determine all version changes
9898
- If the title is a single-package bump where the major version has NOT increased (pure patch/minor), skip it — the existing auto-merge workflow handles those
99-
4. **CI status:** Use the `actions` toolset to retrieve check runs for the PR's head commit. Verify that every check run has a conclusion of `"success"` or `"skipped"`. If the check-runs endpoint returns 0 results, also query workflow runs by head SHA (`GET /repos/IntelliTect/try/actions/runs?head_sha=<sha>`) — Dependabot PRs often register their CI only as workflow runs, not as check-run objects. At least one workflow run must exist and all must have `conclusion: "success"`. If any check or run has failed, is cancelled, or is still in-progress/pending, skip this PR entirely.
99+
4. **CI status:** Use the `actions` toolset to retrieve check runs for the PR's head commit. Verify that every check run has a conclusion of `"success"` or `"skipped"`. If the check-runs endpoint returns 0 results, also query workflow runs by head SHA (`GET /repos/IntelliTect/try/actions/runs?head_sha=<sha>`) — Dependabot PRs often register their CI only as workflow runs, not as check-run objects. Group runs by workflow name and evaluate only the **latest run per workflow** (highest run number) — a successful re-run after an earlier failure is valid. At least one workflow run must exist and the latest run for every workflow must have `conclusion: "success"` or `"skipped"`. If any latest run has failed, is cancelled, or is still in-progress/pending, skip this PR entirely.
100100

101101
### Step 3: Verify the Diff is Version-Only
102102

0 commit comments

Comments
 (0)