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 all commits
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.

123 changes: 33 additions & 90 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,26 @@ 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
default config for android apk tests: &android_defaults
<<: *defaults
resource_class: 'medium'
macos:
xcode: '11.5.0'

default config for android apk builds: &android_defaults
<<: *defaults
docker:
- image: reactnativecommunity/react-native-android
resource_class: 'medium'
working_directory: ~/async_storage
environment:
- _JAVA_OPTIONS: '-XX:+UnlockExperimentalVMOptions -Xmx2048m'
- BUILD_THREADS: 2
resource_class: large
machine:
image: android:2022.06.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 +55,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 @@ -209,10 +187,24 @@ jobs:
name: Run e2e tests
command: yarn test:e2e:ios

"Build: Android release apk":
"Test: Android e2e":
<<: *android_defaults
steps:
- *addWorkspace
- run:
name: "Install node v14.18.1 and yarn 1.22.17"
command: |
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 yarn@1.22.17
yarn -v
- restore_cache: *cache_restore_yarn
- run:
name: Install dependencies
command: yarn --pure-lockfile --non-interactive --cache-folder ~/.cache/yarn
- save_cache: *cache_save_yarn
- run:
name: Bundle JS
command: yarn bundle:android --dev false
Expand All @@ -223,77 +215,31 @@ jobs:
name: Build APK with Next storage
working_directory: example/android
command: ./gradlew assembleNext --max-workers 2
- persist_to_workspace:
root: ~/async_storage
paths:
- example/android/app/build/outputs/apk/*

"Test: Android e2e":
<<: *macos_defaults_android
steps:
- *addWorkspace
- run:
name: Configure env variables
name: Configure Environment Variables
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
echo 'export PATH="$PATH:~/async_storage/node_modules/.bin"' >> $BASH_ENV
source $BASH_ENV
- restore-cache: *cache_restore_brew_android
- run:
name: Install Android SDK tools
command: |
brew update --preinstall
brew bundle --file=.circleci/Brewfile.android --no-lock
- save-cache: *cache_save_brew_android
- run:
name: Install Android emulator
shell: /bin/bash -e
name: Install Android system image
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
sdkmanager "system-images;android-30;default;x86_64"
- run:
name: ADB start/stop
name: "Create Android emulator"
command: |
adb start-server
adb devices
adb kill-server
ls -la ~/.android
avdmanager create avd -n E2E_API_30 -d pixel_4 --package "system-images;android-30;default;x86_64"
- run:
name: Create emulator
name: Launch emulator
command: |
avdmanager create avd --force \
-n "Emu_E2E" \
-k "system-images;android-28;default;x86_64" \
-g "default" \
-d "pixel"
- run:
name: Start emulator in background
emulator -avd E2E_API_30 -delay-adb -verbose -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim
background: true
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:*'
- 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 Expand Up @@ -333,14 +279,11 @@ workflows:
requires:
- "Test: lint"
- "Test: TypeScript"
- "Build: Android release apk":
- "Test: Android e2e":
requires:
- "Test: lint"
- "Test: TypeScript"
- "Test: Android unit"
- "Test: Android e2e":
requires:
- "Build: Android release apk"
- "Release":
requires:
- "Test: iOS e2e"
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