feat(ci): gate merges on maintainer approval via a required status check - #3176
feat(ci): gate merges on maintainer approval via a required status check#3176purp wants to merge 11 commits into
Conversation
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
Signed-off-by: Jim Meyer <jimeyer@nvidia.com>
Signed-off-by: Jim Meyer <jimeyer@nvidia.com>
Signed-off-by: Jim Meyer <jimeyer@nvidia.com>
Signed-off-by: Jim Meyer <jimeyer@nvidia.com>
Signed-off-by: Jim Meyer <jimeyer@nvidia.com>
Signed-off-by: Jim Meyer <jimeyer@nvidia.com>
Signed-off-by: Jim Meyer <jimeyer@nvidia.com>
A checkout or API failure on a merge_group run left STATUS_SHA empty, so the guard skipped and the required check sat at Expected until the queue timed out. Signed-off-by: Jim Meyer <jimeyer@nvidia.com>
Writing to $GITHUB_ENV under pull_request_target trips zizmor's github-env rule, which fails the code-scanning check. Step outputs carry the same values without granting later steps an attacker-shaped environment, and the resolved head SHA now also covers a workflow_dispatch run that fails after the pull request lookup. Signed-off-by: Jim Meyer <jimeyer@nvidia.com>
Add a required check that passes only when someone listed in MAINTAINERS.md has an approving review on the pull request. Unlike CODEOWNERS and ruleset required reviewers, a status check enforces who must approve without notifying anyone, and its approver list is a file, so outside collaborators can be listed. The job reports through its own exit code rather than a posted commit status, so it needs no write token and no head SHA. It runs on pull_request_review, and on merge_group because the queue waits for required contexts to report on the merge group ref regardless of the pull request result. MAINTAINERS.md and the decision helper are read from main, never the pull request ref, so a contributor cannot add themselves and self-approve. The helper fails closed when no handles parse. Signed-off-by: Jim Meyer <jimeyer@nvidia.com>
b6102b0 to
f92a2df
Compare
purp
left a comment
There was a problem hiding this comment.
Refactor per comments.
|
|
||
| """Decide whether a pull request carries an approval from a listed maintainer. | ||
|
|
||
| The logic here is pure so it can be unit tested. The calling workflow does the |
There was a problem hiding this comment.
Lose the comment about purity of logic. Comments say what we do and why, concisely, and only when reading the code isn't explicit enough.
There was a problem hiding this comment.
The maintainers change alert should be a separate, simple tool named alert_maintainer_change.py
This should be named check_maintainer_approval.py
Neither needs a verb argument like detect or diff
| | Name | GitHub ID | Company/Organization | | ||
| | --- | --- | --- | | ||
| | Derek Carr | [@derekwaynecarr](https://github.com/derekwaynecarr) | Red Hat | | ||
| | Jim Meyer | [@purp](https://github.com/purp) | NVIDIA | |
There was a problem hiding this comment.
Let's recognize someone who's contributed more to the project. Use Piotr and Evan here.
| assert "drive-by" not in ca.parse_maintainers(prose) | ||
|
|
||
|
|
||
| def test_parse_maintainers_returns_empty_when_table_is_reformatted() -> None: |
There was a problem hiding this comment.
This is the same as an unparseable list. Drop this test.
| ) | ||
|
|
||
|
|
||
| def decide(markdown: str, reviews: list[dict]) -> tuple[bool, str]: |
There was a problem hiding this comment.
This should just move to main now that the tool has only one purpose.
| return {match.group(1).lower() for match in MAINTAINER_RE.finditer(markdown)} | ||
|
|
||
|
|
||
| def latest_positions(reviews: list[dict]) -> dict[str, str]: |
There was a problem hiding this comment.
Rework to be parse_reviews_to_approvers. Read reviews.json, resolve each reviewer's current state, then filter to only those that are currently "APPROVED". Returns the list of logins who currently have approved reviews.
| return positions | ||
|
|
||
|
|
||
| def approving_maintainers(reviews: list[dict], maintainers: set[str]) -> list[str]: |
There was a problem hiding this comment.
Drop this. Not needed if parse_reviews_to_approvers returns the list of approving logins
Each CI tool now does one thing: check_maintainer_approval.py decides the gate, alert_maintainer_change.py renders the approver-set delta. Neither takes a verb argument. The login pattern is duplicated so each tool stands alone; a test asserts the two patterns stay identical. Signed-off-by: Jim Meyer <jimeyer@nvidia.com>
purp
left a comment
There was a problem hiding this comment.
Please address all comments.
|
|
||
| jobs: | ||
| describe-change: | ||
| name: Comment on the approver set change |
There was a problem hiding this comment.
"... if MAINTAINERS.md has changed."
| jobs: | ||
| describe-change: | ||
| name: Comment on the approver set change | ||
| if: github.repository_owner == 'NVIDIA' |
There was a problem hiding this comment.
Why is this conditional needed?
| # tasks/scripts/core_approval.py, which emits it as the first line of | ||
| # the body. If they drift, the lookup below silently stops matching | ||
| # and every push stacks another comment. | ||
| # tasks/scripts/alert_maintainer_change.py, which emits it as the |
There was a problem hiding this comment.
Can we just set it as an environment variable that we use here and the alert script gets for free? Less maintenance and coupling is a goodness.
| # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Print a review comment describing how a pull request changes the approver set. |
There was a problem hiding this comment.
"... to make sure that reviewers notice the change."
|
|
||
| """Print a review comment describing how a pull request changes the approver set. | ||
|
|
||
| The calling workflow does the I/O: it extracts MAINTAINERS.md at the base and |
There was a problem hiding this comment.
Unnecessary comment. We can read this in the code. Comments say what we do and why concisely and only when the code doesn't speak for itself.
| added, removed = sorted(new - old), sorted(old - new) | ||
|
|
||
| lines = [COMMENT_MARKER, "## Maintainer list change", ""] | ||
| if not added and not removed: |
There was a problem hiding this comment.
In this case we should not comment. It makes no value and unneeded noise is distracting.
| "satisfy `OpenShell / Maintainer Approval`." | ||
| ) | ||
|
|
||
| if not new: |
There was a problem hiding this comment.
This condition should cause the check to fail.
| def test_names_added_and_removed_logins() -> None: | ||
| after = TABLE.replace( | ||
| "| Piotr Mlocek | [@pimlock](https://github.com/pimlock) | NVIDIA |\n", | ||
| "| New Person | [@newbie](https://github.com/newbie) | NVIDIA |\n", |
There was a problem hiding this comment.
Pick a real contributor like Mrunal Patel
| assert "does not change" in body | ||
|
|
||
|
|
||
| def test_warns_when_the_result_parses_empty() -> None: |
There was a problem hiding this comment.
Check should fail in this condition
|
|
||
| """Exit non-zero unless a maintainer listed in MAINTAINERS.md has approved. | ||
|
|
||
| The calling workflow does the I/O: it checks out MAINTAINERS.md from the |
There was a problem hiding this comment.
Again, not needed. Comments say what we do and why concisely and only when the code doesn't speak for itself.
Summary
Adds a
OpenShell / Core Approvalcommit status that passes only when someone listed inMAINTAINERS.mdhas approved the pull request. Once registered on ruleset13332227it becomes the approval gate, which is what makes it safe to disable theCODEOWNERSwildcard in #3168.The motivating problem is that every native GitHub mechanism enforcing who must approve also notifies them:
CODEOWNERSA required status check is the only primitive that gates a merge silently. That splits enforcement from notification: this PR is the enforcement half. Targeted notification (area labels, per-area rosters) follows separately.
A file-based approver list also solves the outside-collaborator problem — three of thirteen maintainers cannot join an NVIDIA org team, but can be listed in a file.
Related Issue
No issue required. This does not touch OpenShell platform code — it is maintenance of the project's own review machinery, and is non-breaking as merged. The gate only starts enforcing when the status context is added to ruleset
13332227, which is a separate manual step (see Rollout).Changes
tasks/scripts/core_approval.py— stdlib-only helper.decideparsesMAINTAINERS.md, folds the review list to each reviewer's latest decisive position, and printsstate<TAB>description.diffrenders the approver-set delta between two versions of the file.tasks/scripts/core_approval_test.py— 17 tests.tasks/test.tomlgainstest:core-approval..github/workflows/core-approval.yml— publishes the status onpull_request_target,pull_request_review,merge_group, andworkflow_dispatch..github/workflows/maintainers-change-alert.yml— comments the added/removed handles on PRs touchingMAINTAINERS.md, so reviewers see the delta instead of diffing a markdown table..github/zizmor.yml— twodangerous-triggerssuppressions for the new workflows.Security invariants
pull_request_targetruns with a write-capable token; executing contributor code under it is the standard escalation. The checkout is pinned toref: mainwith a sparse checkout of only the helper script andpersist-credentials: false.MAINTAINERS.mdis read frommain, never the PR ref. Otherwise a contributor adds themselves in their own PR and self-approves.success.No
${{ }}interpolation appears inside anyrun:block; every context value routes throughenv:.Why this trigger set
pull_requestdoes not re-fire when someone approves, so the check would go stale red forever.pull_request_reviewfires but its jobs are not auto-surfaced as PR checks, so the status is POSTed explicitly. Fork PRs get a read-only token underpull_requestand cannot POST at all;pull_request_targetandpull_request_reviewboth run in base-repo context.merge_grouppublishes success unconditionally. A merge group only forms after the PR already satisfied this gate, and approvals cannot change while an entry sits in the queue. Without this, a required check that never reports on the merge-group ref stalls every entry for the fullcheck_response_timeout_minutes(60).Testing
mise run pre-commitpassesThere is no pre-merge dry run, by construction.
pull_request_targetruns the base branch's workflow definition, so this workflow cannot be exercised from its own PR.if: github.repository_owner == 'NVIDIA'also keeps it from running on forks. Behavior is covered by unit tests here and verified live after merge, before the check is made required.Reviewer notes
$GITHUB_ENVwrites. An earlier revision passed the head SHA between steps via$GITHUB_ENV, which trips zizmor'sgithub-envrule underpull_request_targetand fails the code-scanning check. The workflow now uses step outputs (steps.publish.outputs.posted/head_sha), which carry the same values without granting later steps an attacker-shaped environment. Note that theZizmor High reportjob is informational, but the SARIF it uploads feeds a separate Advanced Securityzizmorcheck that does fail on new alerts.workflow_dispatch, no SHA is knowable until the PR lookup runs, so a failure strictly before that point publishes nothing and logs a warning. A failure after the lookup is covered by thehead_shastep output. Every other event resolves the SHA from the event payload.dismiss_stale_reviews_on_push: true. A push and a dismissal can interleave, but the check re-runs onsynchronize, so it converges.CODEOWNERSgate. Reducing the admin surface is deliberately out of scope.johnnygrecoholds admin viaopenshell-codeownersbut is absent fromMAINTAINERS.md. Deferred; revisit when the team list is reconciled.Rollout
Order matters — reversing steps 1–3 and 4 blocks every open PR.
workflow_dispatch(pr_numberis required; there is no sweep mode). PRs opened before the workflow existed otherwise sit at "Expected" forever once the check is required.MAINTAINERS.mdcannot self-approve.OpenShell / Core Approvalto ruleset13332227.Checklist