Consolidate CI/local test scripts

Summary:
Update `scripts/run-android-emulator.sh` to use same settings as Circle CI when creating and launching an AVD. This helps provide a known good configuration, useful for running Android tests locally.

Run `scripts/run-android-emulator.sh` and confirm AVD is created && launched
Run `scripts/run-android-emulator.sh` again and see message about AVD already running
Run `test_android` on CI and observe AVD is launched.

Run `runXcodeTests.sh` and confirm unit tests run.
Run CI and confirm iOS unit tests run.

[GENERAL][MINOR][`scripts`] - Consolidate CI/local test scripts
Closes https://github.com/facebook/react-native/pull/19228

Differential Revision: D8019888

Pulled By: hramos

fbshipit-source-id: 28b12c2e781ee80bcc90c22e691a5acb16232369
This commit is contained in:
Héctor Ramos 2018-05-15 17:25:16 -07:00 committed by Facebook Github Bot
parent 1ad8351d9b
commit 2472d915ab
7 changed files with 85 additions and 46 deletions

View File

@ -22,12 +22,12 @@ aliases:
- &restore-cache-android-packages
keys:
- v1-android-sdkmanager-packages-{{ arch }}-api-26-alpha-{{ checksum "scripts/circle-ci-android-setup.sh" }}
- v1-android-sdkmanager-packages-{{ arch }}-api-26-alpha-{{ checksum "scripts/android-setup.sh" }}
- v1-android-sdkmanager-packages-{{ arch }}-api-26-alpha-
- &save-cache-android-packages
paths:
- /opt/android/sdk
key: v1-android-sdkmanager-packages-{{ arch }}-api-26-alpha-{{ checksum "scripts/circle-ci-android-setup.sh" }}
key: v1-android-sdkmanager-packages-{{ arch }}-api-26-alpha-{{ checksum "scripts/android-setup.sh" }}
- &restore-cache-gradle
keys:
@ -56,12 +56,12 @@ aliases:
- &restore-cache-ndk
keys:
- v3-android-ndk-{{ arch }}-r10e-{{ checksum "scripts/circle-ci-android-setup.sh" }}
- v3-android-ndk-{{ arch }}-r10e-{{ checksum "scripts/android-setup.sh" }}
- v3-android-ndk-{{ arch }}-r10e-
- &save-cache-ndk
paths:
- /opt/ndk
key: v3-android-ndk-{{ arch }}-r10e-{{ checksum "scripts/circle-ci-android-setup.sh" }}
key: v3-android-ndk-{{ arch }}-r10e-{{ checksum "scripts/android-setup.sh" }}
- &restore-cache-buck
keys:
@ -117,7 +117,7 @@ aliases:
# Dependency Management
- &install-ndk
name: Install Android NDK
command: source scripts/circle-ci-android-setup.sh && getAndroidNDK
command: source scripts/android-setup.sh && getAndroidNDK
- &yarn
|
@ -174,7 +174,7 @@ aliases:
- &install-android-packages
name: Install Android SDK Packages
command: source scripts/circle-ci-android-setup.sh && getAndroidSDK
command: source scripts/android-setup.sh && getAndroidPackages
- &install-android-build-dependencies
name: Install Android Build Dependencies
@ -223,16 +223,16 @@ aliases:
- &create-avd
name: Create Android Virtual Device
command: source scripts/circle-ci-android-setup.sh && createAVD
command: source scripts/android-setup.sh && createAVD
- &launch-avd
name: Launch Android Virtual Device in Background
command: source scripts/circle-ci-android-setup.sh && launchAVD
command: source scripts/android-setup.sh && launchAVD
background: true
- &wait-for-avd
name: Wait for Android Virtual Device
command: source scripts/circle-ci-android-setup.sh && waitForAVD
command: source scripts/android-setup.sh && waitForAVD
- &build-js-bundle
name: Build JavaScript Bundle
@ -253,7 +253,7 @@ aliases:
if [[ ! -e ReactAndroid/src/androidTest/assets/AndroidTestBundle.js ]]; then
echo "JavaScript bundle missing, cannot run instrumentation tests. Verify build-js-bundle step completed successfully."; exit 1;
fi
source scripts/circle-ci-android-setup.sh && NO_BUCKD=1 retry3 timeout 300 buck install ReactAndroid/src/androidTest/buck-runner:instrumentation-tests --config build.threads=$BUILD_THREADS
source scripts/android-setup.sh && NO_BUCKD=1 retry3 timeout 300 buck install ReactAndroid/src/androidTest/buck-runner:instrumentation-tests --config build.threads=$BUILD_THREADS
- &collect-android-test-results
name: Collect Test Results

View File

@ -28,7 +28,7 @@ watchman shutdown-server
node local-cli/cli.js bundle --platform android --dev true --entry-file ReactAndroid/src/androidTest/js/TestBundle.js --bundle-output ReactAndroid/src/androidTest/assets/AndroidTestBundle.js
# build test APK
source ./scripts/circle-ci-android-setup.sh && NO_BUCKD=1 retry3 buck install ReactAndroid/src/androidTest/buck-runner:instrumentation-tests --config build.threads=1
source ./scripts/android-setup.sh && NO_BUCKD=1 retry3 buck install ReactAndroid/src/androidTest/buck-runner:instrumentation-tests --config build.threads=1
# run installed apk with tests
node ./ContainerShip/scripts/run-android-ci-instrumentation-tests.js $*

View File

@ -1,18 +1,20 @@
#!/bin/sh
# This script should be run from the react-native root
# Run from react-native root
THIS_DIR=$(dirname "$0")
source "scripts/.tests.env"
set -e
if [ -z "$1" ]
if [ -n "$1" ]
then
echo "You must supply an OS version as the first arg, e.g. 8.1"
exit 255
echo "Overriding..."
IOS_TARGET_OS="${1}"
SDK="iphonesimulator${1}"
DESTINATION="platform=iOS Simulator,OS=${IOS_TARGET_OS},name=${IOS_DEVICE}"
fi
xctool \
-project RNTester/RNTester.xcodeproj \
-scheme RNTester \
-sdk iphonesimulator${1} \
-destination "platform=iOS Simulator,OS=${1},name=iPhone 5" \
xcodebuild \
-project "RNTester/RNTester.xcodeproj" \
-scheme $SCHEME \
-sdk $SDK \
-destination "$DESTINATION" \
build test

32
scripts/.tests.env Normal file
View File

@ -0,0 +1,32 @@
# These should match the recommended versions listed in
# https://facebook.github.io/react-native/docs/getting-started.html
## ANDROID ##
# Android SDK Build Tools revision
export ANDROID_SDK_BUILD_TOOLS_REVISION=23.0.1
# Android API Level we build with
export ANDROID_SDK_BUILD_API_LEVEL="23"
# Minimum Android API Level we target
export ANDROID_SDK_TARGET_API_LEVEL="19"
# Android Virtual Device name
export AVD_NAME="testAVD"
# ABI to use in Android Virtual Device
export AVD_ABI=x86
## IOS ##
export IOS_TARGET_OS="11.3"
export IOS_DEVICE="iPhone 5s"
export SCHEME="RNTester"
export SDK="iphonesimulator${IOS_TARGET_OS}"
export DESTINATION="platform=iOS Simulator,OS=${IOS_TARGET_OS},name=${IOS_DEVICE}"
## CI OVERRIDES ##
# Values to override when running in CI
# $CI is set by Circle CI
if [ $CI ]; then
# Use ARM on Circle CI
export AVD_ABI=armeabi-v7a
fi

View File

@ -1,25 +1,16 @@
# inspired by https://github.com/Originate/guide/blob/master/android/guide/Continuous%20Integration.md
# SDK Built Tools revision, per http://facebook.github.io/react-native/docs/getting-started.html
ANDROID_SDK_BUILD_TOOLS_REVISION=23.0.1
# API Level we build with
ANDROID_SDK_BUILD_API_LEVEL="23"
# Minimum API Level we target, used for emulator image
ANDROID_SDK_TARGET_API_LEVEL="19"
# Emulator name
AVD_NAME="testAVD"
source "scripts/.tests.env"
function getAndroidSDK {
export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$PATH"
function getAndroidPackages {
export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$ANDROID_HOME/tools.bin:$PATH"
DEPS="$ANDROID_HOME/installed-dependencies"
if [ ! -e $DEPS ]; then
echo "Installing Android API level $ANDROID_SDK_TARGET_API_LEVEL, Google APIs, ARM EABI v7a system image..."
sdkmanager "system-images;android-$ANDROID_SDK_TARGET_API_LEVEL;google_apis;armeabi-v7a"
# x86 image requires hardware acceleration, which is not supported when running within the CircleCI Docker image
# echo "Installing Android API level $ANDROID_SDK_TARGET_API_LEVEL, Google APIs, Intel x86 Atom system image..."
# sdkmanager "system-images;android-$ANDROID_SDK_TARGET_API_LEVEL;google_apis;x86"
# Package names can be obtained using `sdkmanager --list`
if [ ! -e $DEPS ] || [ ! $CI ]; then
echo "Installing Android API level $ANDROID_SDK_TARGET_API_LEVEL, Google APIs, $AVD_ABI system image..."
sdkmanager "system-images;android-$ANDROID_SDK_TARGET_API_LEVEL;google_apis;$AVD_ABI"
echo "Installing build SDK for Android API level $ANDROID_SDK_BUILD_API_LEVEL..."
sdkmanager "platforms;android-$ANDROID_SDK_BUILD_API_LEVEL"
echo "Installing target SDK for Android API level $ANDROID_SDK_TARGET_API_LEVEL..."
@ -30,7 +21,7 @@ function getAndroidSDK {
sdkmanager "add-ons;addon-google_apis-google-$ANDROID_SDK_BUILD_API_LEVEL"
echo "Installing Android Support Repository"
sdkmanager "extras;android;m2repository"
touch $DEPS
$CI && touch $DEPS
fi
}
@ -50,13 +41,21 @@ function getAndroidNDK {
}
function createAVD {
echo no | avdmanager create avd --name $AVD_NAME --force --package "system-images;android-$ANDROID_SDK_TARGET_API_LEVEL;google_apis;armeabi-v7a" --tag google_apis --abi armeabi-v7a
AVD_PACKAGES="system-images;android-$ANDROID_SDK_TARGET_API_LEVEL;google_apis;$AVD_ABI"
echo "Creating AVD with packages $AVD_PACKAGES"
echo no | avdmanager create avd --name $AVD_NAME --force --package $AVD_PACKAGES --tag google_apis --abi $AVD_ABI
}
function launchAVD {
export PATH="$ANDROID_HOME/emulator:$PATH"
# The AVD name here should match the one created in createAVD
# emulator64-arm -avd $AVD_NAME -no-audio -no-window -no-boot-anim -gpu off
emulator -avd $AVD_NAME -no-audio -no-window
if [ $CI ]
then
emulator -avd $AVD_NAME -no-audio -no-window
else
emulator -avd $AVD_NAME
fi
}
function waitForAVD {

View File

@ -5,7 +5,8 @@
# The only reason to use this config is that it represents a known-good
# virtual device configuration.
# This is useful for running integration tests on a local machine.
# TODO: make continuous integration use the precise same setup
THIS_DIR=$(dirname "$0")
STATE=`adb get-state`
@ -14,6 +15,11 @@ if [ -n "$STATE" ]; then
exit 1
fi
echo "Creating virtual device..."
echo no | android create avd -n testAVD -f -t android-23 --abi default/x86
emulator -avd testAVD
echo "Installing packages"
source "${THIS_DIR}/android-setup.sh" && getAndroidPackages
echo "Creating Android virtual device..."
source "${THIS_DIR}/android-setup.sh" && createAVD
echo "Launching Android virtual device..."
source "${THIS_DIR}/android-setup.sh" && launchAVD

0
scripts/validate-android-device-env.sh Normal file → Executable file
View File