forked from massgov/mayflower
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.yml
540 lines (510 loc) · 18.9 KB
/
config.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
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
version: 2.1
references:
configure_npm: &configure_npm
run: { name: 'Configure NPM', command: 'echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc'}
configure_git: &configure_git
run: {name: 'Prepare Git', command: 'git config --global user.email "ci.bot@mass.gov" && git config --global user.name "MassGov Bot"'}
no_host_check: &no_host_check
run: {name: 'Disable StrictHostKeyChecking', command: 'mkdir -p $HOME/.ssh && echo "StrictHostKeyChecking no" >> ~/.ssh/config'}
react_defaults: &react_defaults
working_directory: ~/repo
docker:
- image: circleci/node:12.18.0-browsers
patternlab_defaults: &patternlab_defaults
working_directory: ~/code
docker:
- image: circleci/php:7.1-node-browsers
backstop_defaults: &backstop_defaults
working_directory: /home/circleci
docker:
- image: cimg/node:12.14
jobs:
build:
<<: *patternlab_defaults
steps:
- checkout
- restore_cache:
name: Restore pnpm-lock.yaml
keys:
- root-npm-v4-{{ checksum "common/config/rush/pnpm-lock.yaml" }}-25
- run: {name: 'Install packages', command: 'node common/scripts/install-run-rush.js install'}
- save_cache:
name: Save NPM cache
key: root-npm-v4-{{ checksum "common/config/rush/pnpm-lock.yaml" }}-25
paths:
- common
- packages/assets/node_modules
- packages/react/node_modules
- packages/patternlab/styleguide/node_modules
- packages/site/node_modules
- packages/core/node_modules
patternlab_build:
<<: *patternlab_defaults
steps:
- checkout
- restore_cache:
name: Restore NPM Cache
keys:
- root-npm-v4-{{ checksum "common/config/rush/pnpm-lock.yaml" }}-25
- run: { name: 'Build', command: 'cd packages/patternlab/styleguide && node ../../../common/scripts/install-run-rushx.js build'}
- persist_to_workspace:
root: ~/code
paths: ["*"]
patternlab_test:
<<: *backstop_defaults
steps:
- attach_workspace: {at: /home/circleci}
- setup_remote_docker
- run: |
cd packages/patternlab
docker-compose up --no-start web backstop
docker cp ./ $(docker-compose ps -q backstop):/src/
docker cp ./styleguide/public/. $(docker-compose ps -q web):/usr/share/nginx/html
- run: |
cd packages/patternlab
docker-compose run backstop test
- run:
command: cd packages/patternlab && docker cp $(docker-compose ps -q backstop):/src/backstopjs/. ./backstopjs/
when: always
- store_artifacts:
path: packages/patternlab/backstopjs
destination: backstop
- store_test_results:
path: packages/patternlab/backstopjs/reports/ci
patternlab_deploy_branch:
<<: *patternlab_defaults
steps:
- attach_workspace: {at: ~/code}
- *no_host_check
- add_ssh_keys
- *configure_git
- run:
name: 'Install AWS'
command: |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
- run:
name: 'Deploy Artifact Branch'
command: |
# This snippet pushes the dist directory to the artifact repo by faking a checkout
# of the artifact repository, creating or reusing an existing branch, committing the
# work, then pushing to github.
# See https://github.com/LastCallMedia/Artifact.sh/blob/master/artifact.sh
cd packages/patternlab/styleguide/dist
git clone --bare git@github.com:massgov/mayflower-artifacts.git .git
git config core.bare false
git rev-parse --verify -q "$CIRCLE_BRANCH" || git branch "$CIRCLE_BRANCH" $(git show-ref -s master)
git symbolic-ref HEAD "refs/heads/$CIRCLE_BRANCH"
git add .
if git diff-index --quiet HEAD; then
echo "Nothing to commit"
else
git commit -m "Automated commit based on $CIRCLE_SHA1"
git push origin "$CIRCLE_BRANCH"
fi
- run:
name: 'Deploy S3 Branch'
command: aws s3 sync packages/patternlab/styleguide/public "s3://mayflower.digital.mass.gov/patternlab/b/$CIRCLE_BRANCH"
patternlab_deploy_tag:
<<: *patternlab_defaults
steps:
- attach_workspace: {at: ~/code}
- *no_host_check
- add_ssh_keys
- *configure_git
- *configure_npm
- run:
name: 'Install AWS'
command: |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
- run:
name: 'Deploy Artifact Tag'
command: |
# This snippet pushes the dist directory to the artifact repo by faking a checkout
# of the artifact repository, creating a new commit and tag, then pushing.
# See https://github.com/LastCallMedia/Artifact.sh/blob/master/artifact.sh
cd packages/patternlab/styleguide/dist
git clone --bare git@github.com:massgov/mayflower-artifacts.git .git
git config core.bare false
git symbolic-ref HEAD "refs/heads/master"
git add .
if git diff-index --quiet HEAD; then
echo "Nothing to commit"
else
git commit -m "Automated commit based on $CIRCLE_SHA1"
fi
git rev-parse --verify -q "$CIRCLE_TAG" || git tag "$CIRCLE_TAG"
git push origin "$CIRCLE_TAG"
- run:
name: 'Deploy NPM Tag'
command: |
cd packages/patternlab/styleguide/dist
npm version --no-git-tag-version "$CIRCLE_TAG"
if test -z "$(npm show @massds/mayflower@$CIRCLE_TAG)"; then
npm publish
else
echo "Skipping NPM publish - $CIRCLE_TAG already exists"
fi
- run:
name: 'Deploy S3 Tag'
command: |
aws s3 sync packages/patternlab/styleguide/public "s3://mayflower.digital.mass.gov/patternlab/v/$CIRCLE_TAG"
if [[ "$CIRCLE_TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
# Use cp instead of sync for root copy. sync lists all keys and is too slow.
aws s3 cp --recursive packages/patternlab/styleguide/public/ "s3://mayflower.digital.mass.gov/patternlab"
fi
react_build_storybook:
<<: *patternlab_defaults
steps:
- checkout
- restore_cache:
keys:
- root-npm-v4-{{ checksum "common/config/rush/pnpm-lock.yaml" }}-25
- run:
name: Mayflower React Build
command: cd packages/react && node ../../common/scripts/install-run-rushx.js build
- run:
name: Mayflower React Build Storybook
command: cd packages/react && node ../../common/scripts/install-run-rushx.js build-storybook
- run:
name: Mayflower React Storybook Extract
command: cd packages/react && node ../../common/scripts/install-run-rushx.js storybook:extract
- run:
name: Mayflower React Linter
command: cd packages/react && node ../../common/scripts/install-run-rushx.js lint
- persist_to_workspace:
root: ~/code
paths: ["*"]
react_test:
<<: *backstop_defaults
steps:
- attach_workspace: {at: /home/circleci}
- setup_remote_docker
- run: |
cd packages/react
docker-compose up --no-start web backstop
docker cp ./ $(docker-compose ps -q backstop):/src/
docker cp ../assets $(docker-compose ps -q backstop):/src/assets
docker cp ../../docs $(docker-compose ps -q backstop):/src/docs
docker cp ./storybook-static/. $(docker-compose ps -q web):/usr/share/nginx/html
- run: |
cd packages/react
docker-compose run backstop test
- run:
command: cd packages/react && docker cp $(docker-compose ps -q backstop):/src/backstop/. ./backstop/
when: always
- store_artifacts:
path: packages/react/backstop
destination: backstop
- store_test_results:
path: packages/react/backstop/data/ci_report
react_deploy_tag:
<<: *patternlab_defaults
steps:
- attach_workspace:
at: ~/code
- *configure_npm
- run:
name: 'Publish mayflower-react NPM package'
command: |
cd packages/react
npm version --no-git-tag-version "$CIRCLE_TAG"
if test -z "$(npm show @massds/mayflower-react@$CIRCLE_TAG)"; then
npm publish
else
echo "Skipping NPM publish - $CIRCLE_TAG already exists"
fi
- run: |
# Only sync to S3 for stable tags.
if [[ "$CIRCLE_TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
sudo apt-get update --allow-releaseinfo-change && sudo apt-get -y -qq install awscli
fi
- run: |
# Only sync to S3 for stable tags.
if [[ "$CIRCLE_TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
cd packages/react
aws s3 sync storybook-static s3://mayflower.digital.mass.gov/react --delete
aws configure set preview.cloudfront true
aws cloudfront create-invalidation --distribution-id $AWS_DISTRIBUTION_ID --paths '/react*'
fi
core_build_storybook:
<<: *patternlab_defaults
steps:
- checkout
- restore_cache:
keys:
- root-npm-v4-{{ checksum "common/config/rush/pnpm-lock.yaml" }}-25
- run:
name: Mayflower React NPM Package Build
command: cd packages/react && node ../../common/scripts/install-run-rushx.js build
- run:
name: Mayflower Core Linter
command: cd packages/core && node ../../common/scripts/install-run-rushx.js lint
- run:
name: Mayflower Core Storybook Build
command: cd packages/core && node ../../common/scripts/install-run-rushx.js build
- persist_to_workspace:
root: ~/code
paths: ["*"]
core_deploy_tag:
<<: *patternlab_defaults
steps:
- attach_workspace:
at: ~/code
- run: |
# Only sync to S3 for stable tags.
if [[ "$CIRCLE_TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
sudo apt-get update --allow-releaseinfo-change && sudo apt-get -y -qq install awscli
cd packages/core
aws s3 sync storybook-static "s3://mayflower.digital.mass.gov/core/v/$CIRCLE_TAG" --delete
# Use cp instead of sync for root copy. sync lists all keys and is too slow.
aws s3 cp --recursive storybook-static "s3://mayflower.digital.mass.gov/core"
aws configure set preview.cloudfront true
aws cloudfront create-invalidation --distribution-id $AWS_DISTRIBUTION_ID --paths '/core*'
fi
core_deploy_branch:
<<: *patternlab_defaults
steps:
- attach_workspace:
at: ~/code
- run: |
sudo apt-get update --allow-releaseinfo-change && sudo apt-get -y -qq install awscli
cd packages/core
aws s3 sync storybook-static "s3://mayflower.digital.mass.gov/core/b/$CIRCLE_BRANCH" --delete
aws configure set preview.cloudfront true
aws cloudfront create-invalidation --distribution-id $AWS_DISTRIBUTION_ID --paths "/core/b*"
auto_changelog:
<<: *react_defaults
steps:
- checkout
- *no_host_check
- add_ssh_keys:
fingerprints:
- a7:d5:55:42:fe:37:52:b6:71:7c:a6:d8:05:78:fd:25
- *configure_git
- run:
name: 'Auto add changelog for dependabot'
command: ./.circleci/dependabot.sh
release_branch:
<<: *patternlab_defaults
steps:
- checkout
- *no_host_check
- restore_cache:
keys:
- root-npm-v4-{{ checksum "common/config/rush/pnpm-lock.yaml" }}-25
- run: sudo npm install -g js-yaml@3.13.1 @octokit/rest semver@6.3.0 shelljs@0.8.3 simple-git@1.126.0
# Identify the committer i.e. CircleCI deployment bot
- run: git config --global user.email "circleci@example.com"
- run: git config --global user.name "CircleCI Deployment Bot"
- run: export NODE_PATH=$(npm root --quiet -g) && node scripts/release-branch.js
github_tag:
<<: *patternlab_defaults
steps:
- checkout
- *no_host_check
- restore_cache:
keys:
- root-npm-v4-{{ checksum "common/config/rush/pnpm-lock.yaml" }}-25
- run: sudo npm install -g js-yaml@3.13.1 @octokit/rest semver@6.3.0 shelljs@0.8.3 simple-git@1.126.0
# Identify the committer i.e. CircleCI deployment bot
- run: git config --global user.email "circleci@example.com"
- run: git config --global user.name "CircleCI Deployment Bot"
- run: export NODE_PATH=$(npm root --quiet -g) && node scripts/release-tag.js
assets_build:
<<: *patternlab_defaults
steps:
- checkout
- restore_cache:
keys:
- root-npm-v4-{{ checksum "common/config/rush/pnpm-lock.yaml" }}-25
- run: { name: 'Build', command: 'cd packages/assets && node ../../common/scripts/install-run-rushx.js build'}
- run:
name: Mayflower Style Linter
command: cd packages/assets && node ../../common/scripts/install-run-rushx.js stylelint
assets_deploy_tag:
<<: *patternlab_defaults
steps:
- checkout
- *configure_npm
- restore_cache:
keys:
- root-npm-v4-{{ checksum "common/config/rush/pnpm-lock.yaml" }}-25
- run:
name: 'Publish mayflower-assets NPM package'
command: |
cd packages/assets
npm version --no-git-tag-version "$CIRCLE_TAG"
if test -z "$(npm show @massds/mayflower-assets@$CIRCLE_TAG)"; then
npm publish
else
echo "Skipping NPM publish - $CIRCLE_TAG already exists"
fi
site_build:
<<: *patternlab_defaults
steps:
- checkout
- restore_cache:
keys:
- root-npm-v4-{{ checksum "common/config/rush/pnpm-lock.yaml" }}-25
- run: cd packages/react && node ../../common/scripts/install-run-rushx.js build
- run:
name: Validate Package Build
command: cd packages/site && node ../../common/scripts/install-run-rushx.js build
- persist_to_workspace:
root: ~/code
paths: ["*"]
site_deploy_tag:
<<: *patternlab_defaults
steps:
- attach_workspace:
at: ~/code
- run: |
# Only sync to S3 for stable tags.
if [[ "$CIRCLE_TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
sudo apt-get update --allow-releaseinfo-change && sudo apt-get -y -qq install awscli
fi
- run: |
# Only sync to S3 for stable tags.
if [[ "$CIRCLE_TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
cd packages/site
aws s3 sync public s3://mayflower.digital.mass.gov/home --delete
aws configure set preview.cloudfront true
aws cloudfront create-invalidation --distribution-id $AWS_DISTRIBUTION_ID --paths '/home*'
fi
workflows:
version: 2
# Executed on branch pushes.
build_branch:
jobs:
- build
- auto_changelog:
filters:
branches: { only: /dependabot\/.*/ }
- assets_build:
requires: [react_build_storybook]
filters:
branches: { ignore: /(docs|site\/).*/ }
# patternlab
- patternlab_build:
requires: [build]
filters:
branches: { ignore: /(docs|react\/|site\/|core\/).*/ }
- patternlab_deploy_branch:
requires: [patternlab_build]
filters:
branches: { ignore: /(docs|react\/|site\/|core\/).*/ }
- patternlab_test:
requires: [patternlab_build]
filters:
branches: { ignore: /(docs|react\/|site\/|core\/).*/ }
# react
- react_build_storybook:
requires: [build]
filters:
branches: { ignore: /(docs|patternlab\/|site\/).*/ }
- react_test:
requires: [react_build_storybook]
filters:
branches: { ignore: /(docs|patternlab\/|site\/|core\/).*/ }
# site
- site_build:
requires: [react_build_storybook]
filters:
branches: { ignore: /(docs|patternlab\/|react\/|core\/).*/ }
# core
- core_build_storybook:
requires: [build]
filters:
branches: { ignore: /(docs|patternlab\/|site\/).*/ }
- core_deploy_branch:
requires: [core_build_storybook]
filters:
branches: { ignore: /(docs|patternlab\/|site\/|react\/).*/ }
# Release branch automation every Monday at 1:00 p.m. ET "00 18 * * 1"
release:
jobs:
- build
- release_branch:
requires: [build]
triggers:
- schedule:
cron: "00 18 * * 1"
filters:
branches:
only:
- develop
build_github_tag:
jobs:
- build:
filters:
branches:
only: master
- hold:
type: approval
requires:
- build
filters:
branches:
only: master
- github_tag:
requires:
- hold
filters:
branches:
only: master
# Executed on tag pushes.
build_tag:
jobs:
- build:
filters:
branches: { ignore: /.*/ }
tags: { only: /.*/ }
- patternlab_build:
requires: [build]
filters:
branches: { ignore: /.*/ }
tags: { only: /.*/ }
- patternlab_deploy_tag:
requires: [patternlab_build]
filters:
branches: { ignore: /.*/ }
tags: { only: /.*/ }
- react_build_storybook:
requires: [build]
filters:
branches: { ignore: /.*/ }
tags: { only: /.*/ }
- react_deploy_tag:
requires: [react_build_storybook]
filters:
branches: { ignore: /.*/ }
tags: { only: /.*/ }
- assets_deploy_tag:
requires: [react_build_storybook]
filters:
branches: { ignore: /.*/ }
tags: { only: /.*/ }
- site_build:
requires: [react_build_storybook]
filters:
branches: { ignore: /.*/ }
tags: { only: /.*/ }
- site_deploy_tag:
requires: [site_build]
filters:
branches: { ignore: /.*/ }
tags: { only: /.*/ }
- core_build_storybook:
requires: [build]
filters:
branches: { ignore: /.*/ }
tags: { only: /.*/ }
- core_deploy_tag:
requires: [core_build_storybook]
filters:
branches: { ignore: /.*/ }
tags: { only: /.*/ }