11# Generated by Array CLI - https://github.com/posthog/array
2- # Blocks PRs until their downstack dependencies are merged
2+ # Blocks stacked PRs until their downstack dependencies are merged
3+ # Only runs for PRs managed by Array (detected via stack comment marker)
34
45name : Stack Check
56
910 pull_request_target :
1011 types : [closed]
1112
13+ permissions :
14+ contents : read
15+
1216jobs :
1317 check :
1418 runs-on : ubuntu-latest
1519 if : github.event_name == 'pull_request'
20+ permissions :
21+ pull-requests : read
22+ issues : read
1623 steps :
1724 - name : Check stack dependencies
1825 uses : actions/github-script@v7
1926 with :
2027 script : |
2128 const pr = context.payload.pull_request;
29+
30+ // Check if this is an Array-managed PR by looking for stack comment
31+ const { data: comments } = await github.rest.issues.listComments({
32+ owner: context.repo.owner,
33+ repo: context.repo.repo,
34+ issue_number: pr.number
35+ });
36+
37+ const isArrayPR = comments.some(c =>
38+ c.body.includes('<!-- array-stack-comment -->')
39+ );
40+
41+ if (!isArrayPR) {
42+ console.log('Not an Array PR, skipping');
43+ return;
44+ }
45+
2246 const baseBranch = pr.base.ref;
2347 const trunk = ['main', 'master', 'develop'];
2448
2549 if (trunk.includes(baseBranch)) {
26- console.log('✓ Base is trunk, no dependencies');
50+ console.log('Base is trunk, no dependencies');
2751 return;
2852 }
2953
@@ -55,18 +79,42 @@ jobs:
5579 const list = blockers.map(b => `#${b.number} (${b.title})`).join('\n - ');
5680 core.setFailed(`Blocked by:\n - ${list}\n\nMerge these PRs first (bottom to top).`);
5781 } else {
58- console.log('✓ All dependencies merged, ready to merge');
82+ console.log('All dependencies merged, ready to merge');
5983 }
6084
6185 recheck-dependents :
6286 runs-on : ubuntu-latest
63- if : github.event_name == 'pull_request_target' && github.event.action == 'closed' && github.event.pull_request.merged == true
87+ if : >-
88+ github.event_name == 'pull_request_target' &&
89+ github.event.action == 'closed' &&
90+ github.event.pull_request.merged == true
91+ permissions :
92+ pull-requests : write
93+ issues : read
6494 steps :
6595 - name : Trigger recheck of dependent PRs
6696 uses : actions/github-script@v7
6797 with :
6898 script : |
69- const mergedBranch = context.payload.pull_request.head.ref;
99+ const pr = context.payload.pull_request;
100+
101+ // Check if this is an Array-managed PR
102+ const { data: comments } = await github.rest.issues.listComments({
103+ owner: context.repo.owner,
104+ repo: context.repo.repo,
105+ issue_number: pr.number
106+ });
107+
108+ const isArrayPR = comments.some(c =>
109+ c.body.includes('<!-- array-stack-comment -->')
110+ );
111+
112+ if (!isArrayPR) {
113+ console.log('Not an Array PR, skipping');
114+ return;
115+ }
116+
117+ const mergedBranch = pr.head.ref;
70118
71119 const { data: dependentPRs } = await github.rest.pulls.list({
72120 owner: context.repo.owner,
@@ -75,14 +123,12 @@ jobs:
75123 state: 'open'
76124 });
77125
78- for (const pr of dependentPRs) {
79- console.log(`Re-checking PR #${pr.number}`);
80-
81- // Update base to main since the branch will be deleted
126+ for (const dependentPR of dependentPRs) {
127+ console.log(`Re-checking PR #${dependentPR.number}`);
82128 await github.rest.pulls.update({
83129 owner: context.repo.owner,
84130 repo: context.repo.repo,
85- pull_number: pr .number,
131+ pull_number: dependentPR .number,
86132 base: 'main'
87133 });
88134 }
0 commit comments