Skip to content

Commit a26a1d6

Browse files
authored
[ci] Avoid running full CI mid-stack for GH-native stacks, same as we do for Graphite (#95218)
Running CI only on the top and bottom of the stack avoids expensive `O(n^2)` behavior when merging one PR at a time and recursively rebasing all the others starting at the bottom of the stack. GitHub added this to the webhook/GH actions object for us to be able to do this: https://vercel.slack.com/archives/C01SKER9S1G/p1777926655162839 Prior to this PR being part of a stack, fails open (runs full CI): <img width="1938" height="993" alt="Screenshot 2026-06-26 at 3 03 37 PM" src="https://github.com/user-attachments/assets/54d6055a-2860-45b3-a03a-a9356b3db2a4" /> Example mid-stack run (skips the full e2e jobs): <img width="1917" height="664" alt="Screenshot 2026-06-26 at 3 24 33 PM" src="https://github.com/user-attachments/assets/9ee466da-f3ea-4298-b5b8-2527d197c121" /> https://github.com/vercel/next.js/actions/runs/28268549361/job/83760907003?pr=95219
1 parent 41114a3 commit a26a1d6

2 files changed

Lines changed: 33 additions & 9 deletions

File tree

‎.github/workflows/build_and_test.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ env:
2222

2323
jobs:
2424
optimize-ci:
25-
uses: ./.github/workflows/graphite_ci_optimizer.yml
25+
uses: ./.github/workflows/pr_stack_optimizer.yml
2626
secrets: inherit
2727

2828
changes:

.github/workflows/graphite_ci_optimizer.yml renamed to .github/workflows/pr_stack_optimizer.yml

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
# Avoid running the full CI on mid-stack PRs: https://graphite.dev/docs/stacking-and-ci
22
#
3-
# We still run some high-signal low-cost jobs (e.g. lint, unit tests) on these mid-stack PRs, just
4-
# not anything slow (e.g. integration tests).
3+
# This supports both Graphite stacks and GitHub's native stacked PRs. For either kind of stack, we
4+
# only run the full CI on the very top and very bottom of the stack.
5+
#
6+
# We still run some high-signal low-cost jobs (e.g. lint, unit tests) on mid-stack PRs, just not
7+
# anything slow (e.g. integration tests).
58
#
69
# Because we don't use Graphite's CI batching, full CI will still run on every PR individually
710
# before it merges. The goal is just to avoid wasting CI capacity when frequently rebasing large
811
# stacks.
912
#
10-
# This can by bypassed by labeling a PR with 'CI Bypass Graphite Optimization', and manually
11-
# re-running CI.
13+
# This can by bypassed by labeling a PR with 'CI Bypass PR Stack Optimization' (or the legacy
14+
# 'CI Bypass Graphite Optimization' label), and manually re-running CI.
1215

13-
name: Graphite CI Optimizer
16+
name: PR Stack Optimizer
1417
on:
1518
workflow_call:
1619
outputs:
@@ -29,16 +32,34 @@ env:
2932
HAS_BYPASS_LABEL: |-
3033
${{
3134
github.event_name == 'pull_request' &&
32-
contains(github.event.pull_request.labels.*.name, 'CI Bypass Graphite Optimization')
35+
(
36+
contains(github.event.pull_request.labels.*.name, 'CI Bypass PR Stack Optimization') ||
37+
contains(github.event.pull_request.labels.*.name, 'CI Bypass Graphite Optimization')
38+
)
39+
}}
40+
# GitHub's native stacked PRs expose the PR's position within the stack. We skip expensive CI on
41+
# mid-stack PRs. Fail open if we don't have `stack.size`.
42+
IS_MID_STACK_NATIVE: |-
43+
${{
44+
github.event_name == 'pull_request' &&
45+
github.event.pull_request.stack.size != '' &&
46+
github.event.pull_request.stack.position != 1 &&
47+
github.event.pull_request.stack.position != github.event.pull_request.stack.size
3348
}}
3449
jobs:
3550
optimize-ci:
36-
name: Graphite CI Optimizer
51+
name: PR Stack Optimizer
3752
runs-on: ubuntu-latest
3853
outputs:
3954
# `== 'true'` comparison: If `step.check-skip` fails (`continue-on-error`), that output will
4055
# be an empty string, which sets our `skip` output to `'false'`.
41-
skip: ${{ env.HAS_BYPASS_LABEL == 'false' && steps.check-skip.outputs.skip == 'true' }}
56+
#
57+
# We skip if either Graphite's optimizer says to skip, or the PR is a mid-stack PR in a
58+
# GitHub native stack. The bypass label overrides both.
59+
skip: |-
60+
${{ env.HAS_BYPASS_LABEL == 'false' && (
61+
steps.check-skip.outputs.skip == 'true' || env.IS_MID_STACK_NATIVE == 'true'
62+
) }}
4263
steps:
4364
- name: Optimize CI
4465
id: check-skip
@@ -52,6 +73,9 @@ jobs:
5273
echo 'github.event_name: ${{ github.event_name }}'
5374
echo "secrets.GRAPHITE_CI_OPTIMIZER_TOKEN != '': ${GRAPHITE_CI_OPTIMIZER_TOKEN_NON_EMPTY}"
5475
echo 'env.HAS_BYPASS_LABEL: ${{ env.HAS_BYPASS_LABEL }}'
76+
echo 'env.IS_MID_STACK_NATIVE: ${{ env.IS_MID_STACK_NATIVE }}'
77+
echo 'github.event.pull_request.stack.position: ${{ github.event.pull_request.stack.position }}'
78+
echo 'github.event.pull_request.stack.size: ${{ github.event.pull_request.stack.size }}'
5579
echo 'steps.check-skip.outputs.skip: ${{ steps.check-skip.outputs.skip }}'
5680
5781
env:

0 commit comments

Comments
 (0)