-
Notifications
You must be signed in to change notification settings - Fork 122
/
config.yml
473 lines (442 loc) · 15 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
version: 2.1
orbs:
slack: circleci/slack@3.2.0
win: circleci/windows@2.4.1
commands:
setup:
description: 'Setup Machine'
steps:
- restore_cache:
keys:
- npm-cache
- run:
name: 'Set environment variables'
command: |
touch $BASH_ENV
if [[ "${CIRCLE_BRANCH}" == "develop" ]]; then echo 'export DEVELOP=true' >> $BASH_ENV; fi
if [[ "${CIRCLE_BRANCH}" =~ ^release- ]]; then echo 'export RELEASE=true' >> $BASH_ENV; fi
source $BASH_ENV
- run:
name: 'Install Dependencies'
command: |
# Install system dependencies
sudo apt-get update
sudo apt-get install python-dev python-pip time
sudo pip install -U pip setuptools
sudo pip install awscli==1.18.85 datadog==0.40.1
sudo npm install -g npm@6.14.4
# Install node dependencies
node ./scripts/gtime.js monorepo_install npm ci
# Build the PWA
npm run lerna -- run analyze-build --scope "retail-react-app"
# Report bundle sizes
node ./scripts/report-bundle-size.js
# Check that packages are all using the same versions of compilers, etc.
node ./scripts/check-dependencies.js
# Install Snyk CLI
sudo npm install -g snyk
# Install Lighthouse CI CLI
sudo npm install -g @lhci/cli
- save_cache:
key: npm-cache
paths:
- /root/.npm
setup_windows:
description: 'Setup Machine'
steps:
- restore_cache:
keys:
- npm-cache
- run:
name: 'Install Dependencies'
command: |
# Install node dependencies
npm ci
- save_cache:
key: npm-cache
paths:
- /root/.npm
setup_npm_7:
description: 'Setup Machine with npm 7'
steps:
- restore_cache:
keys:
- npm-cache
- run:
name: 'Install Dependencies'
command: |
sudo npm install -g npm@7
npm ci
- save_cache:
key: npm-cache
paths:
- /root/.npm
setup_npm_8:
description: 'Setup Machine with npm 8'
steps:
- restore_cache:
keys:
- npm-cache
- run:
name: 'Install Dependencies'
command: |
sudo npm install -g npm@8
npm ci
- save_cache:
key: npm-cache
paths:
- /root/.npm
runtests:
description: 'Run tests'
parameters:
cwd:
description: 'The directory to execute the tests from'
default: ${PWD}
type: string
steps:
- run:
name: 'Run tests'
command: |
# Explicitly set pipefile policy. This is the default for non-windows, but seems
# that is needs to be set on windows to fail immediately.
set -eo pipefail
cd << parameters.cwd >>
# Note: Each of these test commands need to be exposed on the monorepo
# root and *also* on the PWA package. This section is run on both.
# Ensure bundlesize is in check
npm run test:max-file-size
# Always run fast unit tests
npm run test
smoketestscripts:
description: 'Smoke test scripts'
parameters:
dir:
description: 'The path to a project to test'
default: './packages/template-retail-react-app'
type: string
steps:
- run:
name: 'Smoke test scripts'
command: |
# Basic smoke-tests for uncommonly run scripts in a project
node ./scripts/smoke-test-npm-scripts.js --dir << parameters.dir >>
lighthouse-ci:
description: 'Run Lighthouse CI on the PWA'
steps:
- run:
name: Run Lighthouse CI on the PWA
command: |
npm run test:lighthouse --prefix packages/template-retail-react-app
checkclean:
description: 'Check Repository Clean'
steps:
- run:
name: Check Repository Clean
command: |
# Print status for debugging on CircleCI.
git status
# Fail the build if any step leaves uncommitted changes in the repo
# that would prevent Lerna from publishing (Lerna gets this right).
git diff --exit-code
generate_and_test_project:
description: 'Generate project'
steps:
- run:
name: Generate project
environment:
GENERATOR_PRESET: 'test-project'
command: |
set GENERATOR_PRESET=test-project
node packages/pwa-kit-create-app/scripts/create-mobify-app-dev.js --outputDir generated-project
cd generated-project
no_output_timeout: 5m
- runtests:
cwd: generated-project
- smoketestscripts:
dir: generated-project
- run:
name: Count Generated Project Dependencies
environment:
command: |
MAX_PACKAGES="2260"
total=$(./scripts/count-dependencies.js generated-project)
echo "export TOTAL_PACKAGES=${total}" >> $BASH_ENV;
source $BASH_ENV
if [ "$total" -gt "$MAX_PACKAGES" ]; then
echo "Error: Found $TOTAL_PACKAGES installed packages (max $MAX_PACKAGES).";
exit 1;
else
echo "Found $TOTAL_PACKAGES installed packages (max $MAX_PACKAGES).";
fi
create_mrt_credentials_file:
steps:
- run:
name: Create MRT credentials file
command: |
# Add credentials file at ~/.mobify so we can upload to Mobify Cloud
npm run save-credentials --prefix packages/template-retail-react-app -- --user "${MOBIFY_CLIENT_USER}" --key "${MOBIFY_CLIENT_API_KEY}"
early_return_for_forked_pull_requests:
description: >-
If this build is from a fork, stop executing the current job and return success.
This is useful to avoid steps that will fail due to missing credentials.
steps:
- run:
name: Early return if this build is from a forked PR
command: |
if [ -n "$CIRCLE_PR_NUMBER" ]; then
echo "Nothing else to do for forked PRs, so marking this step successful"
circleci step halt
fi
generator_store_verdaccio_log_file_artifact:
steps:
- store_artifacts:
path: packages/pwa-kit-create-app/local-npm-repo/verdaccio.log
destination: local-npm-repo/verdaccio.log
jobs:
docs_build_and_deploy:
docker:
- image: circleci/node:14-stretch-browsers
steps:
- add_ssh_keys:
fingerprints:
- "1d:96:b9:15:51:84:09:7b:77:98:f8:ec:51:5b:43:1b"
- checkout
- setup
- run:
name: "Build and publish docs"
command: |
if [[ $RELEASE ]]; then
git config user.email "bot-pwa-kit@salesforce.com"
git config user.name "bot-pwa-kit"
cd packages/commerce-sdk-react
node ./scripts/build-and-release-docs.js
fi
testNode14Windows:
executor:
name: win/default
size: "large"
shell: bash.exe
steps:
- checkout
- setup_windows
- runtests
testNode14npm7:
docker:
- image: circleci/node:14-stretch-browsers
steps:
- checkout
- setup_npm_7
- runtests
testNode14npm8:
docker:
- image: circleci/node:14-stretch-browsers
steps:
- checkout
- setup_npm_8
- runtests
testNode14:
docker:
- image: circleci/node:14-stretch-browsers
steps:
- checkout
- setup
- runtests
- lighthouse-ci
- smoketestscripts
- early_return_for_forked_pull_requests
- create_mrt_credentials_file
- run:
name: Push Bundle
command: |
if [[ $DEVELOP || $RELEASE ]]; then
target=staging
target_commerce_sdk_react="commerce-sdk-react"
elif [[ $RELEASE ]]; then
target=production
else
target=""
fi
project="scaffold-pwa"
if [[ $target ]]; then
npm run push --prefix packages/template-retail-react-app -- -s $project --message "build ${CIRCLE_BUILD_NUM} on ${CIRCLE_BRANCH} (${CIRCLE_SHA1})" --target $target
fi
if [[ $target_commerce_sdk_react ]]; then
npm run push --prefix packages/test-commerce-sdk-react -- -s $project --message "test-commerce-sdk-react build ${CIRCLE_BUILD_NUM} on ${CIRCLE_BRANCH} (${CIRCLE_SHA1})" --target $target_commerce_sdk_react
fi
- checkclean
- run:
name: Publish to NPM
command: |
# Add NPM token to allow publishing from Circle
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
if [[ $RELEASE ]]; then
# Publish all changed packages. The "from-package" arg means "look
# at the version numbers in each package.json file and if that doesn't
# exist on NPM, publish"
npm run lerna -- publish from-package --yes --no-verify-access
fi
# Cleanup
rm ~/.npmrc
- store_test_results:
path: packages/template-retail-react-app/tests/reports
when: always
- store_artifacts:
path: packages/template-retail-react-app/tests/screenshots
when: always
- slack/status:
fail_only: true
only_for_branches: develop
generatedTemplate:
docker:
- image: circleci/node:14-stretch-browsers
parameters:
template:
type: string
steps:
- checkout
- setup
- run:
name: Generate << parameters.template >> project
environment:
GENERATOR_PRESET: << parameters.template >>
command: |
set GENERATOR_PRESET=<< parameters.template >>
node packages/pwa-kit-create-app/scripts/create-mobify-app-dev.js --outputDir generated-<< parameters.template >>
no_output_timeout: 5m
- generator_store_verdaccio_log_file_artifact
generatedTemplateWindows:
parameters:
template:
type: string
executor:
name: win/default
size: "medium"
shell: bash.exe
steps:
- checkout
- setup_windows
- run:
name: Generate << parameters.template >> project
environment:
GENERATOR_PRESET: << parameters.template >>
command: |
set GENERATOR_PRESET=<< parameters.template >>
node packages/pwa-kit-create-app/scripts/create-mobify-app-dev.js --outputDir generated-<< parameters.template >>
no_output_timeout: 5m
- generator_store_verdaccio_log_file_artifact
generatedSFCCProjectTest:
docker:
- image: circleci/node:14-stretch-browsers
steps:
- checkout
- setup
# TODO: un-comment this
# - generate_and_test_project
- early_return_for_forked_pull_requests
- create_mrt_credentials_file
- slack/status:
fail_only: true
only_for_branches: develop
- run:
name: Audit Generated Project
environment:
command: |
# This is the *most* important audit step, much more than the
# "whole monorepo" one above - bear in mind that SDK users probably
# don't care if eg. our docs site uses a vulnerable dependency.
#
# Treat failures here seriously and try to fix them before just bumping
# thresholds. These vulnerabilities create a really bad impression with our
# users during sales or in the early stages of a project.
#
# REMINDER: Have you bumped up our alpha versions? If you recently fixed some
# vulnerabilities, you will need to increment the alpha versions (so that
# publishing them to the local npm repo would be successful).
if [[ "${CIRCLE_BRANCH}" == "develop" ]]; then
# Run snyk auth - authenticate snyk using environment variables to add the token
snyk auth $SNYK_TOKEN
snyk monitor --ignore-policy --remote-repo-url='https://github.com/SalesforceCommerceCloud/pwa-kit.git' --project-name='generated-scaffold-pwa'
fi
# TODO: un-comment this block
# - run:
# name: Send metrics to Datadog
# environment:
# command: |
# # Add a dogrc so we can submit metrics to datadog
# printf "[Connection]\napikey = $DATADOG_API_KEY\nappkey =\n" > ~/.dogrc
# dog metric post mobify_platform_sdks.generated_project_total_packages $TOTAL_PACKAGES
- run:
name: Push Bundle
command: |
if [[ $DEVELOP ]]; then
target='generated-pwa'
else
target=""
fi
project="scaffold-pwa"
if [[ $target ]]; then
cd generated-project
npm run push -- -s $project --message "Generated PWA build ${CIRCLE_BUILD_NUM} on ${CIRCLE_BRANCH} (${CIRCLE_SHA1})" --target $target
fi
- generator_store_verdaccio_log_file_artifact
generatedSFCCProjectTestWindows:
executor:
name: win/default
size: "large"
shell: bash.exe
steps:
- checkout
- setup_windows
# TODO: un-comment this
# - generate_and_test_project
- generator_store_verdaccio_log_file_artifact
workflows:
version: 2
test:
jobs:
- testNode14
- testNode14Windows
- testNode14npm7
- testNode14npm8
- generatedSFCCProjectTest
- generatedSFCCProjectTestWindows
- generatedTemplate:
matrix:
parameters:
template: [express-minimal-test-project, typescript-minimal-test-project]
- generatedTemplateWindows:
matrix:
parameters:
template: [express-minimal-test-project, typescript-minimal-test-project]
- docs_build_and_deploy
nightly-build:
triggers:
- schedule:
cron: "0 8 * * *"
filters:
branches:
only:
- develop
jobs:
- testNode14:
context: nightly-build
- testNode14Windows:
context: nightly-build
- testNode14npm7:
context: nightly-build
- testNode14npm8:
context: nightly-build
- generatedSFCCProjectTest:
context: nightly-build
- generatedSFCCProjectTestWindows:
context: nightly-build
- generatedTemplate:
context: nightly-build
matrix:
parameters:
template: [ express-minimal-test-project, typescript-minimal-test-project ]
- generatedTemplateWindows:
context: nightly-build
matrix:
parameters:
template: [ express-minimal-test-project, typescript-minimal-test-project ]