Skip to content

Commit 49dea24

Browse files
author
Krzysztof
authored
build(ci): Improve Android e2e (#828)
* improve android e2e * use one executor for android
1 parent f2cfcd5 commit 49dea24

File tree

4 files changed

+56
-95
lines changed

4 files changed

+56
-95
lines changed

.circleci/Brewfile.android

-3
This file was deleted.

.circleci/config.yml

+33-90
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,26 @@ checkout step for each job: &addWorkspace
1818
default config for js: &js_defaults
1919
<<: *defaults
2020
docker:
21-
- image: circleci/node:14
21+
- image: cimg/node:14.18.1
2222

2323
default config for macOS: &macos_defaults
2424
<<: *defaults
2525
resource_class: 'medium'
2626
macos:
27-
xcode: '13.2.1'
27+
xcode: '13.1.0'
2828

29-
config for macOS (android): &macos_defaults_android
29+
default config for android apk tests: &android_defaults
3030
<<: *defaults
31-
resource_class: 'medium'
32-
macos:
33-
xcode: '11.5.0'
34-
35-
default config for android apk builds: &android_defaults
36-
<<: *defaults
37-
docker:
38-
- image: reactnativecommunity/react-native-android
39-
resource_class: 'medium'
40-
working_directory: ~/async_storage
41-
environment:
42-
- _JAVA_OPTIONS: '-XX:+UnlockExperimentalVMOptions -Xmx2048m'
43-
- BUILD_THREADS: 2
31+
resource_class: large
32+
machine:
33+
image: android:2022.06.2
4434

4535
# ==============================
4636
# CACHE CONFIG
4737
# ==============================
4838

4939
cache keys:
5040
brew ios: &key_brew_ios cache-brew-ios-v5-{{ arch }}
51-
brew android: &key_brew_android cache-brew-android-v4-{{ arch }}
5241
yarn: &key_yarn cache-yarn-{{ checksum "package.json" }}-{{ arch }}
5342
gradle: &key_gradle cache-gradle-v2-{{ checksum "example/android/gradle/wrapper/gradle-wrapper.properties" }}-{{ checksum "package.json" }}-{{ arch }}
5443
pods: &key_pods cache-pods-v0.64-{{ checksum "example/ios/Podfile" }}-{{ checksum "package.json" }}-{{ arch }}
@@ -66,17 +55,6 @@ cache:
6655
keys:
6756
- *key_brew_ios
6857

69-
save brew cache for android: &cache_save_brew_android
70-
name: Saving Brew cache for android
71-
paths:
72-
- ~/Library/Caches/Homebrew
73-
key: *key_brew_android
74-
75-
restore brew cache for android: &cache_restore_brew_android
76-
name: Restoring Brew cache for android
77-
keys:
78-
- *key_brew_android
79-
8058
# yarn
8159
save yarn cache: &cache_save_yarn
8260
name: Saving Yarn cache
@@ -209,10 +187,24 @@ jobs:
209187
name: Run e2e tests
210188
command: yarn test:e2e:ios
211189

212-
"Build: Android release apk":
190+
"Test: Android e2e":
213191
<<: *android_defaults
214192
steps:
215193
- *addWorkspace
194+
- run:
195+
name: "Install node v14.18.1 and yarn 1.22.17"
196+
command: |
197+
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
198+
source ~/.bashrc
199+
nvm install v14.18.1
200+
node -v
201+
npm install --global [email protected]
202+
yarn -v
203+
- restore_cache: *cache_restore_yarn
204+
- run:
205+
name: Install dependencies
206+
command: yarn --pure-lockfile --non-interactive --cache-folder ~/.cache/yarn
207+
- save_cache: *cache_save_yarn
216208
- run:
217209
name: Bundle JS
218210
command: yarn bundle:android --dev false
@@ -223,77 +215,31 @@ jobs:
223215
name: Build APK with Next storage
224216
working_directory: example/android
225217
command: ./gradlew assembleNext --max-workers 2
226-
- persist_to_workspace:
227-
root: ~/async_storage
228-
paths:
229-
- example/android/app/build/outputs/apk/*
230-
231-
"Test: Android e2e":
232-
<<: *macos_defaults_android
233-
steps:
234-
- *addWorkspace
235218
- run:
236-
name: Configure env variables
219+
name: Configure Environment Variables
237220
command: |
238-
echo 'export ANDROID_HOME="/usr/local/share/android-sdk"' >> $BASH_ENV
239-
echo 'export ANDROID_SDK_ROOT="/usr/local/share/android-sdk"' >> $BASH_ENV
240-
echo 'export PATH="$ANDROID_SDK_ROOT/emulator:$ANDROID_SDK_ROOT/tools:$ANDROID_SDK_ROOT/platform-tools:$PATH"' >> $BASH_ENV
241221
echo 'export QEMU_AUDIO_DRV=none' >> $BASH_ENV
242-
echo 'export JAVA_HOME=$(/usr/libexec/java_home)' >> $BASH_ENV
222+
echo 'export PATH="$PATH:~/async_storage/node_modules/.bin"' >> $BASH_ENV
243223
source $BASH_ENV
244-
- restore-cache: *cache_restore_brew_android
245-
- run:
246-
name: Install Android SDK tools
247-
command: |
248-
brew update --preinstall
249-
brew bundle --file=.circleci/Brewfile.android --no-lock
250-
- save-cache: *cache_save_brew_android
251224
- run:
252-
name: Install Android emulator
253-
shell: /bin/bash -e
225+
name: Install Android system image
254226
command: |
255-
yes | sdkmanager "platform-tools" "tools" 1> /dev/null
256-
yes | sdkmanager "platforms;android-28" "system-images;android-28;default;x86_64" 1> /dev/null
257-
yes | sdkmanager "emulator" --channel=3 1> /dev/null
258-
yes | sdkmanager "build-tools;28.0.3" 1> /dev/null
259-
yes | sdkmanager --licenses 1> /dev/null
260-
yes | sdkmanager --list
227+
sdkmanager "system-images;android-30;default;x86_64"
261228
- run:
262-
name: ADB start/stop
229+
name: "Create Android emulator"
263230
command: |
264-
adb start-server
265-
adb devices
266-
adb kill-server
267-
ls -la ~/.android
231+
avdmanager create avd -n E2E_API_30 -d pixel_4 --package "system-images;android-30;default;x86_64"
268232
- run:
269-
name: Create emulator
233+
name: Launch emulator
270234
command: |
271-
avdmanager create avd --force \
272-
-n "Emu_E2E" \
273-
-k "system-images;android-28;default;x86_64" \
274-
-g "default" \
275-
-d "pixel"
276-
- run:
277-
name: Start emulator in background
235+
emulator -avd E2E_API_30 -delay-adb -verbose -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim
278236
background: true
279-
command: |
280-
emulator -avd "Emu_E2E" \
281-
-cores 1 \
282-
-gpu auto \
283-
-accel on \
284-
-memory 1024 \
285-
-no-audio \
286-
-no-snapshot \
287-
-no-boot-anim \
288-
-no-window \
289-
-logcat '*:E ReactNative:W ReactNativeJS:*'
237+
- run:
238+
name: "Make sure TestButler apk is present"
239+
command: ./scripts/android_e2e.sh 'install_test_butler'
290240
- run:
291241
name: Wait for emulator to boot
292242
command: ./scripts/android_e2e.sh 'wait_for_emulator'
293-
- run:
294-
name: Wake device
295-
command: |
296-
adb shell input keyevent 82
297243
- run:
298244
name: Run e2e tests
299245
command: yarn test:e2e:android
@@ -333,14 +279,11 @@ workflows:
333279
requires:
334280
- "Test: lint"
335281
- "Test: TypeScript"
336-
- "Build: Android release apk":
282+
- "Test: Android e2e":
337283
requires:
338284
- "Test: lint"
339285
- "Test: TypeScript"
340286
- "Test: Android unit"
341-
- "Test: Android e2e":
342-
requires:
343-
- "Build: Android release apk"
344287
- "Release":
345288
requires:
346289
- "Test: iOS e2e"

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,17 @@
120120
"testBinaryPath": "example/android/app/build/outputs/apk/androidTest/release/app-release-androidTest.apk",
121121
"type": "android.emulator",
122122
"device": {
123-
"avdName": "Emu_E2E"
123+
"avdName": "E2E_API_30",
124+
"utilBinaryPaths": ["/var/tmp/test-butler.apk"]
124125
}
125126
},
126127
"android.emu.release.next": {
127128
"binaryPath": "example/android/app/build/outputs/apk/next/app-next.apk",
128129
"testBinaryPath": "example/android/app/build/outputs/apk/androidTest/release/app-release-androidTest.apk",
129130
"type": "android.emulator",
130131
"device": {
131-
"avdName": "Emu_E2E"
132+
"avdName": "E2E_API_30",
133+
"utilBinaryPaths": ["/var/tmp/test-butler.apk"]
132134
}
133135
}
134136
}

scripts/android_e2e.sh

+19
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,22 @@ wait_for_emulator_to_boot() {
4040
echo "[Detox e2e] Emulator booted."
4141
}
4242

43+
install_test_butler() {
44+
apkPath=/var/tmp/test-butler.apk
45+
46+
if [ -f $apkPath ]; then
47+
echo "[Detox e2e] TestButler apk exists, skipping"
48+
else
49+
curl -o $apkPath "https://repo1.maven.org/maven2/com/linkedin/testbutler/test-butler-app/2.2.1/test-butler-app-2.2.1.apk"
50+
echo
51+
echo "[Detox e2e] TestButler app saved to $apkPath"
52+
fi
53+
}
54+
55+
56+
57+
58+
4359

4460
case $1 in
4561
wait_for_emulator)
@@ -51,6 +67,9 @@ case $1 in
5167
bundle)
5268
shift; bundle_js $@
5369
;;
70+
install_test_butler)
71+
install_test_butler
72+
;;
5473
*)
5574
echo -n "Unknown argument: $1"
5675
;;

0 commit comments

Comments
 (0)