-
Notifications
You must be signed in to change notification settings - Fork 90
76 lines (66 loc) · 2.31 KB
/
storybook-preview.yml
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
name: Storybook Preview Publish
on:
workflow_dispatch:
pull_request:
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
pull-requests: write
name: Deploy to Cloudflare Pages
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: "20"
cache: "yarn"
- name: Install dependencies
run: yarn
- name: Run build
run: yarn build-storybook
env:
NODE_OPTIONS: "--max_old_space_size=6144"
- name: Publish
uses: cloudflare/pages-action@v1
id: publish
with:
apiToken: ${{ secrets.CLOUDFLARE_SALT_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_SALT_ACCOUNT_ID }}
projectName: "saltdesignsystem-storybook"
directory: ./storybook-static
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.head_ref || github.ref_name }}
- name: Preview URL
uses: actions/github-script@v6
with:
script: |
if (context.eventName == 'pull_request') {
const previewUrl = "${{ steps.publish.outputs.url }}";
const commentText = `Storybook Preview Link `;
const {data: comments} = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.number,
});
const oldPreviewUrlComment = comments.find(comment => comment.body.includes(commentText));
if (!oldPreviewUrlComment) {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `${commentText} ${previewUrl}`
});
} else {
github.rest.issues.updateComment({
comment_id: oldPreviewUrlComment.id,
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `${commentText} ${previewUrl}`
});
};
}