-
Notifications
You must be signed in to change notification settings - Fork 8
/
circle.yml
417 lines (405 loc) · 15.3 KB
/
circle.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
version: 2
jobs:
build:
docker:
- image: cypress/base:8
- image: circleci/mongo:3
working_directory: ~/TheBrain2.0
steps:
- checkout
- run:
name: Install wait-on
command: npm install -g wait-on
- run:
name: Create artifacts folders
command: |
mkdir -p ~/TheBrain2.0/server/artifacts
mkdir -p ~/TheBrain2.0/web/artifacts
mkdir -p ~/TheBrain2.0/mobile/artifacts
### SHARED PACKAGE
- restore_cache:
keys:
- npm-shared-deps-{{ checksum "./shared/package.json" }}
- run:
name: Install shared packages
working_directory: "~/TheBrain2.0/shared/"
command: npm install
- save_cache:
key: npm-shared-deps-{{ checksum "./shared/package.json" }}
paths:
- ~/TheBrain2.0/shared/node_modules
### SERVER
# - restore_cache:
# keys:
# - npm-server-deps-{{ checksum "./server/package.json" }}
- run:
name: Install server packages
working_directory: "~/TheBrain2.0/server/"
command: npm install
- run:
name: Run server integration/unit tests
working_directory: "~/TheBrain2.0/server/"
command: npm test
environment:
- CI: true
# - save_cache:
# key: npm-server-deps-{{ checksum "./server/package.json" }}
# paths:
# - ~/TheBrain2.0/server/node_modules
- run:
name: Validate standard linting rules on server
working_directory: "~/TheBrain2.0/server/"
command: npm run standard
### Web Client
- restore_cache:
keys:
- npm-web-deps-{{ checksum "./web/package.json" }}
- run:
name: Install Web Client packages
working_directory: "~/TheBrain2.0/web/"
command: npm install
- save_cache:
key: npm-web-deps-{{ checksum "./web/package.json" }}
paths:
- ~/TheBrain2.0/web/node_modules
- run:
name: Validate Standard linting rules on Web Client
working_directory: "~/TheBrain2.0/web/"
command: npm run standard
### Mobile Client
- restore_cache:
keys:
- npm-mobile-deps-{{ checksum "./mobile/package.json" }}
- run:
name: Install Mobile Client packages
working_directory: "~/TheBrain2.0/mobile/"
command: npm install
- save_cache:
key: npm-mobile-deps-{{ checksum "./mobile/package.json" }}
paths:
- ~/TheBrain2.0/mobile/node_modules
- run:
name: Validate Standard linting rules on Mobile Client
working_directory: "~/TheBrain2.0/mobile/"
command: npm run standard
### Testing package
- restore_cache:
keys:
- npm-testing-deps-{{ checksum "./package.json" }}
- run:
name: Install Testing package packages (sic!)
working_directory: "~/TheBrain2.0/"
command: npm install
- save_cache:
key: npm-testing-deps-{{ checksum "./package.json" }}
paths:
- ~/TheBrain2.0/node_modules
- run:
name: Validate standard linting rules for the testing package
working_directory: "~/TheBrain2.0/testing"
command: ../node_modules/.bin/standard .
- run:
name: Validate standard linting rules for the shared package
working_directory: "~/TheBrain2.0/shared"
command: ../node_modules/.bin/standard .
- run:
name: Enzyme almost-end to end tests for Web
working_directory: "~/TheBrain2.0/"
command: npm run enzymeTest -- --coverage --coverageDirectory coverageWeb
- run:
name: Enzyme almost-end to end tests for Mobile
working_directory: "~/TheBrain2.0/"
command: npm run enzymeTestMobile -- --coverage --coverageDirectory coverageMobile
- run:
name: Uploading the coverage to Code Climate
working_directory: "~/TheBrain2.0/"
command: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
mv coverageWeb coverage
./cc-test-reporter -d format-coverage -o codeclimate.web.json
rm -rf coverage
mv coverageMobile coverage
./cc-test-reporter -d format-coverage -o codeclimate.mobile.json
rm -rf coverage
mv server/artifacts coverage
./cc-test-reporter -d format-coverage -o codeclimate.server.json
./cc-test-reporter sum-coverage codeclimate.*.json -p 3 -o total.json
./cc-test-reporter upload-coverage -i total.json
- run:
name: Removing old deploys
working_directory: "~/TheBrain2.0/.scripts/"
command: node cleanDeployments.js
### End to end with web
- run:
name: Start the Web Client with "stateless" Server
working_directory: "~/TheBrain2.0/web"
command: npm run startForCypress
background: true
- run:
name: Wait for the "stateless" Web Client to start up
command: wait-on "http://localhost:3000" -t 30000
- run:
name: Setup the database data
working_directory: ~/TheBrain2.0/
environment:
- STAGING_MONGOURL: mongodb://localhost:27017/thebrain
command: npm run createDefaultDB
- run:
name: Start up the server
working_directory: ~/TheBrain2.0/server
command: npm start
background: true
- run:
name: Wait for the Server to start up
command: wait-on "http://localhost:8080/graphiql" -t 30000
- run:
name: Start the Web Client connecting to real server
working_directory: ~/TheBrain2.0/web
command: npm start
background: true
- run:
name: Wait for the "Real" Web Client to start up
command: wait-on "http://localhost:4000" -t 30000
- run:
name: Cypress Integration and end to end test for Web
working_directory: "~/TheBrain2.0/"
command: npm run cypressTestCI
- store_artifacts:
path: |
~/TheBrain2.0/server/artifacts
~/TheBrain2.0/web/artifacts
~/TheBrain2.0/mobile/artifacts
- store_artifacts:
path: ~/TheBrain2.0/testing/web/cypress/videos
deployServer:
docker:
- image: cypress/base:8
working_directory: ~/TheBrain2.0
steps:
- checkout
- run:
name: Generating build version label
command: BUILD_VERSION_LABEL=$(echo ${CIRCLE_BRANCH,,} | md5sum | awk -v branch=$CIRCLE_BRANCH '{ print tolower(substr(branch,0,15))"-"substr($1,0,8) }') && echo "export BUILD_VERSION_LABEL=$BUILD_VERSION_LABEL" >> $BASH_ENV
- run:
name: Install serverless
command: npm install -g serverless
### SHARED PACKAGE
- restore_cache:
keys:
- npm-shared-deps-{{ checksum "./shared/package.json" }}
- run:
name: Install shared packages
working_directory: "~/TheBrain2.0/shared/"
command: npm install
- save_cache:
key: npm-shared-deps-{{ checksum "./shared/package.json" }}
paths:
- ~/TheBrain2.0/shared/node_modules
- run:
name: Install Testing package packages (sic!)
working_directory: "~/TheBrain2.0/"
command: |
grep -v cypress package.json > package.json.new ; mv package.json.new package.json
npm install
### SERVER
# - restore_cache:
# keys:
# - npm-server-deps-{{ checksum "./server/package.json" }}
- run:
name: Install server packages
working_directory: "~/TheBrain2.0/server/"
command: npm install
- run:
name: Configure the DB for the serverless server
working_directory: ~/TheBrain2.0/
command: STAGING_MONGOURL=`echo $BASE_STAGING_MONGOURL | sed s/'${MY_DB_NAME}'/CI_${BUILD_VERSION_LABEL}/` npm run createDefaultDB
- run:
name: Extend the serverless service name with a build number
working_directory: ~/TheBrain2.0/server
command: |
sed s/thebrain-server/thebrain-server-${BUILD_VERSION_LABEL}/ serverless.yml > serverless.yml.new
mv serverless.yml.new serverless.yml
- run:
name: Build and deploy the serverless server
working_directory: ~/TheBrain2.0/server
command: |
npm run build:lambda
STAGING_MONGOURL=`echo $BASE_STAGING_MONGOURL | sed s/'${MY_DB_NAME}'/CI_${BUILD_VERSION_LABEL}/` npm run deployToServerless
cat .stack.json| grep ServiceEndpoint | awk '{print $2}' | sed s/,// | sed s/\"//g > ~/TheBrain2.0/serviceEndpoint
- persist_to_workspace:
root: ~/TheBrain2.0/
paths:
- serviceEndpoint
deployWeb:
docker:
- image: cypress/base:8
working_directory: ~/TheBrain2.0
steps:
- checkout
- run:
name: Generating build version label
command: BUILD_VERSION_LABEL=$(echo ${CIRCLE_BRANCH,,} | md5sum | awk -v branch=$CIRCLE_BRANCH '{ print tolower(substr(branch,0,15))"-"substr($1,0,8) }') && echo "export BUILD_VERSION_LABEL=$BUILD_VERSION_LABEL" >> $BASH_ENV
- run:
name: Install serverless
command: npm install -g serverless
### SHARED PACKAGE
- restore_cache:
keys:
- npm-shared-deps-{{ checksum "./shared/package.json" }}
- run:
name: Install shared packages
working_directory: "~/TheBrain2.0/shared/"
command: npm install
- save_cache:
key: npm-shared-deps-{{ checksum "./shared/package.json" }}
paths:
- ~/TheBrain2.0/shared/node_modules
### Web Client
- restore_cache:
keys:
- npm-web-deps-{{ checksum "./web/package.json" }}
- run:
name: Install Web Client packages
working_directory: "~/TheBrain2.0/web/"
command: npm install
- save_cache:
key: npm-web-deps-{{ checksum "./web/package.json" }}
paths:
- ~/TheBrain2.0/web/node_modules
- attach_workspace:
at: /tmp/workspace
- run:
name: Build and deploy the serverless web client
working_directory: ~/TheBrain2.0/web
command: |
GRAPHQL_SERVER_URI=`cat /tmp/workspace/serviceEndpoint`/graphql npm run replaceGraphqlEndpoint
cat src/networkInterface.js
sed s/thebrain-web/thebrain-web-${BUILD_VERSION_LABEL}/ ./serverless.yml > ./serverless.yml.new ; mv ./serverless.yml.new ./serverless.yml
npm run build
npm run deployToServerless
echo http://thebrain-web-${BUILD_VERSION_LABEL}.s3-website-us-east-1.amazonaws.com > ~/TheBrain2.0/webEndpoint
- persist_to_workspace:
root: ~/TheBrain2.0/
paths:
- webEndpoint
iosBuild:
macos:
xcode: "9.0"
working_directory: ~/TheBrain2.0
steps:
- checkout
- restore_cache:
keys:
- npm-mobile-deps-v2-{{ checksum "./mobile/package.json" }}
- run:
name: Install mobile packages
working_directory: ~/TheBrain2.0/mobile
command: npm install
- save_cache:
key: npm-mobile-deps-v2-{{ checksum "./mobile/package.json" }}
paths:
- ~/TheBrain2.0/mobile/node_modules
- run:
name: Install shared packages
working_directory: "~/TheBrain2.0/shared/"
command: npm install
- run:
name: Setup macosx kernel settings
command: |
sudo sysctl -w kern.maxfiles=5242880
sudo sysctl -w kern.maxfilesperproc=524288
- run:
name: Installing ios dependencies
command: |
npm install -g react-native-cli
npm install exp --global
# maybe instead of installing it globally just run post install in mobile/node_modules/detox
- run:
name: Start up mobile app
working_directory: ~/TheBrain2.0/mobile
command: npm start
background: true
- attach_workspace:
at: /tmp/workspace
- run:
name: Publish app
working_directory: ~/TheBrain2.0/mobile
command: |
GRAPHQL_SERVER_URI=`cat /tmp/workspace/serviceEndpoint`/graphql npm run changeServerURL
cat ./networkInterface.js
WEB_ENDPOINT=`cat /tmp/workspace/webEndpoint` GRAPHQL_SERVER_URI=`cat /tmp/workspace/serviceEndpoint`/graphql ./node_modules/.bin/appr
- persist_to_workspace:
root: ~/TheBrain2.0/mobile
paths:
- package.json
iosTest:
macos:
xcode: "9.0"
working_directory: ~/TheBrain2.0
steps:
- checkout
- restore_cache:
keys:
- npm-mobile-deps-v2-{{ checksum "./mobile/package.json" }}
- run:
name: Install mobile packages
working_directory: ~/TheBrain2.0/mobile
command: npm install
- save_cache:
key: npm-mobile-deps-v2-{{ checksum "./mobile/package.json" }}
paths:
- ~/TheBrain2.0/mobile/node_modules
- run:
name: Setup macosx kernel settings
command: |
sudo sysctl -w kern.maxfiles=5242880
sudo sysctl -w kern.maxfilesperproc=524288
- run:
name: Boot up the simulator so its ready for testing
command: 'xcrun simctl list | grep "Phone: iphone 7 (" -i | cut -d "(" -f 2 | cut -d ")" -f 1 | while read sim ; do xcrun simctl boot $sim ; done'
- run:
name: Installing Apple Simutils
command: |
curl "https://dl.dropboxusercontent.com/s/ycxj5wnaq8ocafz/applesimutils\?dl\=0" > /usr/local/bin/applesimutils
chmod +x /usr/local/bin/applesimutils
- run:
name: Installing expo CLI
command: npm install exp --global
- run:
name: Installing and link expo ios app
command: |
exp install:ios
mkdir ~/TheBrain2.0/mobile/.expo/
ln -s ~/.expo/ios-simulator-app-cache ~/TheBrain2.0/mobile/.expo/
- run:
name: Installing Detox globally
command: npm install -g detox@7.0.0
- attach_workspace:
at: /tmp/workspace
- run:
name: E2E ios test
working_directory: ~/TheBrain2.0/mobile
command: |
mv /tmp/workspace/package.json ~/TheBrain2.0/mobile/package.json
DETOX_EXTERNAL_LINK=https://expo.io/@thebrain/`node ./.scripts/getPackageName.js` npm run e2e
- run:
name: Github Notification
working_directory: ~/TheBrain2.0/mobile
command: ONLY_NOTIFY_GITHUB=true WEB_ENDPOINT=`cat /tmp/workspace/webEndpoint` GRAPHQL_SERVER_URI=`cat /tmp/workspace/serviceEndpoint`/graphql ./node_modules/.bin/appr
workflows:
version: 2
test_release:
jobs:
- build
- deployServer
- deployWeb:
requires:
- deployServer
- iosBuild:
requires:
- deployServer
- iosTest:
requires:
- deployWeb
- iosBuild