Skip to content

Commit 681fc5d

Browse files
thecodechefCompuIves
authored andcommitted
Rewrote circleci/config.yml to 2.1 schema (codesandbox#1786)
* Rewrote circleci/config.yml to be more DRY. * Fixed typo in create-docker-image * Fixed typo in typecheck - job
1 parent 4032aad commit 681fc5d

File tree

1 file changed

+180
-108
lines changed

1 file changed

+180
-108
lines changed

.circleci/config.yml

Lines changed: 180 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,122 @@
1-
version: 2
1+
version: 2.1
22

3-
jobs:
4-
build-dependencies:
3+
################################
4+
# Aliases
5+
################################
6+
7+
aliases:
8+
- &restore_repo_cache
9+
key: v17-repo-{{ .Environment.CIRCLE_SHA1 }}
10+
11+
- &save_repo_cache
12+
key: v17-repo-{{ .Environment.CIRCLE_SHA1 }}
13+
paths:
14+
- ~/codesandbox-client
15+
16+
- &restore_deps_cache
17+
keys:
18+
- v17-dependency-cache-{{ .Branch }}-{{ checksum "yarn.lock" }}
19+
- v17-dependency-cache-{{ .Branch }}
20+
- v17-dependency-cache
21+
22+
- &save_deps_cache
23+
key: v17-dependency-cache-{{ .Branch }}-{{ checksum "yarn.lock" }}
24+
paths:
25+
- node_modules
26+
- packages/app/node_modules
27+
- packages/chrome-extension/node_modules
28+
- packages/codesandbox-api/node_modules
29+
- packages/common/node_modules
30+
- packages/dynamic-pages/node_modules
31+
- packages/homepage/node_modules
32+
- packages/node-services/node_modules
33+
- packages/react-embed/node_modules
34+
- packages/react-sandpack/node_modules
35+
- packages/sandbox-hooks/node_modules
36+
- packages/sandpack/node_modules
37+
- packages/sse-hooks/node_modules
38+
39+
- &restore_standalone_deps_cache
40+
keys:
41+
- v17-standalone-dependency-cache-{{ .Branch }}-{{ checksum "standalone-packages/codesandbox-browserfs/yarn.lock" }}
42+
- v17-standalone-dependency-cache-{{ .Branch }}
43+
- v17-standalone-dependency-cache
44+
45+
- &save_standalone_deps_cache
46+
key: v17-standalone-dependency-cache-{{ .Branch }}-{{ checksum "standalone-packages/codesandbox-browserfs/yarn.lock" }}
47+
paths:
48+
- standalone-packages/codesandbox-browserfs/node_modules
49+
50+
- &restore_prod_build_cache
51+
key: v17-prod-app-build-cache-master
52+
53+
- &restore_prod_cache
54+
key: v17-prod-build-cache-{{ .Environment.CIRCLE_BRANCH }}-{{ .Environment.CIRCLE_SHA1 }}
55+
56+
- &save_prod_app_cache
57+
key: v17-prod-app-build-cache-{{ .Environment.CIRCLE_BRANCH }}-{{ .Environment.CIRCLE_SHA1 }}
58+
paths:
59+
- ./packages/app/www
60+
- ./packages/app/.cache-loader
61+
62+
- &save_prod_cache
63+
key: v17-prod-build-cache-{{ .Environment.CIRCLE_BRANCH }}-{{ .Environment.CIRCLE_SHA1 }}
64+
paths:
65+
- ./www
66+
67+
- &store_test_results
68+
path: /tmp/test-results
69+
70+
- &store_artifacts
71+
path: packages/app/integration-tests/tests/__image_snapshots__/__diff_output__
72+
destination: image_snapshot_diff
73+
74+
################################
75+
# Executors
76+
################################
77+
78+
executors:
79+
node:
580
docker:
681
- image: circleci/node:10
782
working_directory: ~/codesandbox-client
83+
docker_machine:
84+
machine: true
85+
working_directory: ~/codesandbox-client
86+
87+
################################
88+
# Commands
89+
################################
90+
91+
commands:
92+
build_deps:
93+
description: "Install Dependencies with `yarn install`"
894
steps:
9-
- checkout
10-
- restore_cache:
11-
keys:
12-
- v17-dependency-cache-{{ .Branch }}-{{ checksum "yarn.lock" }}
13-
- v17-dependency-cache-{{ .Branch }}
14-
- v17-dependency-cache
15-
- restore_cache:
16-
keys:
17-
- v17-standalone-dependency-cache-{{ .Branch }}-{{ checksum "standalone-packages/codesandbox-browserfs/yarn.lock" }}
18-
- v17-standalone-dependency-cache-{{ .Branch }}
19-
- v17-standalone-dependency-cache
95+
- restore_cache: *restore_deps_cache
96+
- restore_cache: *restore_standalone_deps_cache
2097
- run:
2198
name: Install Dependencies
2299
command: yarn install
23-
- save_cache:
24-
key: v17-dependency-cache-{{ .Branch }}-{{ checksum "yarn.lock" }}
25-
paths:
26-
- node_modules
27-
- packages/app/node_modules
28-
- packages/chrome-extension/node_modules
29-
- packages/codesandbox-api/node_modules
30-
- packages/common/node_modules
31-
- packages/dynamic-pages/node_modules
32-
- packages/homepage/node_modules
33-
- packages/node-services/node_modules
34-
- packages/react-embed/node_modules
35-
- packages/react-sandpack/node_modules
36-
- packages/sandbox-hooks/node_modules
37-
- packages/sandpack/node_modules
38-
- packages/sse-hooks/node_modules
39-
- save_cache:
40-
key: v17-standalone-dependency-cache-{{ .Branch }}-{{ checksum "standalone-packages/codesandbox-browserfs/yarn.lock" }}
41-
paths:
42-
- standalone-packages/codesandbox-browserfs/node_modules
100+
- save_cache: *save_deps_cache
101+
- save_cache: *save_standalone_deps_cache
43102
- run:
44103
name: Build
45104
command: yarn build:deps
46-
- save_cache:
47-
key: v17-repo-{{ .Environment.CIRCLE_SHA1 }}
48-
paths:
49-
- ~/codesandbox-client
50-
51-
build-prod:
52-
docker:
53-
- image: circleci/node:10
54-
working_directory: ~/codesandbox-client
105+
- save_cache: *save_repo_cache
106+
build_prod:
107+
description: "Build the Application with `yarn build:prod`"
55108
steps:
56-
- restore_cache:
57-
key: v17-repo-{{ .Environment.CIRCLE_SHA1 }}
58-
# We do this to compare sizes from these builds with master
59-
- restore_cache:
60-
key: v17-prod-app-build-cache-master
109+
- restore_cache: *restore_repo_cache
110+
- restore_cache: *restore_prod_build_cache
61111
- run:
62112
name: Build Application
63113
command: yarn build:prod
64-
- save_cache:
65-
key: v17-prod-app-build-cache-{{ .Environment.CIRCLE_BRANCH }}-{{ .Environment.CIRCLE_SHA1 }}
66-
paths:
67-
- ./packages/app/www
68-
- ./packages/app/.cache-loader
69-
- save_cache:
70-
key: v17-prod-build-cache-{{ .Environment.CIRCLE_BRANCH }}-{{ .Environment.CIRCLE_SHA1 }}
71-
paths:
72-
- ./www
73-
74-
test-integrations:
75-
docker:
76-
- image: codesandbox/node-puppeteer
77-
working_directory: ~/codesandbox-client
114+
- save_cache: *save_prod_app_cache
115+
- save_cache: *save_prod_cache
116+
test_integrations:
117+
description: "Test Integrations with `yarn start:test` & 'yarn test:integrations'"
78118
steps:
79-
- restore_cache:
80-
key: v17-repo-{{ .Environment.CIRCLE_SHA1 }}
119+
- restore_cache: *restore_repo_cache
81120
- run:
82121
name: Start Test Server
83122
command: yarn start:test
@@ -93,84 +132,117 @@ jobs:
93132
yarn test:integrations --ci --testResultsProcessor="jest-junit"
94133
environment:
95134
JEST_JUNIT_OUTPUT: '/tmp/test-results/js-test-results.xml'
96-
- store_test_results:
97-
path: /tmp/test-results
98-
- store_artifacts:
99-
path: packages/app/integration-tests/tests/__image_snapshots__/__diff_output__
100-
destination: image_snapshot_diff
101-
102-
test-jest:
103-
docker:
104-
- image: circleci/node:10
105-
working_directory: ~/codesandbox-client
135+
- store_test_results: *store_test_results
136+
- store_artifacts: *store_artifacts
137+
test_jest:
138+
description: "Test with `yarn test`"
106139
steps:
107-
- restore_cache:
108-
key: v17-repo-{{ .Environment.CIRCLE_SHA1 }}
140+
- restore_cache: *restore_repo_cache
109141
- run:
110142
name: Test
111143
command: yarn test --ci --testResultsProcessor="jest-junit"
112144
environment:
113-
JEST_JUNIT_OUTPUT: 'reports/junit/js-test-results.xml'
114-
115-
lint:
116-
docker:
117-
- image: circleci/node:10
118-
working_directory: ~/codesandbox-client
145+
JEST_JUNIT_OUTPUT: 'reports/junit/js-tests-results.xml'
146+
yarn_lint:
147+
description: "Lint with `yarn lint`"
119148
steps:
120-
- restore_cache:
121-
key: v17-repo-{{ .Environment.CIRCLE_SHA1 }}
149+
- restore_cache: *restore_repo_cache
122150
- run:
123151
name: Lint
124152
command: yarn lint
125-
126-
typecheck:
127-
docker:
128-
- image: circleci/node:10
129-
working_directory: ~/codesandbox-client
153+
yarn_typecheck:
154+
description: "Lint with `yarn typecheck`"
130155
steps:
131-
- restore_cache:
132-
key: v17-repo-{{ .Environment.CIRCLE_SHA1 }}
156+
- restore_cache: *restore_repo_cache
133157
- run:
134158
name: Lint
135159
command: yarn typecheck
136-
137-
create-docker-image:
138-
machine: true
139-
working_directory: ~/codesandbox-client
160+
docker_cache:
161+
description: "Cache, Sign In, Create, and Push Docker Image"
162+
parameters:
163+
user:
164+
type: string
165+
default: "$DOCKER_USER"
166+
password:
167+
type: string
168+
default: "$DOCKER_PWD"
140169
steps:
141-
- checkout
142-
- restore_cache:
143-
key: v17-prod-build-cache-{{ .Environment.CIRCLE_BRANCH }}-{{ .Environment.CIRCLE_SHA1 }}
170+
- restore_cache: *restore_prod_cache
144171
- run:
145172
name: Docker Sign In
146-
command: '[ -n "$DOCKER_USER" ] && echo $DOCKER_PWD | docker login -u $DOCKER_USER --password-stdin || true'
173+
command: '[ -n << parameters.user >> ] && echo << parameters.password >> | docker login -u << parameters.user >> --password-stdin || true'
147174
- run:
148175
name: Create Image
149-
command: '[ -n "$DOCKER_USER" ] && docker build -t codesandbox/client:${CIRCLE_SHA1:0:7} . || true'
150-
- deploy:
176+
command: '[ -n << parameters.user >> ] && docker build -t codesandbox/client:${CIRCLE_SHA1:0:7} . || true'
177+
- run:
151178
name: Push Image
152-
command: '[ -n "$DOCKER_USER" ] && docker push codesandbox/client:${CIRCLE_SHA1:0:7} || true'
179+
command: '[ -n << parameters.user >> ] && docker push codesandbox/client:${CIRCLE_SHA1:0:7} || true'
180+
181+
################################
182+
# Jobs
183+
################################
184+
185+
jobs:
186+
build-deps:
187+
executor: node
188+
steps:
189+
- checkout
190+
- build_deps
191+
build-prod:
192+
executor: node
193+
steps:
194+
- checkout
195+
- build_prod
196+
test-integrations:
197+
executor: node
198+
steps:
199+
- checkout
200+
- test_integrations
201+
test-jest:
202+
executor: node
203+
steps:
204+
- checkout
205+
- test_jest
206+
lint:
207+
executor: node
208+
steps:
209+
- checkout
210+
- yarn_lint
211+
typecheck:
212+
executor: node
213+
steps:
214+
- checkout
215+
- yarn_typecheck
216+
create-docker-image:
217+
executor: docker_machine
218+
steps:
219+
- checkout
220+
- docker_cache
221+
222+
################################
223+
# Workflows
224+
################################
153225

154226
workflows:
155227
version: 2
156228
build-and-test:
157229
jobs:
158-
- build-dependencies
230+
- build-deps
159231
- test-integrations:
160232
requires:
161-
- build-dependencies
233+
- build-deps
162234
- typecheck:
163235
requires:
164-
- build-dependencies
236+
- build-deps
165237
- test-jest:
166238
requires:
167-
- build-dependencies
239+
- build-deps
168240
- lint:
169241
requires:
170-
- build-dependencies
242+
- build-deps
171243
- build-prod:
172244
requires:
173-
- build-dependencies
245+
- build-deps
174246
- create-docker-image:
175247
requires:
176248
- build-prod

0 commit comments

Comments
 (0)