-
Notifications
You must be signed in to change notification settings - Fork 90
111 lines (98 loc) · 3.52 KB
/
publish-storybook.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
name: Storybook Preview Publish
run-name: Storybook publish for ${{ github.event.workflow_run.head_branch }}
on:
workflow_run:
workflows: ["Build Storybook"]
types:
- completed
jobs:
deploy:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
pull-requests: write
statuses: write
name: Deploy Storybook to Cloudflare Pages
steps:
- name: Set initial commit status
uses: actions/github-script@v7
with:
script: |
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: "${{ github.event.workflow_run.head_commit.id }}",
state: "pending",
description: "Pending",
context: "Storybook"
})
- name: Checkout
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "yarn"
- name: Install dependencies
run: yarn
- name: "Download run metadata"
uses: actions/download-artifact@v4
with:
name: metadata
path: ./METADATA
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
- name: Get branch for Chromatic
uses: actions/github-script@v7
id: run_metadata
with:
script: |
const fs = require("fs");
const branchName = fs.readFileSync("./METADATA/branch-name", "utf8").trim();
core.setOutput("branchName", branchName);
- name: "Download build artifact"
uses: actions/download-artifact@v4
with:
name: storybook-build
path: ./storybook-static
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
- name: "Delete stats.json if it exists"
run: rm -f ./storybook-static/preview-stats.json
- name: Publish
uses: cloudflare/wrangler-action@v3
id: publish
with:
apiToken: ${{ secrets.CLOUDFLARE_SALT_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_SALT_ACCOUNT_ID }}
command: pages deploy ./storybook-static --project-name=saltdesignsystem-storybook --branch=${{ steps.run_metadata.outputs.branchName }}
- name: Update deploy status (success)
uses: actions/github-script@v7
if: success()
with:
script: |
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: "${{ github.event.workflow_run.head_commit.id }}",
state: "success",
description: "Successfully deployed",
context: "Storybook",
target_url: "${{ steps.publish.outputs.pages-deployment-alias-url }}"
});
- name: Update deploy status (failure)
uses: actions/github-script@v7
if: failure()
with:
script: |
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: "${{ github.event.workflow_run.head_commit.id }}",
state: "error",
description: "Failed to deploy",
context: "Storybook",
target_url: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
});