Skip to content

build(ci): Improve Android e2e #828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .circleci/Brewfile.android

This file was deleted.

108 changes: 36 additions & 72 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,35 @@ checkout step for each job: &addWorkspace
default config for js: &js_defaults
<<: *defaults
docker:
- image: circleci/node:14
- image: cimg/node:14.18.1

default config for macOS: &macos_defaults
<<: *defaults
resource_class: 'medium'
macos:
xcode: '13.2.1'
xcode: '13.1.0'

config for macOS (android): &macos_defaults_android
config for android e2e: &android_e2e
<<: *defaults
resource_class: 'medium'
macos:
xcode: '11.5.0'
resource_class: large
machine:
image: android:2022.06.2

default config for android apk builds: &android_defaults
<<: *defaults
docker:
- image: reactnativecommunity/react-native-android
resource_class: 'medium'
working_directory: ~/async_storage
- image: cimg/android:2021.10.2-node # node 14.18.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this also use cimg/node:14.18.1 as above? Or android:2022.06.2?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This image has Android SDK preinstalled, and is used to create an apk for tests. I could merge the apk creation into e2e job, since it's no longer macos.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a cost to spinning up a separate machine? I'd imagine we should stay on the same machine for as long as possible, but I don't know how CircleCI works.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's no cost for boot up, but rather the overall execution time.

resource_class: medium
environment:
- _JAVA_OPTIONS: '-XX:+UnlockExperimentalVMOptions -Xmx2048m'
- BUILD_THREADS: 2
JAVA_OPTIONS: '-XX:+UnlockExperimentalVMOptions -Xmx2048m'
BUILD_THREADS: 2

# ==============================
# CACHE CONFIG
# ==============================

cache keys:
brew ios: &key_brew_ios cache-brew-ios-v5-{{ arch }}
brew android: &key_brew_android cache-brew-android-v4-{{ arch }}
yarn: &key_yarn cache-yarn-{{ checksum "package.json" }}-{{ arch }}
gradle: &key_gradle cache-gradle-v2-{{ checksum "example/android/gradle/wrapper/gradle-wrapper.properties" }}-{{ checksum "package.json" }}-{{ arch }}
pods: &key_pods cache-pods-v0.64-{{ checksum "example/ios/Podfile" }}-{{ checksum "package.json" }}-{{ arch }}
Expand All @@ -66,17 +64,6 @@ cache:
keys:
- *key_brew_ios

save brew cache for android: &cache_save_brew_android
name: Saving Brew cache for android
paths:
- ~/Library/Caches/Homebrew
key: *key_brew_android

restore brew cache for android: &cache_restore_brew_android
name: Restoring Brew cache for android
keys:
- *key_brew_android

# yarn
save yarn cache: &cache_save_yarn
name: Saving Yarn cache
Expand Down Expand Up @@ -229,71 +216,48 @@ jobs:
- example/android/app/build/outputs/apk/*

"Test: Android e2e":
<<: *macos_defaults_android
<<: *android_e2e
steps:
- *addWorkspace
- run:
name: Configure env variables
name: "Install node v14.18.1 and yarn 1.22.17"
command: |
echo 'export ANDROID_HOME="/usr/local/share/android-sdk"' >> $BASH_ENV
echo 'export ANDROID_SDK_ROOT="/usr/local/share/android-sdk"' >> $BASH_ENV
echo 'export PATH="$ANDROID_SDK_ROOT/emulator:$ANDROID_SDK_ROOT/tools:$ANDROID_SDK_ROOT/platform-tools:$PATH"' >> $BASH_ENV
echo 'export QEMU_AUDIO_DRV=none' >> $BASH_ENV
echo 'export JAVA_HOME=$(/usr/libexec/java_home)' >> $BASH_ENV
source $BASH_ENV
- restore-cache: *cache_restore_brew_android
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
source ~/.bashrc
nvm install v14.18.1
node -v
npm install --global [email protected]
yarn -v
- restore_cache: *cache_restore_yarn
- run:
name: Install Android SDK tools
command: |
brew update --preinstall
brew bundle --file=.circleci/Brewfile.android --no-lock
- save-cache: *cache_save_brew_android
name: Install dependencies
command: yarn --pure-lockfile --non-interactive --cache-folder ~/.cache/yarn
- save_cache: *cache_save_yarn
- run:
name: Install Android emulator
shell: /bin/bash -e
name: Configure Environment Variables
command: |
yes | sdkmanager "platform-tools" "tools" 1> /dev/null
yes | sdkmanager "platforms;android-28" "system-images;android-28;default;x86_64" 1> /dev/null
yes | sdkmanager "emulator" --channel=3 1> /dev/null
yes | sdkmanager "build-tools;28.0.3" 1> /dev/null
yes | sdkmanager --licenses 1> /dev/null
yes | sdkmanager --list
echo 'export QEMU_AUDIO_DRV=none' >> $BASH_ENV
echo 'export PATH="$PATH:~/async_storage/node_modules/.bin"' >> $BASH_ENV
source $BASH_ENV
- run:
name: ADB start/stop
name: Install Android system image
command: |
adb start-server
adb devices
adb kill-server
ls -la ~/.android
sdkmanager "system-images;android-30;default;x86_64"
- run:
name: Create emulator
name: "Create Android emulator"
command: |
avdmanager create avd --force \
-n "Emu_E2E" \
-k "system-images;android-28;default;x86_64" \
-g "default" \
-d "pixel"
avdmanager create avd -n E2E_API_30 -d pixel_4 --package "system-images;android-30;default;x86_64"
- run:
name: Start emulator in background
background: true
name: Launch emulator
command: |
emulator -avd "Emu_E2E" \
-cores 1 \
-gpu auto \
-accel on \
-memory 1024 \
-no-audio \
-no-snapshot \
-no-boot-anim \
-no-window \
-logcat '*:E ReactNative:W ReactNativeJS:*'
emulator -avd E2E_API_30 -delay-adb -verbose -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim
background: true
- run:
name: "Make sure TestButler apk is present"
command: ./scripts/android_e2e.sh 'install_test_butler'
- run:
name: Wait for emulator to boot
command: ./scripts/android_e2e.sh 'wait_for_emulator'
- run:
name: Wake device
command: |
adb shell input keyevent 82
- run:
name: Run e2e tests
command: yarn test:e2e:android
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,17 @@
"testBinaryPath": "example/android/app/build/outputs/apk/androidTest/release/app-release-androidTest.apk",
"type": "android.emulator",
"device": {
"avdName": "Emu_E2E"
"avdName": "E2E_API_30",
"utilBinaryPaths": ["/var/tmp/test-butler.apk"]
}
},
"android.emu.release.next": {
"binaryPath": "example/android/app/build/outputs/apk/next/app-next.apk",
"testBinaryPath": "example/android/app/build/outputs/apk/androidTest/release/app-release-androidTest.apk",
"type": "android.emulator",
"device": {
"avdName": "Emu_E2E"
"avdName": "E2E_API_30",
"utilBinaryPaths": ["/var/tmp/test-butler.apk"]
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions scripts/android_e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ wait_for_emulator_to_boot() {
echo "[Detox e2e] Emulator booted."
}

install_test_butler() {
apkPath=/var/tmp/test-butler.apk

if [ -f $apkPath ]; then
echo "[Detox e2e] TestButler apk exists, skipping"
else
curl -o $apkPath "https://repo1.maven.org/maven2/com/linkedin/testbutler/test-butler-app/2.2.1/test-butler-app-2.2.1.apk"
echo
echo "[Detox e2e] TestButler app saved to $apkPath"
fi
}






case $1 in
wait_for_emulator)
Expand All @@ -51,6 +67,9 @@ case $1 in
bundle)
shift; bundle_js $@
;;
install_test_butler)
install_test_butler
;;
*)
echo -n "Unknown argument: $1"
;;
Expand Down