diff --git a/.github/workflows/merge-bot-task.yml b/.github/workflows/merge-bot-task.yml index 3f569030b..9bcc62186 100644 --- a/.github/workflows/merge-bot-task.yml +++ b/.github/workflows/merge-bot-task.yml @@ -137,9 +137,10 @@ jobs: passing_since=0 while :; do read_pr - read_api "the head's check runs" "checks: read" gh api --paginate "repos/$REPO/commits/$HEAD_SHA/check-runs?per_page=100" --jq '.check_runs[] | {id, name, status, conclusion}' - # A re-run leaves its earlier attempt on the head, so only the newest run of each name counts. - runs=$(jq -sc 'group_by(.name) | map(max_by(.id))[]' <<<"$out") + read_api "the head's check runs" "checks: read" gh api --paginate "repos/$REPO/commits/$HEAD_SHA/check-runs?per_page=100" --jq '.check_runs[] | {id, name, status, conclusion, app: .app.id}' + # A re-run leaves its earlier attempt on the head, so only the newest run counts. + # A run is keyed by App and name, so another App's passing run never hides a failure. + runs=$(jq -sc 'group_by([.app, .name]) | map(max_by(.id))[]' <<<"$out") read_api "the head's commit statuses" "statuses: read" gh api --paginate "repos/$REPO/commits/$HEAD_SHA/status?per_page=100" --jq '.statuses[] | {name: .context, status: (if .state == "pending" then "pending" else "completed" end), conclusion: .state}' # This workflow's own jobs post on the head too, as a caller job name, a slash, and the job name, so the wait leaves them out. checks=$(jq -sc --argjson own "$OWN_JOBS" ' diff --git a/tests/test_merge_bot_merge.py b/tests/test_merge_bot_merge.py index d6f03c4a5..0879c5b74 100755 --- a/tests/test_merge_bot_merge.py +++ b/tests/test_merge_bot_merge.py @@ -54,9 +54,19 @@ def check_run( - name: str, status: str = "completed", conclusion: str | None = "success", run_id: int = 1 + name: str, + status: str = "completed", + conclusion: str | None = "success", + run_id: int = 1, + app_id: int = 1, ) -> dict[str, Any]: - return {"id": run_id, "name": name, "status": status, "conclusion": conclusion} + return { + "id": run_id, + "name": name, + "status": status, + "conclusion": conclusion, + "app": {"id": app_id}, + } def runs(*checks: dict[str, Any]) -> dict[str, Any]: @@ -328,6 +338,15 @@ def test_only_the_newest_run_of_a_re_run_check_counts(self) -> None: self.assertEqual(0, result.returncode, result.stdout + result.stderr) self.assertEqual(1, len(self.merges(calls))) + def test_a_passing_run_of_another_app_does_not_hide_a_failed_one(self) -> None: + failed = check_run("Lint job", conclusion="failure", run_id=1, app_id=1) + result, calls = self.merge( + UNREQUIRED, [runs(check_run("Lint job", run_id=2, app_id=2), failed)] + ) + self.assertEqual(1, result.returncode, result.stdout + result.stderr) + self.assertIn("Lint job (failure)", result.stdout + result.stderr) + self.assertEqual(0, len(self.merges(calls))) + def test_a_pull_request_closed_during_the_merge_retry_ends_without_failing(self) -> None: refused = {"error": "GraphQL: Pull request is closed"} closed = {"json": {**OPEN, "state": "closed"}}