Skip to content

Commit cd40b34

Browse files
johntmyersdrew
authored andcommitted
fix(ci): split vouch gate into two steps with separate tokens (#446)
The ORG_READ_TOKEN (read:org PAT) was being used for all API calls, including closing PRs and posting comments, which it lacks permissions for. Split into two steps: 1. Org membership check — uses ORG_READ_TOKEN exclusively 2. VOUCHED.td check + close — uses default GITHUB_TOKEN (has repo write) Step 2 is skipped entirely if step 1 confirms org membership. Co-authored-by: John Myers <johntmyers@users.noreply.github.com>
1 parent df2233f commit cd40b34

File tree

1 file changed

+19
-30
lines changed

1 file changed

+19
-30
lines changed

.github/workflows/vouch-check.yml

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,54 +13,43 @@ jobs:
1313
if: github.repository_owner == 'NVIDIA'
1414
runs-on: ubuntu-latest
1515
steps:
16-
- name: Check if contributor is vouched
16+
- name: Check org membership
17+
id: org-check
18+
if: ${{ secrets.ORG_READ_TOKEN != '' }}
1719
uses: actions/github-script@v7
1820
with:
19-
github-token: ${{ secrets.ORG_READ_TOKEN || secrets.GITHUB_TOKEN }}
21+
github-token: ${{ secrets.ORG_READ_TOKEN }}
22+
result-encoding: string
2023
script: |
2124
const author = context.payload.pull_request.user.login;
22-
const authorType = context.payload.pull_request.user.type;
23-
24-
// Skip bots (dependabot, renovate, github-actions, etc.).
25-
if (authorType === 'Bot') {
26-
console.log(`${author} is a bot. Skipping vouch check.`);
27-
return;
28-
}
29-
30-
// Check org membership. Requires a token with read:org scope
31-
// (ORG_READ_TOKEN secret). The default GITHUB_TOKEN cannot see org
32-
// membership, so author_association and orgs.checkMembershipForUser
33-
// both return NONE/404 for private members.
3425
try {
3526
const { status } = await github.rest.orgs.checkMembershipForUser({
3627
org: context.repo.owner,
3728
username: author,
3829
});
3930
if (status === 204 || status === 302) {
4031
console.log(`${author} is an org member. Skipping vouch check.`);
41-
return;
32+
return 'skip';
4233
}
4334
} catch (e) {
4435
if (e.status !== 404) {
4536
console.log(`Org membership check error (status=${e.status}): ${e.message}`);
4637
}
4738
}
39+
return '';
4840
49-
// Check collaborator status — direct collaborators bypass.
50-
try {
51-
const { status } = await github.rest.repos.checkCollaborator({
52-
owner: context.repo.owner,
53-
repo: context.repo.repo,
54-
username: author,
55-
});
56-
if (status === 204) {
57-
console.log(`${author} is a repo collaborator. Skipping vouch check.`);
58-
return;
59-
}
60-
} catch (e) {
61-
if (e.status !== 404) {
62-
console.log(`Collaborator check error (status=${e.status}): ${e.message}`);
63-
}
41+
- name: Check if contributor is vouched
42+
if: steps.org-check.outputs.result != 'skip'
43+
uses: actions/github-script@v7
44+
with:
45+
script: |
46+
const author = context.payload.pull_request.user.login;
47+
const authorType = context.payload.pull_request.user.type;
48+
49+
// Skip bots (dependabot, renovate, github-actions, etc.).
50+
if (authorType === 'Bot') {
51+
console.log(`${author} is a bot. Skipping vouch check.`);
52+
return;
6453
}
6554
6655
// Check the VOUCHED.td file on the dedicated "vouched" branch.

0 commit comments

Comments
 (0)