Skip to content

Commit 169dad6

Browse files
authored
fix: watch-pr-ci exits with false FAILURE when draft-to-ready cancels superseded runs (#113230)
* fix(scripts): ignore superseded workflow runs in watch-pr-ci rollup classification Draft->ready re-triggers leave cancelled superseded runs on the head SHA forever, and GitHub's aggregate rollup state counts them, so the watcher emitted terminal FAILURE while the replacement run was still in progress and could never reach GREEN (observed on PR #113150, head bd1b9a0). - fetch run identity per check and resolve same-name checks to the newest run/check id (GitHub latest-name-wins); drop cancelled checks from replaced runs; keep older runs' unique jobs visible - paginate statusCheckRollup contexts (bounded, 10 pages) so >100-context rollups are not truncation-blind; changed or lost snapshots throw into the bounded retry - classify GREEN when aggregate FAILURE is explained solely by superseded contexts with full visibility; truncation still fails conservatively * ci: scope GitHub App token permissions in stale, labeler, auto-response, and pr-ci-sweeper Fixes red main: #112963 bumped zizmor v1.22.0 -> v1.28.0, whose github-app audit flags create-github-app-token mints without permission-* inputs (14 high findings, Workflow Sanity red on main since 3b7b2a2). Most workflows already migrated to scoped tokens; these four were stragglers. Scopes follow each consumer's actual API surface: stale needs issues/PR write plus actions read for its state-cache check; labeler needs label CRUD (issues write), PR write, members read for maintainer gates, and contents read where actions/labeler reads its config; auto-response needs issues/PR write plus members read; pr-ci-sweeper needs actions write to re-fire runs, checks read, and PR write. Verified locally with the exact CI invocation (zizmor 1.28.0, repo config, regular persona, medium severity/confidence): no findings, ignore/suppress counts match CI.
1 parent 2b7622d commit 169dad6

7 files changed

Lines changed: 642 additions & 44 deletions

File tree

‎.github/workflows/auto-response.yml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,18 @@ jobs:
3535
with:
3636
app-id: "2729701"
3737
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
38+
permission-issues: write
39+
permission-members: read
40+
permission-pull-requests: write
3841
- uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3
3942
id: app-token-fallback
4043
if: steps.app-token.outcome == 'failure'
4144
with:
4245
app-id: "2971289"
4346
private-key: ${{ secrets.GH_APP_PRIVATE_KEY_FALLBACK }}
47+
permission-issues: write
48+
permission-members: read
49+
permission-pull-requests: write
4450
- name: Run Barnacle auto-response
4551
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
4652
with:

‎.github/workflows/labeler.yml‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,20 @@ jobs:
4747
with:
4848
app-id: "2729701"
4949
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
50+
permission-contents: read
51+
permission-issues: write
52+
permission-members: read
53+
permission-pull-requests: write
5054
- uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3
5155
id: app-token-fallback
5256
if: steps.app-token.outcome == 'failure'
5357
with:
5458
app-id: "2971289"
5559
private-key: ${{ secrets.GH_APP_PRIVATE_KEY_FALLBACK }}
60+
permission-contents: read
61+
permission-issues: write
62+
permission-members: read
63+
permission-pull-requests: write
5664
- uses: actions/labeler@b8dd2d9be0f68b860e7dae5dae7d772984eacd6d # v6
5765
if: ${{ github.event.action != 'edited' || github.event.changes.base }}
5866
with:
@@ -486,12 +494,18 @@ jobs:
486494
with:
487495
app-id: "2729701"
488496
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
497+
permission-issues: write
498+
permission-members: read
499+
permission-pull-requests: write
489500
- uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3
490501
id: app-token-fallback
491502
if: steps.app-token.outcome == 'failure'
492503
with:
493504
app-id: "2971289"
494505
private-key: ${{ secrets.GH_APP_PRIVATE_KEY_FALLBACK }}
506+
permission-issues: write
507+
permission-members: read
508+
permission-pull-requests: write
495509
- name: Backfill PR labels
496510
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
497511
with:
@@ -785,12 +799,16 @@ jobs:
785799
with:
786800
app-id: "2729701"
787801
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
802+
permission-issues: write
803+
permission-members: read
788804
- uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3
789805
id: app-token-fallback
790806
if: steps.app-token.outcome == 'failure'
791807
with:
792808
app-id: "2971289"
793809
private-key: ${{ secrets.GH_APP_PRIVATE_KEY_FALLBACK }}
810+
permission-issues: write
811+
permission-members: read
794812
- name: Apply maintainer or trusted-contributor label
795813
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
796814
with:

‎.github/workflows/pr-ci-sweeper.yml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,18 @@ jobs:
4040
with:
4141
app-id: "2729701"
4242
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
43+
permission-actions: write
44+
permission-checks: read
45+
permission-pull-requests: write
4346
- uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3
4447
id: app-token-fallback
4548
if: steps.app-token.outcome == 'failure'
4649
with:
4750
app-id: "2971289"
4851
private-key: ${{ secrets.GH_APP_PRIVATE_KEY_FALLBACK }}
52+
permission-actions: write
53+
permission-checks: read
54+
permission-pull-requests: write
4955
- name: Sweep dropped PR CI runs
5056
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
5157
with:

‎.github/workflows/stale.yml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,18 @@ jobs:
5050
with:
5151
app-id: "2729701"
5252
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
53+
permission-actions: read
54+
permission-issues: write
55+
permission-pull-requests: write
5356
- uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3
5457
id: app-token-fallback
5558
continue-on-error: true
5659
with:
5760
app-id: "2971289"
5861
private-key: ${{ secrets.GH_APP_PRIVATE_KEY_FALLBACK }}
62+
permission-actions: read
63+
permission-issues: write
64+
permission-pull-requests: write
5965
- name: Mark stale unassigned issues and pull requests (primary)
6066
id: stale-primary
6167
continue-on-error: true
@@ -252,6 +258,8 @@ jobs:
252258
with:
253259
app-id: "2971289"
254260
private-key: ${{ secrets.GH_APP_PRIVATE_KEY_FALLBACK }}
261+
permission-issues: write
262+
permission-pull-requests: write
255263
- name: Backfill stale closures
256264
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
257265
env:
@@ -500,6 +508,7 @@ jobs:
500508
with:
501509
app-id: "2729701"
502510
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
511+
permission-issues: write
503512
- name: Lock closed issues after 48h of no activity
504513
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
505514
with:

‎scripts/watch-pr-ci.d.mts‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,38 @@ export interface WatchPrCiArgs {
1010

1111
export interface RollupCheck {
1212
kind: "CheckRun" | "StatusContext";
13+
databaseId?: number;
1314
name?: string;
1415
context?: string;
1516
status?: string;
1617
conclusion?: string | null;
1718
state?: string;
19+
checkSuite?: {
20+
workflowRun?: { databaseId?: number; workflow?: { databaseId?: number } } | null;
21+
} | null;
1822
}
1923

2024
export interface RollupPayload {
2125
state?: string;
22-
contexts?: { totalCount?: number; nodes?: RollupCheck[] };
26+
contexts?: {
27+
totalCount?: number;
28+
nodes?: RollupCheck[];
29+
pageInfo?: { hasNextPage?: boolean; endCursor?: string | null };
30+
};
31+
}
32+
33+
export interface RollupPage {
34+
state?: string;
35+
mergeable?: boolean | string;
36+
headRefOid?: string;
37+
statusCheckRollup?: RollupPayload | null;
2338
}
2439

2540
export interface RollupClassification {
2641
verdict: "GREEN" | "FAILING" | "PENDING" | "STALE-CANCELLED";
2742
pendingCount: number;
2843
failingNames: string[];
44+
supersededCount: number;
2945
}
3046

3147
export interface RunListItem {
@@ -54,6 +70,9 @@ export interface PollUntilDeadlineOptions<T> {
5470
export function parseArgs(argv: string[]): WatchPrCiArgs;
5571
export function sanitizeCheckName(name: string): string;
5672
export function classifyRollup(rollup: RollupPayload | null | undefined): RollupClassification;
73+
export function collectRollupContexts(
74+
fetchPage: (cursor: string | null) => RollupPage | null | undefined,
75+
): RollupPage | null | undefined;
5776
export function buildFindRunArgs(repo: string, sha: string): string[];
5877
export function selectRunAfter(runs: RunListItem[], after?: number): RunListItem | undefined;
5978
export function classifyRunAttachment(

0 commit comments

Comments
 (0)