-
Notifications
You must be signed in to change notification settings - Fork 828
436 lines (371 loc) · 14.9 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
name: Make Review Apps
on:
release:
types: [released, prereleased]
pull_request:
branches: [ '**' ]
push:
branches: [ '2[0-9][02468]-*-2[0-9]' ]
env:
# APPLITOOLS_API_KEY:
# AWS_ACCESS_KEY_ID:
# AWS_REGION:
# AWS_SECRET_ACCESS_KEY:
# DSE_API_RELEASE_TOKEN:
# GITHUB_PACKAGES_TOKEN:
# GITHUB_TOKEN: ${{ github.token }}
HEROKU_API_KEY: ${{ secrets.DSE_INFRA_HEROKU_API_KEY }}
jobs:
init:
runs-on: ubuntu-latest
steps:
- uses: tibdex/github-app-token@v1
id: get_installation_token
with:
app_id: 244972
private_key: ${{ secrets.DSE_CI_APP_KEY }}
- uses: actions/checkout@v3
- run: printenv | sort
- name: Show GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- run: mkdir -p workspace
- name: Retrieve Github deployments
env:
GITHUB_TOKEN: ${{ steps.get_installation_token.outputs.token }}
run: 'gh api /repos/salesforce-ux/design-system-internal/deployments --field ref=${{ github.event.pull_request.head.sha }} --method GET | jq "map({ status: .statuses_url, url: .payload.web_url})" > workspace/gh-deployments.json'
- name: View deployments
run: cat workspace/gh-deployments.json
- name: Set Github deployments to "in progress"
env:
GITHUB_TOKEN: ${{ steps.get_installation_token.outputs.token }}
run: |-
for row in $(jq -r '.[] | @base64' workspace/gh-deployments.json); do
export STATUS_URL=$(echo ${row} | base64 --decode | jq -r ".status" | sed 's/https:\/\/api.github.com//')
gh api ${STATUS_URL} -f state=in_progress -H "Accept: application/vnd.github.flash-preview+json"
done
- uses: actions/upload-artifact@v3
with:
path: |-
workspace/gh-deployments.json
prepare:
runs-on: ubuntu-latest
outputs:
HEROKU_APP_NAME: ${{ steps.which-heroku-app.outputs.HEROKU_APP_NAME }}
HEROKU_RELEASE_STORYBOOK_APP_NAME: ${{ steps.which-heroku-app.outputs.HEROKU_RELEASE_STORYBOOK_APP_NAME }}
needs:
- init
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
cache: 'npm'
- uses: actions/download-artifact@v3
with:
path: workspace
- name: Determine Heroku App
uses: "./.github/actions/set-heroku-app-name"
id: which-heroku-app
- run: npm ci
- uses: "./.github/actions/build-tokens"
- uses: "./.github/actions/copy-tokens-to-workspace"
- name: Print destination app names
run: |
HEROKU_APP_NAME=${{ steps.which-heroku-app.outputs.HEROKU_APP_NAME }}
HEROKU_RELEASE_STORYBOOK_APP_NAME=${{ steps.which-heroku-app.outputs.HEROKU_RELEASE_STORYBOOK_APP_NAME }}
echo "=============================="
echo $HEROKU_APP_NAME
echo $HEROKU_RELEASE_STORYBOOK_APP_NAME
# if HEROKU_RELEASE_STORYBOOK_APP_NAME is "true", then we are in a PR
echo "=============================="
- name: Compile styles
run: npm run gulp -- styles
- name: Compress styles
run: tar -cvf workspace/styles.tar assets/styles/
- name: Compress generated metadata
run: tar -cvf workspace/metadata.tar .generated/metadata/
- uses: actions/upload-artifact@v3
with:
path: |-
workspace/design-tokens.tar
workspace/styles.tar
workspace/metadata.tar
workspace/heroku-app-name.txt
workspace/heroku-release-storybook-app-name.txt
build-storybook:
if: ${{ !contains('refs/heads//^v\d+\.\d+\.\d+-.+$/', github.ref) }}
runs-on: ubuntu-latest
needs:
- prepare
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
cache: 'npm'
- uses: actions/download-artifact@v3
with:
path: workspace
- name: Display structure of downloaded files
run: ls -R
working-directory: workspace
- uses: "./.github/actions/copy-tokens-from-workspace"
- name: Install and Build task
run: |
npm ci
npm run build
- name: Build static Storybook
run: npm run storybook:build
env:
NODE_OPTIONS: --openssl-legacy-provider # per https://candid.technology/error-error-0308010c-digital-envelope-routines-unsupported/
- name: Archive static Storybook
run: tar -czvf workspace/storybook.tar.gz .www/ Procfile config/nginx.conf.erb heroku-start.sh app.json
- uses: actions/upload-artifact@v3
with:
path: workspace/storybook.tar.gz
publish-storybook:
if: ${{ needs.prepare.outputs.HEROKU_RELEASE_STORYBOOK_APP_NAME != 'false' }}
runs-on: ubuntu-latest
needs:
- init
- prepare
- build-storybook
steps:
- uses: actions/download-artifact@v3
with:
path: workspace
- name: Display structure of downloaded files
run: ls -R
working-directory: workspace
- name: Install Heroku CLI
run: |-
if [[ $(command -v heroku) == "" ]]; then
curl https://cli-assets.heroku.com/install.sh | sh
else
echo "Heroku is already installed. No operation was performed."
fi
- name: Install Heroku Build CLI plugin
run: heroku plugins:install heroku-builds
- name: Deploy to Heroku
run: |-
HEROKU_APP_NAME=${{ needs.prepare.outputs.HEROKU_APP_NAME }}
HEROKU_RELEASE_STORYBOOK_APP_NAME=${{ needs.prepare.outputs.HEROKU_RELEASE_STORYBOOK_APP_NAME }}
export PR_NUMBER=${{ github.event.pull_request.number }}
export REVIEW_APP_NAME=slds-storybook-pr-${PR_NUMBER}
echo $HEROKU_APP_NAME
echo $HEROKU_RELEASE_STORYBOOK_APP_NAME
echo $PR_NUMBER
echo REVIEW_APP_NAME
if [[ ${HEROKU_RELEASE_STORYBOOK_APP_NAME} != "false" && ${PR_NUMBER} == "" ]]; then
export PUBLISH_STORYBOOK_TO=${HEROKU_RELEASE_STORYBOOK_APP_NAME}
else
export PUBLISH_STORYBOOK_TO=${REVIEW_APP_NAME}
fi
echo "=============================="
echo ${PUBLISH_STORYBOOK_TO}
echo "=============================="
heroku buildpacks -a ${PUBLISH_STORYBOOK_TO} | grep "https://github.com/salesforce-ux/heroku-buildpack-nginx.git#dse" || heroku buildpacks:set https://github.com/salesforce-ux/heroku-buildpack-nginx.git#dse -a ${PUBLISH_STORYBOOK_TO}
heroku builds:create --source-tar workspace/artifact/storybook.tar.gz -a ${PUBLISH_STORYBOOK_TO}
- uses: tibdex/github-app-token@v1
id: get_installation_token
with:
app_id: 244972
private_key: ${{ secrets.DSE_CI_APP_KEY }}
- name: Set Github deployments to "success"
env:
GITHUB_TOKEN: ${{ steps.get_installation_token.outputs.token }}
run: |-
for row in $(jq -r '.[] | select(.url | contains("storybook")) | @base64' workspace/artifact/gh-deployments.json); do
export STATUS_URL=$(echo ${row} | base64 --decode | jq -r ".status" | sed 's/https:\/\/api.github.com//')
export SITE_URL=$(echo ${row} | base64 --decode | jq -r ".url")
gh api ${STATUS_URL} -f state=success -f environment_url=${SITE_URL} -H "Accept: application/vnd.github.ant-man-preview+json"
done
framework-build:
# if: ${{ (1 < 0) }}
runs-on: ubuntu-latest
needs:
- prepare
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
cache: 'npm'
node-version: '<=18.17.1'
- uses: actions/download-artifact@v3
with:
path: workspace
- name: Display structure of downloaded files
run: ls -R
working-directory: workspace
- uses: "./.github/actions/copy-tokens-from-workspace"
- name: Decompress styles
run: tar -xvf workspace/artifact/styles.tar
- name: Decompress metadata
run: tar -xvf workspace/artifact/metadata.tar
- run: npm ci
- name: Do build-dist
run: npm run build-dist
- name: Compress .dist
run: |-
tar -cvf workspace/design-system-dist.tar .dist/
cd .dist && zip -r dist . && mv dist.zip ../workspace/ && cd ..
- uses: actions/upload-artifact@v3
with:
path: |-
workspace/design-system-dist.tar
workspace/dist.zip
publish-site:
runs-on: ubuntu-latest
needs:
- framework-build
steps:
- uses: tibdex/github-app-token@v1
id: get_installation_token
with:
app_id: 244972
private_key: ${{ secrets.DSE_CI_APP_KEY }}
- name: Checkout design-system-site
uses: actions/checkout@v3
with:
repository: salesforce-ux/design-system-site
ref: main
token: ${{ steps.get_installation_token.outputs.token }}
- name: Display structure of downloaded files
run: ls -la
- uses: actions/download-artifact@v3
with:
path: workspace
- name: Display structure of downloaded files
run: ls -R
working-directory: workspace
- name: Decompress SLDS .dist
run: |-
mkdir -p .slds
tar -xvf workspace/artifact/design-system-dist.tar --directory .slds
- uses: actions/setup-node@v3
with:
cache: 'npm'
- run: npm ci
- shell: bash
run: |-
if [[ $(command -v heroku) == "" ]]; then
curl https://cli-assets.heroku.com/install.sh | sh
else
echo "Heroku is already installed. No operation was performed."
fi
- name: Install Heroku Build CLI plugin
run: heroku plugins:install heroku-builds
- name: Build static site
run: npm run build
env:
SLDS__FRAMEWORK__PATH: ".slds/.dist/"
NODE_OPTIONS: --openssl-legacy-provider # per https://candid.technology/error-error-0308010c-digital-envelope-routines-unsupported/
- name: Display structure of downloaded files
run: ls -la
- name: Generate site tarball
run: tar -czvf site-next.tar.gz .www/ Procfile config/nginx.conf.erb heroku-start.sh app.json
- name: Deploy to Heroku app
run: |-
export HEROKU_APP_NAME=$(cat workspace/artifact/heroku-app-name.txt)
echo "=============================="
echo ${HEROKU_APP_NAME}
echo "=============================="
heroku buildpacks -a ${HEROKU_APP_NAME} | grep "https://github.com/salesforce-ux/heroku-buildpack-nginx.git#dse" || heroku buildpacks:set https://github.com/salesforce-ux/heroku-buildpack-nginx.git#dse -a ${HEROKU_APP_NAME}
heroku builds:create --source-tar site-next.tar.gz -a ${HEROKU_APP_NAME}
- name: Set Github deployments to "success"
env:
GITHUB_TOKEN: ${{ steps.get_installation_token.outputs.token }}
run: |-
for row in $(jq -r '.[] | select(.url | contains("review-site")) | @base64' workspace/gh-deployments.json); do
export STATUS_URL=$(echo ${row} | base64 --decode | jq -r ".status" | sed 's/https:\/\/api.github.com//')
export SITE_URL=$(echo ${row} | base64 --decode | jq -r ".url")
gh api ${STATUS_URL} -f state=success -f environment_url=${SITE_URL} -H "Accept: application/vnd.github.ant-man-preview+json"
done
attach-artifact:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'release' }}
needs:
- framework-build
steps:
- uses: tibdex/github-app-token@v1
id: get_installation_token
with:
app_id: 244972
private_key: ${{ secrets.DSE_CI_APP_KEY }}
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
path: workspace
- name: 'Github: attach artifact to release'
env:
DSE_API_RELEASE_TOKEN: ${{ secrets.DSE_API_RELEASE_TOKEN }}
VERSION_FROM_TAG: ${{ github.event.release.tag_name }}
GITHUB_TOKEN: ${{ steps.get_installation_token.outputs.token }}
run: |-
gh release view ${VERSION_FROM_TAG} | grep ${VERSION_FROM_TAG}
if [ $? -eq 0 ]; then
cp workspace/artifact/dist.zip workspace/slds-${VERSION_FROM_TAG}.zip
echo "=============================="
echo "» Attaching artifact to release ${VERSION_FROM_TAG}"
gh release upload ${VERSION_FROM_TAG} workspace/slds-${VERSION_FROM_TAG}.zip#"SLDS ${VERSION_FROM_TAG}" --clobber
else
echo "=============================="
echo "» ERROR: release ${VERSION_FROM_TAG} not found on Github"
fi
update-database:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'release' }}
needs:
- attach-artifact
steps:
- uses: actions/checkout@v3
- name: Trigger database update via API
env:
DSE_API_RELEASE_TOKEN: ${{ secrets.DSE_API_RELEASE_TOKEN }}
VERSION_FROM_TAG: ${{ github.event.release.tag_name }}
run: |-
export SALESFORCE_VERSION=$(cat package.json | jq -r .slds.id)
curl --location --request PATCH 'https://api.lightningdesignsystem.com/v1/release' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer '"$DSE_API_RELEASE_TOKEN"'' \
--data-raw '{
"version":"'"${VERSION_FROM_TAG:1:20}"'",
"salesforce_version": "'"$SALESFORCE_VERSION"'"
}'
slack-broadcast:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'release' }}
needs:
- attach-artifact
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0 # retrieve git history
- name: Get Salesforce and Package Versions
id: get-salesforce-versions
env:
VERSION_FROM_TAG: ${{ github.event.release.tag_name }}
run: |
SALESFORCE_VERSION=$(cat package.json | jq -r .slds.id)
echo "salesforce_version=${SALESFORCE_VERSION}" >> $GITHUB_OUTPUT
echo "version_from_tag=${VERSION_FROM_TAG}" >> $GITHUB_OUTPUT
- name: Compile slack message
id: compile-slack-msg-body
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
result-encoding: string
script: |
const releaseVersion = '${{ steps.get-salesforce-versions.outputs.salesforce_version }}';
const versionFromTag = '${{ steps.get-salesforce-versions.outputs.version_from_tag }}';
const [v, semVersion] = versionFromTag.split(/(?<=v)/);
const packageURL = `https://www.npmjs.com/package/@salesforce-ux/design-system/${v}/${semVersion}`;
const slackBody = `*Salesforce Release*: ${releaseVersion} | *Package Version*: ${versionFromTag} | <${packageURL}| ${packageURL}>`
return slackBody;
- name: Notify Slack
uses: ./.github/actions/send-slack-notifications
with:
slack-webhook-url: ${{ secrets.SLACK_DESIGN_SYSTEM_BROADCAST_WEBHOOK_URL }}
slack-title: 'A new version of *@salesforce-ux/design-system* package :package: was published :rocket:'
slack-body: ${{ steps.compile-slack-msg-body.outputs.result }}