-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[TRTLLMINF-396][ci] Automate full pre-merge approval #18656
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
Closed
ZhanruiSunCh
wants to merge
4
commits into
NVIDIA:main
from
ZhanruiSunCh:user/zhanruis/0903_auto_full_premerge_approval
+559
−40
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
99d2bda
[TRTLLMINF-396][ci] Automate full pre-merge approval
ZhanruiSunCh 7d11ec2
[TRTLLMINF-396][test] Skip PipelineMonitor GPU execution
ZhanruiSunCh dcb9f7a
Merge branch 'main' into user/zhanruis/0903_auto_full_premerge_approval
ZhanruiSunCh c24ed93
[TRTLLMINF-396][fix] Correct full single-GPU gate decisions
ZhanruiSunCh 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,256 @@ | ||
| # 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: Auto Full Pre-Merge Approval Label | ||
|
|
||
| on: | ||
| status: | ||
| pull_request_review: | ||
| types: [submitted] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| auto-full-premerge-approval: | ||
| if: >- | ||
| github.repository == 'NVIDIA/TensorRT-LLM' && | ||
| ((github.event_name == 'status' && | ||
| github.event.context == 'full-single-gpu-tests' && | ||
| github.event.state == 'success') || | ||
| (github.event_name == 'pull_request_review' && | ||
| github.event.review.state == 'approved')) | ||
| concurrency: | ||
| group: auto-full-premerge-${{ github.event.pull_request.head.sha || github.event.sha }} | ||
| cancel-in-progress: false | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 5 | ||
| steps: | ||
| - name: Require agent token | ||
| env: | ||
| AGENT_TOKEN: ${{ secrets.TRTLLM_AGENT_SHARED_TOKEN }} | ||
| run: | | ||
| if [[ -z "${AGENT_TOKEN}" ]]; then | ||
| echo "::error::TRTLLM_AGENT_SHARED_TOKEN is unavailable for this event." | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Add full pre-merge approval label when eligible | ||
| uses: actions/github-script@v8 | ||
| with: | ||
| github-token: ${{ secrets.TRTLLM_AGENT_SHARED_TOKEN }} | ||
| script: | | ||
| const approvalLabel = 'ci: full pre-merge approved'; | ||
| const fullSingleStatus = 'full-single-gpu-tests'; | ||
| const owner = context.repo.owner; | ||
| const repo = context.repo.repo; | ||
|
|
||
| const sleep = (milliseconds) => | ||
| new Promise((resolve) => setTimeout(resolve, milliseconds)); | ||
|
|
||
| async function withRetry(description, operation) { | ||
| const attempts = 3; | ||
| for (let attempt = 1; attempt <= attempts; attempt += 1) { | ||
| try { | ||
| return await operation(); | ||
| } catch (error) { | ||
| if (attempt === attempts) { | ||
| throw error; | ||
| } | ||
| core.warning( | ||
| `${description} failed (attempt ${attempt}/${attempts}): ${error.message}` | ||
| ); | ||
| await sleep(1000 * attempt); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| async function getCandidatePullRequests() { | ||
| if (context.eventName === 'pull_request_review') { | ||
| return [context.payload.pull_request.number]; | ||
| } | ||
|
|
||
| const pullRequests = await withRetry( | ||
| `Find pull requests associated with ${context.payload.sha}`, | ||
| () => | ||
| github.paginate( | ||
| 'GET /repos/{owner}/{repo}/commits/{commit_sha}/pulls', | ||
| { | ||
| owner, | ||
| repo, | ||
| commit_sha: context.payload.sha, | ||
| per_page: 100, | ||
| } | ||
| ) | ||
| ); | ||
| const repository = `${owner}/${repo}`.toLowerCase(); | ||
| return [ | ||
| ...new Set( | ||
| pullRequests | ||
| .filter( | ||
| (pullRequest) => | ||
| pullRequest.state === 'open' && | ||
| pullRequest.base.repo.full_name.toLowerCase() === repository | ||
| ) | ||
| .map((pullRequest) => pullRequest.number) | ||
| ), | ||
| ]; | ||
| } | ||
|
|
||
| const pullRequestQuery = ` | ||
| query($owner: String!, $repo: String!, $number: Int!) { | ||
| repository(owner: $owner, name: $repo) { | ||
| pullRequest(number: $number) { | ||
| headRefOid | ||
| labels(first: 100) { | ||
| nodes { | ||
| name | ||
| } | ||
| } | ||
| reviewDecision | ||
| state | ||
| } | ||
| } | ||
| } | ||
| `; | ||
|
|
||
| async function getPullRequestState(pullNumber) { | ||
| const result = await withRetry( | ||
| `Read pull request #${pullNumber}`, | ||
| () => | ||
| github.graphql(pullRequestQuery, { | ||
| owner, | ||
| repo, | ||
| number: pullNumber, | ||
| }) | ||
| ); | ||
| return result.repository.pullRequest; | ||
| } | ||
|
|
||
| function hasApprovalLabel(pullRequest) { | ||
| return pullRequest.labels.nodes.some( | ||
| (label) => | ||
| label.name.toLowerCase() === approvalLabel.toLowerCase() | ||
| ); | ||
| } | ||
|
|
||
| async function getLatestFullSingleStatus(sha) { | ||
| const statuses = await withRetry( | ||
| `Read commit statuses for ${sha}`, | ||
| () => | ||
| github.paginate( | ||
| github.rest.repos.listCommitStatusesForRef, | ||
| { | ||
| owner, | ||
| repo, | ||
| ref: sha, | ||
| per_page: 100, | ||
| } | ||
| ) | ||
| ); | ||
| return statuses.find( | ||
| (status) => status.context === fullSingleStatus | ||
| ); | ||
| } | ||
|
|
||
| async function findSuccessfulFullSingleStatus(pullNumber) { | ||
| const commits = await withRetry( | ||
| `Read commits for pull request #${pullNumber}`, | ||
| () => | ||
| github.paginate(github.rest.pulls.listCommits, { | ||
| owner, | ||
| repo, | ||
| pull_number: pullNumber, | ||
| per_page: 100, | ||
| }) | ||
| ); | ||
| const commitShas = commits.map((commit) => commit.sha).reverse(); | ||
| const triggeringSha = | ||
| context.eventName === 'status' ? context.payload.sha : null; | ||
|
|
||
| if (triggeringSha && commitShas.includes(triggeringSha)) { | ||
| commitShas.splice(commitShas.indexOf(triggeringSha), 1); | ||
| commitShas.unshift(triggeringSha); | ||
| } | ||
|
|
||
| for (const sha of commitShas) { | ||
| const status = await getLatestFullSingleStatus(sha); | ||
| if (status?.state === 'success') { | ||
| return sha; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| const pullNumbers = await getCandidatePullRequests(); | ||
| if (pullNumbers.length === 0) { | ||
| console.log('No open pull request is associated with this event.'); | ||
| return; | ||
| } | ||
|
|
||
| for (const pullNumber of pullNumbers) { | ||
| const initialState = await getPullRequestState(pullNumber); | ||
| if (!initialState || initialState.state !== 'OPEN') { | ||
| console.log(`PR #${pullNumber} is not open; skipping.`); | ||
| continue; | ||
| } | ||
| if (hasApprovalLabel(initialState)) { | ||
| console.log(`PR #${pullNumber} already has the approval label.`); | ||
| continue; | ||
| } | ||
| if (initialState.reviewDecision !== 'APPROVED') { | ||
| console.log(`PR #${pullNumber} is not fully approved; skipping.`); | ||
| continue; | ||
| } | ||
|
|
||
| const successfulCommit = | ||
| await findSuccessfulFullSingleStatus(pullNumber); | ||
| if (!successfulCommit) { | ||
| console.log( | ||
| `PR #${pullNumber} has no successful ${fullSingleStatus} status in its current commit history.` | ||
| ); | ||
| continue; | ||
| } | ||
|
|
||
| const finalState = await getPullRequestState(pullNumber); | ||
| if (!finalState || finalState.state !== 'OPEN') { | ||
| console.log(`PR #${pullNumber} is no longer open; skipping.`); | ||
| continue; | ||
| } | ||
| if (hasApprovalLabel(finalState)) { | ||
| console.log(`PR #${pullNumber} already has the approval label.`); | ||
| continue; | ||
| } | ||
| if (finalState.reviewDecision !== 'APPROVED') { | ||
| console.log(`PR #${pullNumber} is no longer fully approved; skipping.`); | ||
| continue; | ||
| } | ||
| if (finalState.headRefOid !== initialState.headRefOid) { | ||
| console.log(`PR #${pullNumber} changed during validation; skipping.`); | ||
| continue; | ||
| } | ||
|
|
||
| await withRetry(`Add approval label to PR #${pullNumber}`, () => | ||
| github.rest.issues.addLabels({ | ||
| owner, | ||
| repo, | ||
| issue_number: pullNumber, | ||
| labels: [approvalLabel], | ||
| }) | ||
| ); | ||
| console.log( | ||
| `Added ${approvalLabel} to PR #${pullNumber}; ${fullSingleStatus} succeeded on ${successfulCommit}.` | ||
| ); | ||
| } | ||
Oops, something went wrong.
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.