Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 56 additions & 10 deletions .github/workflows/array-stack-check.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by Array CLI - https://github.com/posthog/array
# Blocks PRs until their downstack dependencies are merged
# Blocks stacked PRs until their downstack dependencies are merged
# Only runs for PRs managed by Array (detected via stack comment marker)

name: Stack Check

Expand All @@ -9,21 +10,44 @@ on:
pull_request_target:
types: [closed]

permissions:
contents: read

jobs:
check:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
permissions:
pull-requests: read
issues: read
steps:
- name: Check stack dependencies
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request;

// Check if this is an Array-managed PR by looking for stack comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number
});

const isArrayPR = comments.some(c =>
c.body.includes('<!-- array-stack-comment -->')
);

if (!isArrayPR) {
console.log('Not an Array PR, skipping');
return;
}

const baseBranch = pr.base.ref;
const trunk = ['main', 'master', 'develop'];

if (trunk.includes(baseBranch)) {
console.log('Base is trunk, no dependencies');
console.log('Base is trunk, no dependencies');
return;
}

Expand Down Expand Up @@ -55,18 +79,42 @@ jobs:
const list = blockers.map(b => `#${b.number} (${b.title})`).join('\n - ');
core.setFailed(`Blocked by:\n - ${list}\n\nMerge these PRs first (bottom to top).`);
} else {
console.log('All dependencies merged, ready to merge');
console.log('All dependencies merged, ready to merge');
}

recheck-dependents:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request_target' && github.event.action == 'closed' && github.event.pull_request.merged == true
if: >-
github.event_name == 'pull_request_target' &&
github.event.action == 'closed' &&
github.event.pull_request.merged == true
permissions:
pull-requests: write
issues: read
steps:
- name: Trigger recheck of dependent PRs
uses: actions/github-script@v7
with:
script: |
const mergedBranch = context.payload.pull_request.head.ref;
const pr = context.payload.pull_request;

// Check if this is an Array-managed PR
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number
});

const isArrayPR = comments.some(c =>
c.body.includes('<!-- array-stack-comment -->')
);

if (!isArrayPR) {
console.log('Not an Array PR, skipping');
return;
}

const mergedBranch = pr.head.ref;

const { data: dependentPRs } = await github.rest.pulls.list({
owner: context.repo.owner,
Expand All @@ -75,14 +123,12 @@ jobs:
state: 'open'
});

for (const pr of dependentPRs) {
console.log(`Re-checking PR #${pr.number}`);

// Update base to main since the branch will be deleted
for (const dependentPR of dependentPRs) {
console.log(`Re-checking PR #${dependentPR.number}`);
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
pull_number: dependentPR.number,
base: 'main'
});
}