-
Notifications
You must be signed in to change notification settings - Fork 2.6k
[TRTLLMINF-188][infra] Require approval for broad post-merge bot runs #16318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chzblych
wants to merge
6
commits into
NVIDIA:main
Choose a base branch
from
chzblych:trtllminf-188-post-merge-approval
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+238
−8
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3e82b91
ci: guard post-merge approval labels
chzblych ede2b4e
ci: use shared TRT-LLM agent token
chzblych f39f1da
ci: prevent stale approval cleanup
chzblych e23c845
docs: explain post-merge workflow trigger safety
chzblych 9d79005
docs: clarify post-merge workflow API usage
chzblych b9e1420
test: remove unexecuted workflow harness
chzblych File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,217 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| name: Guard Post-Merge Approval Label | ||
|
|
||
| on: | ||
| # Intentional: this runs static default-branch API logic only. It never checks | ||
| # out or executes PR code; it uses GitHub APIs to validate membership and | ||
| # manage this PR's approval label/comment. | ||
| pull_request_target: | ||
| types: [labeled] | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| guard-post-merge-approval: | ||
| concurrency: | ||
| group: post-merge-approval-${{ github.event.pull_request.number }} | ||
| cancel-in-progress: false | ||
| if: >- | ||
| github.repository == 'NVIDIA/TensorRT-LLM' && | ||
| github.event.action == 'labeled' && | ||
| github.event.label.name == 'ci: post-merge approved' | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Validate post-merge approver | ||
| id: validate | ||
| if: github.event.action == 'labeled' | ||
| uses: actions/github-script@v8 | ||
| with: | ||
| github-token: ${{ secrets.TRTLLM_AGENT_SHARED_TOKEN }} | ||
| result-encoding: string | ||
| script: | | ||
| const approvalLabel = 'ci: post-merge approved'; | ||
| const owner = context.repo.owner; | ||
| const repo = context.repo.repo; | ||
| const issueNumber = context.payload.pull_request.number; | ||
| let actor = context.payload.sender?.login || context.actor; | ||
| let labelEventId = ''; | ||
| let timelineVerified = false; | ||
|
|
||
| try { | ||
| const events = await github.paginate( | ||
| github.rest.issues.listEventsForTimeline, | ||
| { owner, repo, issue_number: issueNumber, per_page: 100 } | ||
| ); | ||
| const latestApprovalEvent = events | ||
| .filter( | ||
| (event) => | ||
| event.event === 'labeled' && | ||
| event.label?.name === approvalLabel | ||
| ) | ||
| .at(-1); | ||
| if (latestApprovalEvent) { | ||
| actor = latestApprovalEvent.actor?.login || actor; | ||
| labelEventId = String(latestApprovalEvent.id); | ||
| timelineVerified = true; | ||
| } else { | ||
| core.warning('Could not identify the latest post-merge approval event.'); | ||
| } | ||
| } catch (error) { | ||
| core.warning( | ||
| 'Could not read the latest post-merge approval event: ' + error.message | ||
| ); | ||
| } | ||
|
|
||
| core.setOutput('validated_actor', actor); | ||
| core.setOutput('label_event_id', labelEventId); | ||
| if (!timelineVerified) { | ||
| return 'false'; | ||
| } | ||
| try { | ||
| const response = await github.request( | ||
| 'GET /orgs/{org}/teams/{team_slug}/memberships/{username}', | ||
| { | ||
| org: 'NVIDIA', | ||
| team_slug: 'trt-llm-ci-approvers', | ||
| username: actor, | ||
| } | ||
| ); | ||
| const authorized = response.data.state === 'active'; | ||
| console.log( | ||
| actor + ' active membership in NVIDIA/trt-llm-ci-approvers: ' + authorized | ||
| ); | ||
| return authorized ? 'true' : 'false'; | ||
| } catch (error) { | ||
| if (error.status === 404) { | ||
| console.log( | ||
| actor + ' is not an active member of NVIDIA/trt-llm-ci-approvers.' | ||
| ); | ||
| } else { | ||
| core.warning( | ||
| 'Could not verify post-merge approver ' + actor + ': ' + error.message | ||
| ); | ||
| } | ||
| return 'false'; | ||
| } | ||
|
|
||
| - name: Clear unauthorized post-merge approval | ||
| if: always() && !cancelled() && steps.validate.outputs.result != 'true' | ||
| uses: actions/github-script@v8 | ||
| env: | ||
| VALIDATED_ACTOR: ${{ steps.validate.outputs.validated_actor }} | ||
| VALIDATED_LABEL_EVENT_ID: ${{ steps.validate.outputs.label_event_id }} | ||
| with: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| script: | | ||
| const approvalLabel = 'ci: post-merge approved'; | ||
| const actor = | ||
| process.env.VALIDATED_ACTOR || | ||
| context.payload.sender?.login || | ||
| context.actor; | ||
| const validatedEventId = process.env.VALIDATED_LABEL_EVENT_ID || ''; | ||
| const owner = context.repo.owner; | ||
| const repo = context.repo.repo; | ||
| const issueNumber = context.payload.pull_request.number; | ||
|
|
||
| try { | ||
| const pullRequest = await github.rest.pulls.get({ | ||
| owner, | ||
| repo, | ||
| pull_number: issueNumber, | ||
| }); | ||
| const labelIsPresent = pullRequest.data.labels.some( | ||
| (label) => label.name === approvalLabel | ||
| ); | ||
| if (!labelIsPresent) { | ||
| console.log('Post-merge approval label is already absent; no cleanup needed.'); | ||
| return; | ||
| } | ||
| } catch (error) { | ||
| core.warning( | ||
| 'Could not read the current post-merge approval label state; continuing validation: ' + | ||
| error.message | ||
| ); | ||
| } | ||
|
|
||
| try { | ||
| const events = await github.paginate( | ||
| github.rest.issues.listEventsForTimeline, | ||
| { owner, repo, issue_number: issueNumber, per_page: 100 } | ||
| ); | ||
| const latestApprovalEvent = events | ||
| .filter( | ||
| (event) => | ||
| event.event === 'labeled' && | ||
| event.label?.name === approvalLabel | ||
| ) | ||
| .at(-1); | ||
| const latestEventId = latestApprovalEvent | ||
| ? String(latestApprovalEvent.id) | ||
| : ''; | ||
| const latestActor = latestApprovalEvent?.actor?.login || ''; | ||
| if (!latestApprovalEvent) { | ||
| core.warning( | ||
| 'Could not identify the latest post-merge approval event; removing the label to fail closed.' | ||
| ); | ||
| } else if (!latestActor) { | ||
| core.warning( | ||
| 'Could not identify the latest post-merge approval actor; removing the label to fail closed.' | ||
| ); | ||
| } else if (!validatedEventId) { | ||
| core.warning( | ||
| 'The validation run did not bind an approval event; removing the label to fail closed.' | ||
| ); | ||
| } else if ( | ||
| latestEventId !== validatedEventId || | ||
| latestActor !== actor | ||
| ) { | ||
| console.log( | ||
| 'A newer post-merge approval event was found; leaving it for its own validation run.' | ||
| ); | ||
| return; | ||
| } | ||
| } catch (error) { | ||
| core.warning( | ||
| 'Could not re-check the latest post-merge approval event; removing the label to fail closed: ' + | ||
| error.message | ||
| ); | ||
| } | ||
|
|
||
| try { | ||
| await github.rest.issues.removeLabel({ | ||
| owner, | ||
| repo, | ||
| issue_number: issueNumber, | ||
| name: approvalLabel, | ||
| }); | ||
| } catch (error) { | ||
| if (error.status !== 404) { | ||
| throw error; | ||
| } | ||
| } | ||
|
|
||
| await github.rest.issues.createComment({ | ||
| owner, | ||
| repo, | ||
| issue_number: issueNumber, | ||
| body: | ||
| 'Removed the "' + approvalLabel + '" label because @' + actor + | ||
| ' could not be verified as an active member of ' + | ||
| 'NVIDIA/trt-llm-ci-approvers. Ask a member of that team to apply it.', | ||
| }); | ||
|
chzblych marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.