config.yml 14.4 KB
Newer Older
1
2
3
defaults: &defaults
  working_directory: ~/repo

4
5
macos: &macos
  macos:
6
    xcode: "12.1.0"
7
8
9
10

bash-env: &bash-env
  BASH_ENV: "~/.nvm/nvm.sh"

11
12
13
14
15
android-env: &android-env
  JAVA_OPTS: '-Xms512m -Xmx2g'
  GRADLE_OPTS: '-Xmx3g -Dorg.gradle.daemon=false -Dorg.gradle.jvmargs="-Xmx2g -XX:+HeapDumpOnOutOfMemoryError"'
  TERM: dumb

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
install-npm-modules: &install-npm-modules
  name: Install NPM modules
  command: yarn

restore-npm-cache-linux: &restore-npm-cache-linux
  name: Restore NPM cache
  key: node-modules-{{ checksum "yarn.lock" }}

save-npm-cache-linux: &save-npm-cache-linux
  key: node-modules-{{ checksum "yarn.lock" }}
  name: Save NPM cache
  paths:
    - ./node_modules

restore-npm-cache-mac: &restore-npm-cache-mac
  name: Restore NPM cache
  key: node-v1-mac-{{ checksum "yarn.lock" }}

save-npm-cache-mac: &save-npm-cache-mac
  key: node-v1-mac-{{ checksum "yarn.lock" }}
  name: Save NPM cache
  paths:
    - ./node_modules

install-node: &install-node
41
  name: Install Node
42
  command: |
43
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
44
    source ~/.nvm/nvm.sh
45
46
    INSTALLED_NODE=`nvm which current`
    echo "export PATH=\"${INSTALLED_NODE%%/node}:\$PATH\"" >> ~/.bash_profile
47
48
49
50
51
52
53
54
55
56
57
58
    source ~/.bash_profile

restore-gems-cache: &restore-gems-cache
  name: Restore gems cache
  key: bundle-v1-{{ checksum "ios/Gemfile.lock" }}

save-gems-cache: &save-gems-cache
  name: Save gems cache
  key: bundle-v1-{{ checksum "ios/Gemfile.lock" }}
  paths:
    - vendor/bundle

59
update-fastlane-ios: &update-fastlane-ios
60
61
62
63
64
65
  name: Update Fastlane
  command: |
    echo "ruby-2.6.4" > ~/.ruby-version
    bundle install
  working_directory: ios

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
update-fastlane-android: &update-fastlane-android
  name: Update Fastlane
  command: |
    echo "ruby-2.6.4" > ~/.ruby-version
    bundle install
  working_directory: android

save-gradle-cache: &save-gradle-cache
  name: Save gradle cache
  key: android-{{ checksum "android/build.gradle" }}-{{ checksum  "android/app/build.gradle" }}
  paths:
    - ~/.gradle

restore_cache: &restore-gradle-cache
  name: Restore gradle cache
  key: android-{{ checksum "android/build.gradle" }}-{{ checksum  "android/app/build.gradle" }}

83
84
# COMMANDS
commands:
85

86
87
  android-build:
    description: "Build Android app"
88
89
90
    steps:
      - checkout

91
      - run: *install-node
92

93
      - restore_cache: *restore-npm-cache-linux
94

95
      - run: *install-npm-modules
96

97
      - restore_cache: *restore-gradle-cache
98
99

      - run:
Rodrigo Nascimento's avatar
Rodrigo Nascimento committed
100
          name: Configure Gradle
101
          command: |
102
            echo -e "" > ./gradle.properties
103
104
105
            # echo -e "android.enableAapt2=false" >> ./gradle.properties
            echo -e "android.useAndroidX=true" >> ./gradle.properties
            echo -e "android.enableJetifier=true" >> ./gradle.properties
106
            echo -e "FLIPPER_VERSION=0.51.0" >> ./gradle.properties
107
            echo -e "VERSIONCODE=$CIRCLE_BUILD_NUM" >> ./gradle.properties
108

109
110
111
112
113
114
115
116
117
118
119
            if [[ $CIRCLE_JOB == "android-build-official" ]]; then
              echo -e "APPLICATION_ID=chat.rocket.android" >> ./gradle.properties
              echo -e "BugsnagAPIKey=$BUGSNAG_KEY_OFFICIAL" >> ./gradle.properties
              echo $CHAT_ROCKET_ANDROID_STORE_FILE_BASE64_JKS | base64 --decode > ./app/$KEYSTORE_OFFICIAL
              echo -e "KEYSTORE=$KEYSTORE_OFFICIAL" >> ./gradle.properties
              echo -e "KEYSTORE_PASSWORD=$CHAT_ROCKET_ANDROID_STORE_PASSWORD" >> ./gradle.properties
              echo -e "KEY_ALIAS=$CHAT_ROCKET_ANDROID_KEY_ALIAS" >> ./gradle.properties
              echo -e "KEY_PASSWORD=$CHAT_ROCKET_ANDROID_KEY_PASSWORD" >> ./gradle.properties
            else
              echo -e "APPLICATION_ID=chat.rocket.reactnative" >> ./gradle.properties
              echo -e "BugsnagAPIKey=$BUGSNAG_KEY" >> ./gradle.properties
120
121
122
123
124
125
              echo $KEYSTORE_BASE64 | base64 --decode > ./app/$KEYSTORE
              echo -e "KEYSTORE=$KEYSTORE" >> ./gradle.properties
              echo -e "KEYSTORE_PASSWORD=$KEYSTORE_PASSWORD" >> ./gradle.properties
              echo -e "KEY_ALIAS=$KEY_ALIAS" >> ./gradle.properties
              echo -e "KEY_PASSWORD=$KEYSTORE_PASSWORD" >> ./gradle.properties
            fi
126
          working_directory: android
127

128
129
130
      - run:
          name: Set Google Services
          command: |
131
132
133
            if [[ $KEYSTORE ]]; then
              echo $GOOGLE_SERVICES_ANDROID | base64 --decode > google-services.json
            fi
134
          working_directory: android/app
135
136
137
138

      - run:
          name: Config variables
          command: |
139
140
141
142
143
            if [[ $CIRCLE_JOB == "android-build-official" ]]; then
              echo -e "export default { BUGSNAG_API_KEY: '$BUGSNAG_KEY_OFFICIAL' };" > ./config.js
            else
              echo -e "export default { BUGSNAG_API_KEY: '$BUGSNAG_KEY' };" > ./config.js
            fi
144

Rodrigo Nascimento's avatar
Rodrigo Nascimento committed
145
      - run:
146
          name: Build App
Rodrigo Nascimento's avatar
Rodrigo Nascimento committed
147
          command: |
148
149
150
151
152
153
154
155
            if [[ $CIRCLE_JOB == "android-build-official" ]]; then
              ./gradlew bundleOfficialPlayRelease
            fi
            if [[ $CIRCLE_JOB == "android-build-experimental" ]]; then
              ./gradlew bundleExperimentalPlayRelease
            fi
            if [[ ! $KEYSTORE ]]; then
              ./gradlew assembleExperimentalPlayDebug
156
            fi
157
          working_directory: android
158

159
160
161
      - run:
          name: Upload sourcemaps to Bugsnag
          command: |
162
            if [[ $CIRCLE_JOB == "android-build-official" ]]; then
163
              yarn generate-source-maps-android upload \
164
                --api-key=$BUGSNAG_KEY_OFFICIAL \
165
                --app-version=$CIRCLE_BUILD_NUM \
166
167
                --minifiedFile=android/app/build/generated/assets/react/officialPlay/release/app.bundle \
                --source-map=android/app/build/generated/sourcemaps/react/officialPlay/release/app.bundle.map \
168
169
170
                --minified-url=app.bundle \
                --upload-sources
            fi
171
172
173
174
175
176
177
178
            if [[ $CIRCLE_JOB == "android-build-experimental" ]]; then
              yarn generate-source-maps-android upload \
                --api-key=$BUGSNAG_KEY \
                --app-version=$CIRCLE_BUILD_NUM \
                --minifiedFile=android/app/build/generated/assets/react/experimentalPlay/release/app.bundle \
                --source-map=android/app/build/generated/sourcemaps/react/experimentalPlay/release/app.bundle.map \
                --minified-url=app.bundle \
                --upload-sources
Govind Dixit's avatar
Govind Dixit committed
179
180
181
182
183
184
185
186
187
188
189
190
191
192
            fi

      - store_artifacts:
          path: android/app/build/outputs

      - save_cache: *save-npm-cache-linux

      - save_cache: *save-gradle-cache

      - persist_to_workspace:
          root: .
          paths:
            - android/app/build/outputs

193
  ios-build:
194
    description: "Build iOS app"
195
196
    steps:
      - checkout
197
198
199
200
      - restore_cache: *restore-gems-cache
      - restore_cache: *restore-npm-cache-mac
      - run: *install-node
      - run: *install-npm-modules
201
      - run: *update-fastlane-ios
202
203
204
      - run:
          name: Set Google Services
          command: |
205
            if [[ $KEYSTORE ]]; then
206
              echo $GOOGLE_SERVICES_IOS | base64 --decode > GoogleService-Info.plist
207
            fi
208
          working_directory: ios
209
210
211
      - run:
          name: Upload sourcemaps to Bugsnag
          command: |
212
213
214
215
216
217
218
219
220
221
222
            if [[ $CIRCLE_JOB == "ios-build-official" ]]; then
              yarn generate-source-maps-ios
              curl https://upload.bugsnag.com/react-native-source-map \
                -F apiKey=$BUGSNAG_KEY_OFFICIAL \
                -F appBundleVersion=$CIRCLE_BUILD_NUM \
                -F dev=false \
                -F platform=ios \
                -F sourceMap=@ios-release.bundle.map \
                -F bundle=@ios-release.bundle
            fi
            if [[ $CIRCLE_JOB == "ios-build-experimental" ]]; then
223
224
225
226
227
228
229
230
231
              yarn generate-source-maps-ios
              curl https://upload.bugsnag.com/react-native-source-map \
                -F apiKey=$BUGSNAG_KEY \
                -F appBundleVersion=$CIRCLE_BUILD_NUM \
                -F dev=false \
                -F platform=ios \
                -F sourceMap=@ios-release.bundle.map \
                -F bundle=@ios-release.bundle
            fi
232
233
234
235
      - run:
          name: Fastlane Build
          no_output_timeout: 1200
          command: |
236
            agvtool new-version -all $CIRCLE_BUILD_NUM
237
238
239
240
241
242
243
            if [[ $CIRCLE_JOB == "ios-build-official" ]]; then
              /usr/libexec/PlistBuddy -c "Set BugsnagAPIKey $BUGSNAG_KEY_OFFICIAL" ./RocketChatRN/Info.plist
              /usr/libexec/PlistBuddy -c "Set IS_OFFICIAL YES" ./RocketChatRN/Info.plist
            else
              /usr/libexec/PlistBuddy -c "Set BugsnagAPIKey $BUGSNAG_KEY" ./RocketChatRN/Info.plist
              /usr/libexec/PlistBuddy -c "Set IS_OFFICIAL NO" ./RocketChatRN/Info.plist
            fi
244

245
246
            if [[ $APP_STORE_CONNECT_API_KEY ]]; then
              echo $APP_STORE_CONNECT_API_KEY | base64 --decode > ./fastlane/app_store_connect_api_key.p8
247
248
249
250
              if [[ $CIRCLE_JOB == "ios-build-official" ]]; then
                bundle exec fastlane ios build_official
              else
                if [[ $KEYSTORE ]]; then
251
                  bundle exec fastlane ios build_experimental
252
253
254
255
                else
                  bundle exec fastlane ios build_fork
                fi
              fi
256
            fi
257
          working_directory: ios
258
259
      - save_cache: *save-npm-cache-mac
      - save_cache: *save-gems-cache
260
      - store_artifacts:
261
262
263
          path: ios/Rocket.Chat.ipa
      - store_artifacts:
          path: ios/Rocket.Chat.app.dSYM.zip
264
      - persist_to_workspace:
265
          root: .
266
          paths:
267
            - ios/*.ipa
268
            - ios/*.zip
269

270
271
272
273
274
  upload-to-google-play-beta:
    description: "Upload to Google Play beta"
    parameters:
      official:
        type: boolean
275
276
    steps:
      - checkout
277
278
279
280
281
282
283
284
285
286
287
      - attach_workspace:
          at: android
      - run:
          name: Store the google service account key
          command: echo "$FASTLANE_GOOGLE_SERVICE_ACCOUNT" | base64 --decode > service_account.json
          working_directory: android
      - run: *update-fastlane-android
      - run:
          name: Fastlane Play Store Upload
          command: bundle exec fastlane android beta official:<< parameters.official >>
          working_directory: android
288

289
290
291
292
293
294
295
  upload-to-testflight:
    description: "Upload to TestFlight"
    parameters:
      official:
        type: boolean
    steps:
      - checkout
296
297
      - attach_workspace:
          at: ios
298
      - restore_cache: *restore-gems-cache
299
      - run: *update-fastlane-ios
300
301
302
      - run:
          name: Fastlane Tesflight Upload
          command: |
303
            echo $APP_STORE_CONNECT_API_KEY | base64 --decode > ./fastlane/app_store_connect_api_key.p8
304
            bundle exec fastlane ios beta official:<< parameters.official >>
305
          working_directory: ios
306
      - save_cache: *save-gems-cache
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
version: 2.1

# EXECUTORS
executors:
  mac-env:
    <<: *macos
    environment:
      <<: *bash-env

# JOBS
jobs:
  lint-testunit:
    <<: *defaults
    docker:
      - image: circleci/node:10

    environment:
      CODECOV_TOKEN: caa771ab-3d45-4756-8e2a-e1f25996fef6

    steps:
      - checkout

      - restore_cache: *restore-npm-cache-linux

      - run: *install-npm-modules

      - run:
          name: Lint
          command: |
            yarn lint

      - run:
          name: Test
          command: |
            yarn test

      - run:
          name: Codecov
          command: |
            yarn codecov

      - save_cache: *save-npm-cache-linux

  # Android builds
  android-build-experimental:
    <<: *defaults
    docker:
      - image: circleci/android:api-28-node
    environment:
      <<: *android-env
      <<: *bash-env
    steps:
      - android-build
  
  android-build-official:
    <<: *defaults
    docker:
      - image: circleci/android:api-28-node
    environment:
      <<: *android-env
      <<: *bash-env
    steps:
      - android-build

  android-google-play-beta-experimental:
    <<: *defaults
    docker:
      - image: circleci/android:api-28-node

    steps:
      - upload-to-google-play-beta:
          official: false

  android-google-play-beta-official:
    <<: *defaults
    docker:
      - image: circleci/android:api-28-node

    steps:
      - upload-to-google-play-beta:
          official: true

  # iOS builds
  ios-build-experimental:
    executor: mac-env
    steps:
      - ios-build

  ios-build-official:
    executor: mac-env
    steps:
      - ios-build

  ios-testflight-experimental:
    executor: mac-env
    steps:
      - upload-to-testflight:
          official: false

  ios-testflight-official:
    executor: mac-env
    steps:
      - upload-to-testflight:
          official: true

413
414
415
416
workflows:
  build-and-test:
    jobs:
      - lint-testunit
417

418
      # iOS Experimental
419
420
421
422
      - ios-hold-build-experimental:
          type: approval
          requires:
              - lint-testunit
423
      - ios-build-experimental:
424
          requires:
425
            - ios-hold-build-experimental
426
      - ios-hold-testflight-experimental:
427
          type: approval
428
          requires:
429
430
            - ios-build-experimental
      - ios-testflight-experimental:
431
          requires:
432
            - ios-hold-testflight-experimental
Guilherme Gazzo's avatar
Guilherme Gazzo committed
433

434
435
436
      # iOS Official
      - ios-hold-build-official:
          type: approval
437
438
          requires:
            - lint-testunit
439
440
441
442
      - ios-build-official:
          requires:
            - ios-hold-build-official
      - ios-hold-testflight-official:
443
444
          type: approval
          requires:
445
446
            - ios-build-official
      - ios-testflight-official:
447
          requires:
448
449
450
            - ios-hold-testflight-official

      # Android Experimental
451
452
453
454
      - android-hold-build-experimental:
          type: approval
          requires:
              - lint-testunit
455
456
      - android-build-experimental:
          requires:
457
            - android-hold-build-experimental
458
459
460
461
462
463
464
465
466
467
      - android-hold-google-play-beta-experimental:
          type: approval
          requires:
            - android-build-experimental
      - android-google-play-beta-experimental:
          requires:
            - android-hold-google-play-beta-experimental
      
      # Android Official
      - android-hold-build-official:
Govind Dixit's avatar
Govind Dixit committed
468
469
470
          type: approval
          requires:
            - lint-testunit
471
472
473
474
475
476
477
478
      - android-build-official:
          requires:
            - android-hold-build-official
      - android-hold-google-play-beta-official:
          type: approval
          requires:
            - android-build-official
      - android-google-play-beta-official:
Govind Dixit's avatar
Govind Dixit committed
479
          requires:
480
            - android-hold-google-play-beta-official