-
-
Notifications
You must be signed in to change notification settings - Fork 649
155 lines (136 loc) · 5.75 KB
/
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: Storybook
env:
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET_MYCRYPTOBUILDS }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID_MYCRYPTOBUILDS }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY_MYCRYPTOBUILDS }}
AWS_REGION: 'us-east-2'
on:
pull_request:
branches:
- '*'
push:
branches:
- master
repository_dispatch:
types: [ok-to-test-command]
jobs:
storybook-build:
runs-on: ubuntu-latest
steps:
# Fetch the PR number to use it with AWS
- name: Set PR_NUMBER
run: |
PR_NUMBER=$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }')
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
- uses: actions/checkout@v2
if: github.event_name != 'repository_dispatch'
- uses: actions/checkout@v2
if: github.event_name == 'repository_dispatch'
with:
ref: 'refs/pull/${{ github.event.client_payload.pull_request.number }}/merge'
- name: Retrieve node version from .nvmrc
run: echo "##[set-output name=NVMRC;]$(cat package.json | grep '\"node\":' | sed 's/^ *//;s/ *$//;s/\"node\":\ \"//;s/\",//')"
id: nvm
- name: Setup node ${{ steps.nvm.outputs.NVMRC }}
uses: actions/setup-node@v1
with:
node-version: '${{ steps.nvm.outputs.NVMRC }}'
- name: Cache node modules
id: cache
uses: actions/cache@v2
with:
path: node_modules
## Check cache based on yarn.lock hashfile
key: ${{ runner.OS }}-build-${{ hashFiles('**/yarn.lock') }}
- name: Install Dependencies
## If no cache is found, install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
- name: yarn build:storybook
if: github.ref == 'refs/heads/master' || github.event_name == 'pull_request'
run: yarn build:storybook
- name: S3 Sync - Storybook SHA
uses: jakejarvis/[email protected]
if: github.event_name == 'pull_request'
with:
args: --acl public-read --cache-control max-age=0 --follow-symlinks --exclude '.git/*'
env:
DEST_DIR: 'storybook/${GITHUB_SHA}'
SOURCE_DIR: 'storybook-static'
- name: S3 Sync - Storybook SHA - repository_dispatch
uses: jakejarvis/[email protected]
if: github.event_name == 'repository_dispatch'
with:
args: --acl public-read --cache-control max-age=0 --follow-symlinks --exclude '.git/*'
env:
DEST_DIR: 'storybook/${{ github.event.client_payload.pull_request.head.sha }}'
SOURCE_DIR: 'storybook-static'
- name: S3 Sync - Storybook Branch - push
uses: jakejarvis/[email protected]
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
with:
args: --acl public-read --cache-control max-age=0 --follow-symlinks --delete --exclude '.git/*'
env:
DEST_DIR: 'storybook/${GITHUB_REF##*/}'
SOURCE_DIR: 'storybook-static'
- name: S3 Sync - Storybook Branch - pull_request
uses: jakejarvis/[email protected]
if: github.event_name == 'pull_request'
with:
args: --acl public-read --cache-control max-age=0 --follow-symlinks --delete --exclude '.git/*'
env:
DEST_DIR: 'storybook/${{ github.head_ref }}'
SOURCE_DIR: 'storybook-static'
- name: S3 Sync - Storybook Branch - repository_dispatch
uses: jakejarvis/[email protected]
if: github.event_name == 'repository_dispatch'
with:
args: --acl public-read --cache-control max-age=0 --follow-symlinks --delete --exclude '.git/*'
env:
DEST_DIR: 'storybook/${{ github.event.client_payload.pull_request.head.ref }}'
SOURCE_DIR: 'storybook-static'
- name: S3 Sync - Storybook - PR Number - pull_request
uses: jakejarvis/[email protected]
if: github.event_name == 'pull_request'
with:
args: --acl public-read --cache-control max-age=0 --follow-symlinks --delete --exclude '.git/*'
env:
DEST_DIR: 'storybook/pr/${PR_NUMBER}'
SOURCE_DIR: 'storybook-static'
- name: S3 Sync - Storybook - PR Number - repository_dispatch
uses: jakejarvis/[email protected]
if: github.event_name == 'repository_dispatch'
with:
args: --acl public-read --cache-control max-age=0 --follow-symlinks --delete --exclude '.git/*'
env:
DEST_DIR: 'storybook/pr/${{ github.event.client_payload.pull_request.number }}'
SOURCE_DIR: 'storybook-static'
- name: Update PR status
uses: actions/github-script@v1
id: update-check-run
if: github.event_name == 'repository_dispatch'
env:
number: ${{ github.event.client_payload.pull_request.number }}
job: ${{ github.job }}
# Conveniently, job.status maps to https://developer.github.com/v3/checks/runs/#update-a-check-run
conclusion: ${{ job.status }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { data: pull } = await github.pulls.get({
...context.repo,
pull_number: process.env.number
});
const ref = pull.head.sha;
const { data: checks } = await github.checks.listForRef({
...context.repo,
ref
});
const check = checks.check_runs.filter(c => c.name === process.env.job);
const { data: result } = await github.checks.update({
...context.repo,
check_run_id: check[0].id,
status: 'completed',
conclusion: process.env.conclusion
});
return result;