Skip to content

Commit 39dcb79

Browse files
committed
ci: make Chromatic visual check a real approval gate
Set exitZeroOnChanges: false on the required visual-tests job so PRs with unaccepted visual changes fail the check until a maintainer accepts them in Chromatic and re-runs the job. Add a pull_request_target reporter that posts the required "Visual regression (Chromatic)" status as success for dev PRs that touch no UI code. This unblocks content-only PRs -- including fork PRs whose CI workflow is held for manual approval and therefore never reports the check (e.g. #18806).
1 parent 7b3f3b9 commit 39dcb79

2 files changed

Lines changed: 58 additions & 1 deletion

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Chromatic required status
2+
3+
# Satisfies the required "Visual regression (Chromatic)" status check for dev PRs
4+
# that touch no UI code. The CI `visual-tests` job is skipped for such PRs, and
5+
# for fork PRs the whole CI workflow is held for manual approval -- so without
6+
# this reporter the required check is never posted and the PR is blocked forever
7+
# (e.g. content-only fork PRs).
8+
#
9+
# Runs as pull_request_target so it executes in the base-repo context with a
10+
# token that can post commit statuses, without approval. It only reads the PR's
11+
# changed-file list -- it never checks out or executes fork code.
12+
13+
on:
14+
pull_request_target:
15+
branches: [dev]
16+
types: [opened, synchronize, reopened, ready_for_review]
17+
18+
permissions:
19+
contents: read
20+
pull-requests: read
21+
statuses: write
22+
23+
concurrency:
24+
group: chromatic-required-status-${{ github.event.pull_request.number }}
25+
cancel-in-progress: true
26+
27+
jobs:
28+
report:
29+
name: Report Chromatic status for non-UI PRs
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Mark non-UI PRs as passing
33+
env:
34+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
PR: ${{ github.event.pull_request.number }}
36+
SHA: ${{ github.event.pull_request.head.sha }}
37+
REPO: ${{ github.repository }}
38+
run: |
39+
set -euo pipefail
40+
41+
# Keep in sync with the `chromatic-gate` path filter in ci.yml.
42+
UI_REGEX='^(src/components/|src/layouts/|src/styles/|app/|\.storybook/|package\.json$|pnpm-lock\.yaml$)'
43+
44+
files=$(gh api --paginate "repos/${REPO}/pulls/${PR}/files" --jq '.[].filename')
45+
46+
if echo "$files" | grep -qE "$UI_REGEX"; then
47+
echo "UI files changed -- the CI visual-regression job owns the required check."
48+
exit 0
49+
fi
50+
51+
echo "No UI files changed -- reporting the required Chromatic check as passed."
52+
gh api "repos/${REPO}/statuses/${SHA}" \
53+
-f state=success \
54+
-f context='Visual regression (Chromatic)' \
55+
-f description='No UI changes — visual review not required'

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ jobs:
113113
uses: chromaui/action@v16
114114
with:
115115
projectToken: fee8e66c9916
116-
exitZeroOnChanges: true
116+
# Fail the check when unaccepted visual changes exist, so a maintainer
117+
# must accept them in Chromatic (then re-run this job) before merge.
118+
exitZeroOnChanges: false
117119
onlyChanged: true
118120
# Release-train builds (dev/staging/master head branches) were
119121
# already reviewed per-PR on dev; auto-accept them as baselines.

0 commit comments

Comments
 (0)