-
Notifications
You must be signed in to change notification settings - Fork 62
94 lines (85 loc) · 3.35 KB
/
Copy pathchromatic-upload.yml
File metadata and controls
94 lines (85 loc) · 3.35 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
name: Chromatic Upload
on:
workflow_run:
workflows: ["Storybook"]
types: [completed]
permissions:
pull-requests: write
actions: read
jobs:
upload:
runs-on: ubuntu-24.04
if: >
github.event.workflow_run.conclusion == 'success' &&
(github.event.workflow_run.event == 'pull_request' || github.event.workflow_run.event == 'push')
steps:
# Checkout base repo with full history — Chromatic needs git log to find
# the baseline commit. We always check out the default branch (not the PR
# branch) so that no untrusted code from forks is ever executed.
- name: Checkout Base Repository
uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: storybook-static
path: storybook-static
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to Chromatic
id: chromatic
uses: chromaui/action@v1
with:
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
storybookBuildDir: storybook-static
# Auto-accept changes on master (push) to establish the visual baseline.
# PR builds are left for review.
autoAcceptChanges: ${{ github.event.workflow_run.event == 'push' }}
# Post Chromatic URLs as a PR comment (only for pull_request events)
- name: Find PR number
id: find-pr
if: github.event.workflow_run.event == 'pull_request'
uses: actions/github-script@v7
with:
script: |
// workflow_run.pull_requests works for same-repo PRs
const prs = context.payload.workflow_run.pull_requests;
if (prs && prs.length > 0) {
return prs[0].number;
}
// Fallback: search for a PR matching the head SHA (covers fork PRs)
const head_sha = context.payload.workflow_run.head_sha;
const { data: pulls } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
sort: 'updated',
direction: 'desc',
per_page: 10,
});
const matched = pulls.find(pr => pr.head.sha === head_sha);
return matched ? matched.number : '';
- name: Find existing comment
id: find-comment
if: steps.find-pr.outputs.result && steps.find-pr.outputs.result != ''
uses: peter-evans/find-comment@v3
with:
issue-number: ${{ steps.find-pr.outputs.result }}
comment-author: 'github-actions[bot]'
body-includes: '<!-- chromatic-build -->'
- name: Comment on PR
if: steps.find-pr.outputs.result && steps.find-pr.outputs.result != ''
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ steps.find-pr.outputs.result }}
edit-mode: replace
body: |
<!-- chromatic-build -->
### Chromatic Build
| | Link |
|---|---|
| Storybook | ${{ steps.chromatic.outputs.storybookUrl }} |
| Build | ${{ steps.chromatic.outputs.buildUrl }} |