-
Notifications
You must be signed in to change notification settings - Fork 5.4k
55 lines (46 loc) · 2.03 KB
/
Copy pathchromatic-required-status.yml
File metadata and controls
55 lines (46 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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'