Skip to content
Draft
Show file tree
Hide file tree
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
55 changes: 55 additions & 0 deletions .github/workflows/chromatic-required-status.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Chromatic required status

# Satisfies the required "Visual regression (Chromatic)" status check for dev PRs
# that touch no UI code. The CI `visual-tests` job is skipped for such PRs, and
# for fork PRs the whole CI workflow is held for manual approval -- so without
# this reporter the required check is never posted and the PR is blocked forever
# (e.g. content-only fork PRs).
#
# Runs as pull_request_target so it executes in the base-repo context with a
# token that can post commit statuses, without approval. It only reads the PR's
# changed-file list -- it never checks out or executes fork code.

on:
pull_request_target:
branches: [dev]
types: [opened, synchronize, reopened, ready_for_review]

permissions:
contents: read
pull-requests: read
statuses: write

concurrency:
group: chromatic-required-status-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
report:
name: Report Chromatic status for non-UI PRs
runs-on: ubuntu-latest
steps:
- name: Mark non-UI PRs as passing
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR: ${{ github.event.pull_request.number }}
SHA: ${{ github.event.pull_request.head.sha }}
REPO: ${{ github.repository }}
run: |
set -euo pipefail

# Keep in sync with the `chromatic-gate` path filter in ci.yml.
UI_REGEX='^(src/components/|src/layouts/|src/styles/|app/|\.storybook/|package\.json$|pnpm-lock\.yaml$)'

files=$(gh api --paginate "repos/${REPO}/pulls/${PR}/files" --jq '.[].filename')

if echo "$files" | grep -qE "$UI_REGEX"; then
echo "UI files changed -- the CI visual-regression job owns the required check."
exit 0
fi

echo "No UI files changed -- reporting the required Chromatic check as passed."
gh api "repos/${REPO}/statuses/${SHA}" \
-f state=success \
-f context='Visual regression (Chromatic)' \
-f description='No UI changes — visual review not required'
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ jobs:
uses: chromaui/action@v16
with:
projectToken: fee8e66c9916
exitZeroOnChanges: true
# Fail the check when unaccepted visual changes exist, so a maintainer
# must accept them in Chromatic (then re-run this job) before merge.
exitZeroOnChanges: false
onlyChanged: true
# Release-train builds (dev/staging/master head branches) were
# already reviewed per-PR on dev; auto-accept them as baselines.
Expand Down
Loading