You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
See the [Webhooks reference](/gh-stack/reference/webhooks/) for the full details on the `stack` object in webhook payloads, or the [REST API reference](/gh-stack/reference/rest-api/) to read the same object on demand from a pull request.
120
108
109
+
### How can I optimize CI usage for a stack?
110
+
111
+
Because a workflow runs for every PR in a stack, a large stack can multiply your CI usage. You can use the `stack` fields to selectively run jobs based on the position of the current PR in the stack.
112
+
113
+
Two conditions are especially useful for deciding where a job should run:
114
+
115
+
- **Lowest unmerged PR** — the PR currently at the bottom of the remaining stack. Because it targets the stack base directly, `github.event.pull_request.stack.base.ref` equals `github.event.pull_request.base.ref`.
116
+
- **Top PR** — the last PR in the stack, containing the full set of changes. It's the PR where `github.event.pull_request.stack.position` equals `github.event.pull_request.stack.size`.
117
+
118
+
```yaml
119
+
jobs:
120
+
build:
121
+
runs-on: ubuntu-latest
122
+
steps:
123
+
- uses: actions/checkout@v4
124
+
125
+
- name: Run for the lowest unmerged PR in the stack
As PRs merge from the bottom up, the lowest unmerged PR changes: once the bottom PR lands, the next PR is rebased to target the stack base directly, so it becomes the new lowest unmerged PR on the following workflow run. You can also gate on the original bottom PR with `github.event.pull_request.stack.position == 1`, or on any specific layer using `position`.
135
+
121
136
### Do all previous PRs need to be passing checks before I can merge?
122
137
123
138
Yes. In order to merge a PR in the stack, **all PRs below it** must also have passing checks and meet all merge requirements. For example, in a stack of `main <- PR1 <- PR2 <- PR3`, if you want to merge PR #3, both PR #1 and PR #2 must have passing checks, required reviews, and satisfy all branch protection rules.
Copy file name to clipboardExpand all lines: docs/src/content/docs/reference/webhooks.md
+22Lines changed: 22 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -106,3 +106,25 @@ The top-level `stack` object is unique to the `stacked` event; other `pull_reque
106
106
GitHub Actions automatically evaluates workflow triggers using the stack's base branch. If a PR is part of a stack targeting `main`, any workflow configured to run on pull requests targeting `main` will run for every PR in the stack — no workflow changes are required.
107
107
108
108
The `stack` object is also available in GitHub Actions workflow expressions via `github.event.pull_request.stack`. See [How do I access stack metadata in my GitHub Actions workflow?](/gh-stack/faq/#how-do-i-access-stack-metadata-in-my-github-actions-workflow) in the FAQ for examples.
109
+
110
+
### Optimizing CI usage
111
+
112
+
Because a workflow runs for every PR in a stack, you can use the `stack` fields to selectively run jobs. For example, if you only plan on merging one PR at a time, you can choose to only run CI for the lowest unmerged PR. Compare the stack's base ref to the PR's own base ref to detect the **lowest unmerged PR**, and compare `position` to `size` to detect the **top PR**:
113
+
114
+
```yaml
115
+
jobs:
116
+
build:
117
+
runs-on: ubuntu-latest
118
+
steps:
119
+
- uses: actions/checkout@v4
120
+
121
+
- name: Run for the lowest unmerged PR in the stack
0 commit comments