-
Notifications
You must be signed in to change notification settings - Fork 54
/
config.yml
422 lines (414 loc) · 16.6 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
version: 2.1
orbs:
slack: circleci/slack@3.4.2
commands:
npm-install:
steps:
- restore_cache:
name: Restore NPM Cache
keys:
- npm-i18n-v4-cache-v{{ .Environment.CACHE_TRIGGER_VERSION }}-job-{{ .Environment.CIRCLE_JOB }}-{{ checksum "package-lock.json" }}
- run:
name: NPM Install
command: npm ci --prefer-offline
- save_cache:
name: Save NPM Cache
key: npm-i18n-v4-cache-v{{ .Environment.CACHE_TRIGGER_VERSION }}-job-{{ .Environment.CIRCLE_JOB }}-{{ checksum "package-lock.json" }}
paths:
- ~/.npm
- i18n-cache/data
npm-install-full:
steps:
- restore_cache:
name: Restore NPM Cache
keys:
- npm-i18n-v4-cache-v{{ .Environment.CACHE_TRIGGER_VERSION }}-job-{{ .Environment.CIRCLE_JOB }}-{{ checksum "gutenberg/package-lock.json" }}
- run:
name: NPM Install Full
command: npm install
- save_cache:
name: Save NPM Cache
key: npm-i18n-v4-cache-v{{ .Environment.CACHE_TRIGGER_VERSION }}-job-{{ .Environment.CIRCLE_JOB }}-{{ checksum "gutenberg/package-lock.json" }}
paths:
- ~/.npm
- i18n-cache/data
checkout-submodules:
steps:
- run:
name: Checkout Submodules
command: git submodule update --init --recursive
add-jest-reporter-dir:
steps:
- run:
name: Create reports directory
command: mkdir reports && mkdir reports/test-results
parameters:
android-docker-image:
type: string
# Hash points to previous version with node 12. When everything works with node 14 it can be removed
default: "circleci/android:api-29-node@sha256:71d61d6c21b29948d57120f476a83cc322a280979bce355c5a0ad771293ca380"
linux-machine-image:
type: string
# Latest supported ubuntu image from https://circleci.com/docs/2.0/configuration-reference/#available-machine-images
default: "ubuntu-2004:202010-01"
jobs:
checks:
parameters:
platform:
type: string
default: ""
check-tests:
type: boolean
default: false
check-correctness:
type: boolean
default: false
machine:
image: << pipeline.parameters.linux-machine-image >>
steps:
- checkout
- checkout-submodules
- run:
name: Install newer nvm
command: curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
- run:
name: Install newer node using nvm
command: |
cd gutenberg
nvm install
- when:
condition: <<parameters.check-correctness>>
steps:
- npm-install-full
- unless:
condition: <<parameters.check-correctness>>
steps:
- npm-install
- add-jest-reporter-dir
- run:
name: Set Environment Variables
command: |
echo 'export CHECK_CORRECTNESS=<<parameters.check-correctness>>' >> $BASH_ENV
echo 'export CHECK_TESTS=<<parameters.check-tests>>' >> $BASH_ENV
echo 'export TEST_RN_PLATFORM=<<parameters.platform>>' >> $BASH_ENV
- run:
name: Run Checks
command: bin/ci-checks-js.sh
environment:
JEST_JUNIT_OUTPUT: "reports/test-results/android-test-results.xml"
- store_test_results:
path: ./reports/test-results
android-device-checks:
parameters:
post-to-slack:
description: Post to Slack when tests fail. SLACK_WEBHOOK ENV variable must be set.
type: boolean
default: false
is-canary:
type: string
default: ""
machine:
image: << pipeline.parameters.linux-machine-image >>
steps:
- checkout
- checkout-submodules
- run: node -v
- run: npm install -g yarn
- npm-install
- run: npm run test:e2e:bundle:android
- run:
name: Build apk
command: |
docker run --rm -it \
--volume $(pwd):/home/circleci/project \
--workdir /home/circleci/project \
--env JAVA_OPTS='-Xms512m -Xmx2g' \
--env GRADLE_OPTS='-Xmx3g -Dorg.gradle.daemon=false -Dorg.gradle.jvmargs="-Xmx2g -XX:+HeapDumpOnOutOfMemoryError"' \
<< pipeline.parameters.android-docker-image >> \
/bin/bash -c "sudo chown -R circleci:circleci . && npm run core test:e2e:build-app:android"
- run:
name: Upload apk to sauce labs
command: |
source bin/sauce-pre-upload.sh
curl -u "$SAUCE_USERNAME:$SAUCE_ACCESS_KEY" -X POST -H "Content-Type: application/octet-stream" https://saucelabs.com/rest/v1/storage/automattic/Gutenberg-$SAUCE_FILENAME.apk?overwrite=true --data-binary @./gutenberg/packages/react-native-editor/android/app/build/outputs/apk/debug/app-debug.apk
- run: mkdir /home/circleci/test-results
- run:
name: Run Device Tests
command: npm run device-tests<<parameters.is-canary>>
no_output_timeout: 1200
environment:
TEST_RN_PLATFORM: android
TEST_ENV: sauce
JEST_JUNIT_OUTPUT: "/home/circleci/test-results/android-test-results.xml"
- store_test_results:
path: /home/circleci/test-results
- when:
condition: << parameters.post-to-slack >>
steps:
- slack/status:
fail_only: true
include_job_number_field: false
include_project_field: false
failure_message: ':red_circle: Scheduled tests failed on Android device!'
android-native-unit-tests:
parameters:
post-to-slack:
description: Post to Slack when tests fail. SLACK_WEBHOOK ENV variable must be set.
type: boolean
default: false
docker:
- image: << pipeline.parameters.android-docker-image >>
steps:
- checkout
- checkout-submodules
- npm-install
- run:
name: Run Android native unit tests
command: cd gutenberg/packages/react-native-editor/android && ./gradlew testDebug
ios-device-checks:
parameters:
post-to-slack:
description: Post to Slack when tests fail. SLACK_WEBHOOK ENV variable must be set.
type: boolean
default: false
is-canary:
type: string
default: ""
macos:
xcode: "12.0.0"
steps:
- checkout
- checkout-submodules
- npm-install
- add-jest-reporter-dir
- run:
name: Set Environment Variables
command: |
echo 'export TEST_RN_PLATFORM=ios' >> $BASH_ENV
echo 'export TEST_ENV=sauce' >> $BASH_ENV
- run:
name: Prepare build cache key
command: find gutenberg/package-lock.json gutenberg/packages/react-native-editor/ios gutenberg/packages/react-native-aztec/ios gutenberg/packages/react-native-bridge/ios -type f -print0 | sort -z | xargs -0 shasum | tee ios-checksums.txt
- restore_cache:
name: Restore Build Cache
keys:
- ios-build-cache-{{ checksum "ios-checksums.txt" }}
- restore_cache:
name: Restore Dependencies Cache
keys:
- dependencies-v4-{{ checksum "gutenberg/packages/react-native-editor/ios/Gemfile.lock" }}-{{ checksum "gutenberg/packages/react-native-editor/ios/Podfile.lock" }}-{{ checksum "gutenberg/package-lock.json" }}
- dependencies-v4-{{ checksum "gutenberg/packages/react-native-editor/ios/Gemfile.lock" }}-{{ checksum "gutenberg/packages/react-native-editor/ios/Podfile.lock" }}
- dependencies-v4-{{ checksum "gutenberg/packages/react-native-editor/ios/Gemfile.lock" }}
- dependencies-v4-
- run:
name: Build (if needed)
command: test -e gutenberg/packages/react-native-editor/ios/build/GutenbergDemo/Build/Products/Release-iphonesimulator/GutenbergDemo.app || npm run core test:e2e:build-app:ios
- save_cache:
name: Save Dependencies Cache
key: dependencies-v4-{{ checksum "gutenberg/packages/react-native-editor/ios/Gemfile.lock" }}-{{ checksum "gutenberg/packages/react-native-editor/ios/Podfile.lock" }}-{{ checksum "gutenberg/package-lock.json" }}
paths:
- gutenberg/packages/react-native-editor/ios/Pods
- ~/Library/Caches/CocoaPods
- ~/.cocoapods/repos/trunk
- gutenberg/packages/react-native-editor/ios/vendor
- run:
name: Bundle iOS
command: npm run test:e2e:bundle:ios
- run:
name: Generate .app file for testing
command: WORK_DIR=$(pwd) && cd ./gutenberg/packages/react-native-editor/ios/build/GutenbergDemo/Build/Products/Release-iphonesimulator && zip -r $WORK_DIR/gutenberg/packages/react-native-editor/ios/GutenbergDemo.app.zip GutenbergDemo.app
- run:
name: Upload .app to sauce labs
command: |
source bin/sauce-pre-upload.sh
HOMEBREW_NO_AUTO_UPDATE=1 brew install curl
/usr/local/opt/curl/bin/curl --version
/usr/local/opt/curl/bin/curl -u "$SAUCE_USERNAME:$SAUCE_ACCESS_KEY" -X POST -H "Content-Type: application/octet-stream" https://saucelabs.com/rest/v1/storage/automattic/Gutenberg-$SAUCE_FILENAME.app.zip?overwrite=true --data-binary @./gutenberg/packages/react-native-editor/ios/GutenbergDemo.app.zip
- run:
name: Run Device Tests
command: |
npm run device-tests<<parameters.is-canary>>
no_output_timeout: 1200
environment:
JEST_JUNIT_OUTPUT: "reports/test-results/ios-test-results.xml"
- store_test_results:
path: ./reports/test-results
- run:
name: Prepare build cache
command: rm gutenberg/packages/react-native-editor/ios/build/GutenbergDemo/Build/Products/Release-iphonesimulator/GutenbergDemo.app/main.jsbundle
- save_cache:
name: Save Build Cache
key: ios-build-cache-{{ checksum "ios-checksums.txt" }}
paths:
- gutenberg/packages/react-native-editor/ios/build/GutenbergDemo/Build/Products/Release-iphonesimulator/GutenbergDemo.app
- when:
condition: << parameters.post-to-slack >>
steps:
- slack/status:
fail_only: true
include_job_number_field: false
include_project_field: false
failure_message: ':red_circle: Scheduled tests failed on iOS device!'
android-build-and-publish-react-native-bridge:
# This job builds the JS bunle required by the Android version of the
# react-native-bridge package, builds the AAR for that package, and uploads
# it to S3.
#
# Running on a Ubuntu machine to have more memory compared to the Docker +
# Node or Docker + Android images that CircleCI offers (circleci/node)
#
# Also running all in one job so that we can bail out early under cetrain
# conditions and save CI cycles.
#
# See: https://github.com/wordpress-mobile/gutenberg-mobile/pull/3038#issuecomment-765334675
machine:
image: << pipeline.parameters.linux-machine-image >>
steps:
- run:
name: Evaluate whether to run
command: |
# This is a partial duplication of the logic to compute the version
# to use for the AAR from below. It's useful to have it here
# because there are conditions under which we shouldn't run the job
# that can't be captured in a CircleCI filter.
#
# Exiting here saves a non-trivial amount of CI time because of how
# heavy the repo is to checkout (it takes at least 1 minute) and
# how time consuming running `npm ci` is.
if [[ -z ${CIRCLE_TAG+x} ]]; then
if [[ -n "$CIRCLE_PULL_REQUEST" ]]; then
echo "Build initiated from a branch with a pull request: proceeding..."
elif [[ $CIRCLE_BRANCH == "develop" ]]; then
echo "Build initiated on $CIRCLE_BRANCH: proceeding..."
else
# We end up here on the first push of a new branch, when there
# isn't a PR open for it yet.
echo "Build initiated from a feature branch with no pull request: aborting."
circleci-agent step halt
fi
else
echo "Build initiated from a tag: proceeding..."
fi
- checkout
- checkout-submodules
- run:
# Setting up Android before fetching the Node dependencies because
# this step is faster, so if it fails we'll learn about it sooner and
# avoid wasting cycles.
name: Setup Android Tooling
command: .circleci/setup-android-on-ubuntu.sh
- npm-install
- run:
name: Build JavaScript Bundle
command: |
npm run core prebundle
npm run bundle:android
# The job can take a long time, so let's bump the no_output_timeout
# to more than the default 10m
no_output_timeout: 20m
- run:
name: Build React Native Bridge & Upload to S3
environment:
# This value is set in the setup script, but I'm not sure whether
# it's available after executing it
ANDROID_SDK_ROOT: /usr/lib/android-sdk
command: |
# We publish from PRs as well as the main branch and tags to help
# developers to iterate faster.
#
# If we're not on a PR but a merge commit on the develop branch the
# version will be the "develop-" followed by the commit SHA1.
#
# On a tag, the version should be the tag value.
#
# If we're on a different branch that has no open PR, we should
# not build and exit early instead.
if [[ -z "${CIRCLE_TAG+x}" ]]; then
if [[ -n "$CIRCLE_PULL_REQUEST" ]]; then
PR_NUMBER=$(basename $CIRCLE_PULL_REQUEST)
# CIRCLE_SHA1 should always be available.
VERSION="$PR_NUMBER-$CIRCLE_SHA1"
elif [[ $CIRCLE_BRANCH == "develop" ]]; then
VERSION="$CIRCLE_BRANCH-$CIRCLE_SHA1"
else
# This happens on the first push of a new branch, when there
# isn't a PR open for it yet.
echo "Running on a feature branch with no open PR."
echo "The checks previous to this step should not have let this happen."
exit 1
fi
else
VERSION=$CIRCLE_TAG
fi
cd gutenberg/packages/react-native-bridge/android
./publish-aztec-and-bridge.sh $VERSION
workflows:
gutenberg-mobile:
jobs:
- checks:
name: Check Correctness
check-correctness: true
- checks:
name: Test iOS
platform: ios
check-tests: true
- checks:
name: Test Android
platform: android
check-tests: true
- ios-device-checks:
name: Test iOS on Device - Canaries
is-canary: "-canary"
- android-device-checks:
name: Test Android on Device - Canaries
is-canary: "-canary"
- Optional UI Tests:
type: approval
filters:
branches:
ignore:
- develop
- /^dependabot/submodules/.*/
- ios-device-checks:
name: Test iOS on Device - Full
requires: [ "Optional UI Tests" ]
- android-device-checks:
name: Test Android on Device - Full
requires: [ "Optional UI Tests" ]
- android-native-unit-tests:
name: Android Native Unit Tests
- ios-device-checks:
name: Test iOS on Device - Full (Submodule Update)
post-to-slack: true
filters:
branches:
only: /^dependabot/submodules/.*/
- android-device-checks:
name: Test Android on Device - Full (Submodule Update)
post-to-slack: true
filters:
branches:
only: /^dependabot/submodules/.*/
- android-build-and-publish-react-native-bridge:
name: Build Android RN Bridge & Publish to S3
filters:
branches:
# Don't run on trunk, otherwise, run on every other branch
ignore: trunk
tags:
# Run for every tag
only: /.*/
ui-tests-full-scheduled:
jobs:
- ios-device-checks:
name: Test iOS on Device - Scheduled
post-to-slack: true
- android-device-checks:
name: Test Android on Device - Scheduled
post-to-slack: true
triggers:
- schedule:
cron: '1 1,13 * * *'
filters:
branches:
only: develop