Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(ci): narrow visual regression outside merge queue (#83266)

Paul D'Ambra6de94c639f18
diff --git a/.github/workflows/ci-storybook.yml b/.github/workflows/ci-storybook.yml
index c08c6c999a2f..e8249157ae50 100644
--- a/.github/workflows/ci-storybook.yml
+++ b/.github/workflows/ci-storybook.yml
@@ -1,10 +1,10 @@
name: Storybook
on:
pull_request:
- # Draft PRs run a narrowed visual-regression matrix when the Storybook module
- # graph can safely identify affected stories. Ready PRs run the full chromium
- # matrix as the merge gate. To force the full matrix on a draft, add the
- # `run-ci-frontend` label. The `no-ci` label does the opposite: it silences
+ # PRs outside the merge queue run a narrowed visual-regression matrix when the
+ # Storybook module graph can safely identify affected stories. Merge-queue runs
+ # use the full matrix. To force the full matrix earlier, add the `run-ci-frontend`
+ # label. The `no-ci` label does the opposite: it silences
# this workflow on a draft entirely (prototypes).
# No labeled/unlabeled triggers: GitHub cannot filter a label trigger by name,
# so every unrelated label re-ran the full chromium matrix against a commit CI
@@ -298,8 +298,8 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 5
needs: [changes, build-storybook, select-stories]
- # A status function is required because select-stories is skipped on ready PRs
- # and master pushes, and GitHub would otherwise cascade that skip to this job.
+ # A status function is required because select-stories is skipped on forced-full
+ # PRs and master pushes, and GitHub would otherwise cascade that skip to this job.
# !cancelled() rather than always() so a superseded run stops here instead of
# creating a Visual Review run that its cancelled matrix will never complete.
if: |
@@ -392,8 +392,8 @@ jobs:
name: Visual regression tests - ${{ matrix.browser }} (${{ matrix.shard }}/${{ matrix.shard_count }})
runs-on: ${{ matrix.browser == 'webkit' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
needs: [changes, build-storybook, vr-setup, select-stories]
- # A status function is required because select-stories is skipped on ready PRs
- # and master pushes. !cancelled() rather than always() so a superseded run's
+ # A status function is required because select-stories is skipped on forced-full
+ # PRs and master pushes. !cancelled() rather than always() so a superseded run's
# browser shards stop promptly instead of running the full 30-minute matrix.
if: >-
!cancelled()
@@ -408,9 +408,9 @@ jobs:
fail-fast: false
# Shard counts and worker config (maxWorkers in common/storybook/package.json)
# are tuned for runner CPU — consult #team-devex before changing.
- # Draft PRs may use chromium shards running only affected story files.
- # Ready PRs fall back to changes.outputs.matrix (full chromium), while
- # master pushes run chromium + webkit.
+ # PRs may use chromium shards running only affected story files.
+ # Forced-full PRs fall back to changes.outputs.matrix (full chromium),
+ # while master pushes run chromium + webkit.
matrix: ${{ fromJson(needs.select-stories.outputs.matrix || needs.changes.outputs.matrix) }}
env:
NODE_OPTIONS: --max-old-space-size=16384
@@ -682,7 +682,7 @@ jobs:
# Collate matrix + VR completion status for the required check
visual_regression_tests:
- needs: [changes, build-storybook, visual-regression, vr-setup, vr-complete]
+ needs: [changes, build-storybook, select-stories, visual-regression, vr-setup, vr-complete]
name: Visual regression tests pass
runs-on: ubuntu-latest
timeout-minutes: 5
@@ -709,6 +709,11 @@ jobs:
exit 1
fi
+ if [[ "${{ needs.select-stories.result }}" != "success" && "${{ needs.select-stories.result }}" != "skipped" ]]; then
+ echo "Story selection did not succeed (result: ${{ needs.select-stories.result }}) — visual regression is uncovered."
+ exit 1
+ fi
+
if [[ "${{ needs.visual-regression.result }}" != "success" && "${{ needs.visual-regression.result }}" != "skipped" ]]; then
echo "One or more jobs in the visual-regression test matrix failed."
exit 1
@@ -851,8 +856,8 @@ jobs:
needs: [select-stories]
runs-on: ubuntu-latest
timeout-minutes: 5
- # select-stories only runs on internal draft PRs; fire only when it produced a
- # decision. DevEx project only; continue-on-error so telemetry never reds CI.
+ # select-stories skips merge-queue and forced-full runs. Fire only when it
+ # produced a decision. DevEx project only; continue-on-error so telemetry never reds CI.
if: |
!cancelled() && github.run_attempt == '1'
&& github.actor != 'dependabot[bot]'
@@ -882,23 +887,19 @@ jobs:
"run_id": ${{ toJSON(github.run_id) }}
}
- # Pick a narrowed visual-regression matrix for draft PRs based on which stories
- # the Vite module graph says are affected by the diff. Ready PRs and drafts with
- # the run-ci-frontend label skip this job and use the full chromium matrix.
- # Selector uncertainty skips draft visual regression because the ready run is
- # still the merge gate.
+ # Pick a narrowed visual-regression matrix for PRs based on which stories the Vite
+ # module graph says are affected by the diff. Merge-queue runs and PRs with the
+ # run-ci-frontend label skip this job and use the full chromium matrix. Selector
+ # uncertainty also falls back to the full matrix.
select-stories:
name: Story selection
runs-on: ubuntu-latest
timeout-minutes: 5
needs: [changes, build-storybook]
- # Trunk's merge-queue branches open as draft PRs, but their run IS the
- # merge gate, so they must never get the narrowed selection.
if: |
!cancelled() && needs.changes.outputs.frontend == 'true'
&& github.event_name == 'pull_request'
- && github.event.pull_request.draft == true
- && !startsWith(github.head_ref, 'trunk-merge/')
+ && needs.changes.outputs.merge_queue != 'true'
&& !contains(github.event.pull_request.labels.*.name, 'run-ci-frontend')
outputs:
mode: ${{ steps.classify.outputs.mode }}
@@ -920,6 +921,17 @@ jobs:
ref: ${{ github.event.pull_request.head.sha }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
+ - name: Check out trusted story selector
+ uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
+ with:
+ filter: blob:none
+ fetch-depth: 1
+ path: story-selector
+ ref: ${{ github.event.pull_request.base.ref }}
+ repository: ${{ github.event.pull_request.base.repo.full_name }}
+ sparse-checkout: bin/find-affected-stories
+ sparse-checkout-cone-mode: false
+
- name: Mint setup-action GitHub token
id: setup-gh-token
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
@@ -948,18 +960,18 @@ jobs:
continue-on-error: true
env:
BASE_REF: ${{ github.event.pull_request.base.ref }}
+ BASE_REPO: ${{ github.event.pull_request.base.repo.full_name }}
run: |
- # Fetch the *current* tip of the base branch, not pull_request.base.sha —
- # base.sha is captured at webhook time and goes stale if the branch later
- # merges a newer master, which makes `base.sha...HEAD` balloon to include
- # every merged-in master change.
- git fetch --no-tags origin "$BASE_REF"
+ BASE_SHA=$(git -C story-selector rev-parse HEAD)
+ git fetch --no-tags --depth=500 --filter=blob:none \
+ "${{ github.server_url }}/$BASE_REPO.git" \
+ "$BASE_SHA:refs/remotes/base/$BASE_REF"
echo "### Changed files" >&2
- git diff --name-only "origin/$BASE_REF"...HEAD >&2
+ git diff --name-only "base/$BASE_REF"...HEAD >&2
- RESULT=$(bin/find-affected-stories \
+ RESULT=$(story-selector/bin/find-affected-stories \
--graph /tmp/storybook-graph/module-graph.json \
- --base-ref "origin/$BASE_REF")
+ --base-ref "base/$BASE_REF")
echo "$RESULT" > /tmp/selection-result.json
# Stash compact form in step output (single line) for the summary step.
COMPACT=$(node -e 'const d = JSON.parse(require("fs").readFileSync("/tmp/selection-result.json", "utf8")); delete d.affected_stories; delete d.unresolved_changed_files; process.stdout.write(JSON.stringify(d))')
@@ -991,24 +1003,23 @@ jobs:
} >> "$GITHUB_OUTPUT"
}
- fall_back_to_skip() {
- echo "mode=skip" >> "$GITHUB_OUTPUT"
- echo 'matrix={"include":[]}' >> "$GITHUB_OUTPUT"
- echo "should_run=false" >> "$GITHUB_OUTPUT"
+ fall_back_to_full() {
+ echo "mode=full" >> "$GITHUB_OUTPUT"
+ echo "should_run=true" >> "$GITHUB_OUTPUT"
echo "affected_files_json=[]" >> "$GITHUB_OUTPUT"
emit_metrics false "$1"
}
if [[ "$SELECT_OUTCOME" != "success" ]] || [[ ! -s /tmp/selection-result.json ]]; then
- echo "::warning::story selector did not produce output; skipping draft visual regression"
- fall_back_to_skip selector_error
+ echo "::warning::story selector did not produce output; running the full visual regression matrix"
+ fall_back_to_full selector_error
exit 0
fi
MODE=$(jq -r '.mode' /tmp/selection-result.json)
if [[ "$MODE" != "selective" ]]; then
- echo "Selector declined to narrow (mode=$MODE); skipping draft visual regression"
- fall_back_to_skip "$(jq -r '.reason // "full_requested"' /tmp/selection-result.json)"
+ echo "Selector declined to narrow (mode=$MODE); running the full visual regression matrix"
+ fall_back_to_full "$(jq -r '.reason // "full_requested"' /tmp/selection-result.json)"
exit 0
fi
@@ -1019,7 +1030,7 @@ jobs:
echo "should_run=false" >> "$GITHUB_OUTPUT"
echo "affected_files_json=[]" >> "$GITHUB_OUTPUT"
emit_metrics true no_affected_stories
- echo "Selective mode: 0 affected stories, skipping draft visual regression"
+ echo "Selective mode: 0 affected stories, skipping visual regression"
exit 0
fi