/
config.yml
411 lines (386 loc) · 11.5 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
version: 2.1
################################
# Aliases
################################
aliases:
- &attach_deps_workspace
at: ~/codesandbox-client
- &build_deps_paths
root: ~/codesandbox-client
paths:
- packages/codesandbox-api/dist
- packages/common/lib
- packages/components/lib
- packages/deps/dist
- packages/executors/dist
- packages/node-services/lib
- packages/notifications/lib
- packages/template-icons/lib
- packages/sse-hooks/dist
- standalone-packages/codesandbox-browserfs/dist
- standalone-packages/codesandbox-browserfs/build
- standalone-packages/vscode-textmate/out
- standalone-packages/vscode-textmate/node_modules
- &restore_deps_cache
keys:
- v36-dependency-cache-{{ .Branch }}-{{ checksum "yarn.lock" }}
- v36-dependency-cache-{{ .Branch }}
- v36-dependency-cache
- &save_deps_cache
key: v36-dependency-cache-{{ .Branch }}-{{ checksum "yarn.lock" }}
paths:
- node_modules
- packages/app/node_modules
- packages/chrome-extension/node_modules
- packages/codesandbox-api/node_modules
- packages/components/node_modules
- packages/template-icons/node_modules
- packages/common/node_modules
- packages/dynamic-pages/node_modules
- packages/deps/node_modules
- packages/executors/node_modules
- packages/homepage/node_modules
- packages/node-services/node_modules
- packages/notifications/node_modules
- packages/react-embed/node_modules
- packages/sandbox-hooks/node_modules
- packages/sse-hooks/node_modules
- &restore_standalone_deps_cache
keys:
- v36-standalone-dependency-cache-{{ .Branch }}-{{ checksum
"standalone-packages/codesandbox-browserfs/yarn.lock" }}
- v36-standalone-dependency-cache-{{ .Branch }}
- v36-standalone-dependency-cache
- &save_standalone_deps_cache
key:
v36-standalone-dependency-cache-{{ .Branch }}-{{ checksum
"standalone-packages/codesandbox-browserfs/yarn.lock" }}
paths:
- standalone-packages/codesandbox-browserfs/node_modules
- &restore_prod_homepage_cache
key: v36-prod-homepage-build-cache-master
- &restore_prod_result
key:
v36-prod-build-result-{{ .Environment.CIRCLE_BRANCH
}}-{{.Environment.CIRCLE_SHA1 }}
- &save_prod_build_cache
key:
v36-prod-build-cache-{{ .Environment.CIRCLE_BRANCH
}}-{{.Environment.CIRCLE_SHA1 }}
paths:
- packages/app/node_modules/.cache
- &restore_prod_build_cache
keys:
- v36-prod-build-cache-{{ .Environment.CIRCLE_BRANCH
}}-{{.Environment.CIRCLE_SHA1 }}
- v36-prod-build-cache-{{ .Environment.CIRCLE_BRANCH }}-
- v36-prod-build-cache-master-
# To persist the images built by sharp
- &save_prod_homepage_cache
key:
v36-prod-homepage-build-cache-{{ .Environment.CIRCLE_BRANCH }}-{{
.Environment.CIRCLE_SHA1 }}
paths:
- ./packages/homepage/public
- &save_prod_result
key:
v36-prod-build-result-{{ .Environment.CIRCLE_BRANCH }}-{{
.Environment.CIRCLE_SHA1 }}
paths:
- ./www
- ./.git
- ./Dockerfile
- &store_test_results
path: /tmp/test-results
- &store_artifacts
path: packages/app/integration-tests/tests/__image_snapshots__/__diff_output__
destination: image_snapshot_diff
################################
# Executors
################################
executors:
node:
docker:
- image: circleci/node:10
working_directory: ~/codesandbox-client
node-xlarge:
docker:
- image: circleci/node:10
resource_class: xlarge
working_directory: ~/codesandbox-client
node-with-puppeteer:
docker:
- image: codesandbox/node-puppeteer
working_directory: ~/codesandbox-client
docker_machine:
machine: true
working_directory: ~/codesandbox-client
################################
# Commands
################################
commands:
checkout_with_cache:
description: 'Checkout git with a cache'
steps:
- restore_cache:
keys:
- v36-source-cache-{{ .Branch }}-{{ .Revision }}
- v36-source-cache-{{ .Branch }}-
- v36-source-cache-
- checkout
- save_cache:
key: v36-source-cache-{{ .Branch }}-{{ .Revision }}
paths:
- '.git'
build_deps:
description: 'Install Dependencies with `yarn install`'
steps:
- restore_cache: *restore_deps_cache
- restore_cache: *restore_standalone_deps_cache
# Add extra items to yarnclean so the cache doesn't grow too big
- run:
name: Configure .yarnclean
command: cat .yarnclean.ci >> .yarnclean
- run:
name: Install Dependencies
command: yarn install
- save_cache: *save_deps_cache
- save_cache: *save_standalone_deps_cache
- run:
name: Build
command: yarn build:deps
- persist_to_workspace: *build_deps_paths
build_prod:
description: 'Build the Application with `yarn build:prod`'
steps:
- restore_cache: *restore_deps_cache
- attach_workspace: *attach_deps_workspace
- restore_cache: *restore_prod_homepage_cache
- restore_cache: *restore_prod_build_cache
- run:
name: Build Application
command: yarn build:prod
- save_cache: *save_prod_build_cache
- save_cache: *save_prod_result
- run:
name: Remove non-images from public
command: |
find packages/homepage/public -name "*.js" -type f -delete
find packages/homepage/public -name "*.json" -type f -delete
find packages/homepage/public -name "*.js.map" -type f -delete
- save_cache: *save_prod_homepage_cache
test_integrations:
description:
"Test Integrations with `yarn start:test` & 'yarn test:integrations'"
steps:
- restore_cache: *restore_deps_cache
- attach_workspace: *attach_deps_workspace
- run:
name: Start Test Server
command: yarn start:test
background: true
- run:
name: Setup BrowserStack local environment
command:
'[ -n "$BROWSER_STACK_KEY" ] &&
./packages/app/integration-tests/BrowserStackLocal --key
$BROWSER_STACK_KEY || true'
background: true
- run:
name: Test Integrations
command: |
sleep 15
yarn test:integrations --ci --testResultsProcessor="jest-junit"
environment:
JEST_JUNIT_OUTPUT: '/tmp/test-results/js-test-results.xml'
- store_test_results: *store_test_results
- store_artifacts: *store_artifacts
test_visual_regressions:
description: "Test Chromatic with 'yarn chromatic'"
steps:
- restore_cache: *restore_deps_cache
- attach_workspace: *attach_deps_workspace
- run:
command: yarn chromatic
test_jest:
description: 'Test with `yarn test`'
steps:
- restore_cache: *restore_deps_cache
- attach_workspace: *attach_deps_workspace
- run:
name: Test
command: yarn test:ci
environment:
JEST_JUNIT_OUTPUT: 'reports/junit/js-tests-results.xml'
yarn_lint:
description: 'Lint with `yarn lint`'
steps:
- restore_cache: *restore_deps_cache
- attach_workspace: *attach_deps_workspace
- run:
name: Lint
command: yarn lint
yarn_typecheck:
description: 'Lint with `yarn typecheck`'
steps:
- restore_cache: *restore_deps_cache
- attach_workspace: *attach_deps_workspace
- run:
name: Typecheck
command: yarn typecheck
docker_cache:
description: 'Cache, Sign In, Create, and Push Docker Image'
parameters:
user:
type: string
default: '$DOCKER_USER'
password:
type: string
default: '$DOCKER_PWD'
steps:
- restore_cache: *restore_prod_result
- run:
name: Docker Sign In
command:
'[ -n "<< parameters.user >>" ] && echo << parameters.password >> |
docker login -u << parameters.user >> --password-stdin || true'
- run:
name: Create DockerIgnore
command: echo '**\n!www' > .dockerignore
- run:
name: Create Image
command:
'[ -n "<< parameters.user >>" ] && docker build -t
codesandbox/client:${CIRCLE_SHA1:0:7} . || true'
- run:
name: Push Image
command:
'[ -n "<< parameters.user >>" ] && docker push
codesandbox/client:${CIRCLE_SHA1:0:7} || true'
################################
# Jobs
################################
jobs:
build-deps:
executor: node-xlarge
steps:
- checkout_with_cache
- build_deps
build-prod:
executor: node-xlarge
steps:
- checkout_with_cache
- build_prod
test-integrations:
executor: node-with-puppeteer
parallelism: 2
steps:
- checkout_with_cache
- test_integrations
test-visual-regressions:
executor: node
steps:
- checkout_with_cache
- test_visual_regressions
test-jest:
executor: node
steps:
- checkout_with_cache
- test_jest
lint:
executor: node
steps:
- checkout_with_cache
- yarn_lint
typecheck:
executor: node
steps:
- checkout_with_cache
- yarn_typecheck
create-docker-image:
executor: docker_machine
steps:
- docker_cache
deploy-to-production:
executor: node
environment:
ENVIRONMENT: prod
steps:
- checkout_with_cache
- restore_cache: *restore_deps_cache
- attach_workspace: *attach_deps_workspace
- run:
name: Mark Sentry release
command: node packages/app/scripts/sentry-create-release.js
- run:
name: Deploy Image
command: node packages/app/scripts/deploy.js
- run:
name: Deploy Sentry release
command: node packages/app/scripts/sentry-deploy-release.js
deploy-to-staging:
executor: node
environment:
ENVIRONMENT: staging
steps:
- checkout_with_cache
- restore_cache: *restore_deps_cache
- attach_workspace: *attach_deps_workspace
- run:
name: Deploy Image
command: node packages/app/scripts/deploy.js
################################
# Workflows
################################
workflows:
version: 2
build-and-test:
jobs:
- build-deps
- test-integrations:
requires:
- build-deps
- test-visual-regressions:
requires:
- build-deps
- typecheck:
requires:
- build-deps
- test-jest:
requires:
- build-deps
- lint:
requires:
- build-deps
- build-prod:
requires:
- build-deps
- create-docker-image:
requires:
- build-prod
- deploy-to-production:
requires:
- create-docker-image
- lint
- typecheck
- test-integrations
- test-jest
- test-visual-regressions
filters:
branches:
only:
- master
- deploy-staging-approval:
type: approval
filters:
branches:
ignore:
- master
- deploy-to-staging:
requires:
- deploy-staging-approval
- create-docker-image
filters:
branches:
ignore:
- master