Skip to content

Commit 2472d91

Browse files
hramosfacebook-github-bot
authored andcommitted
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 facebook#19228 Differential Revision: D8019888 Pulled By: hramos fbshipit-source-id: 28b12c2e781ee80bcc90c22e691a5acb16232369
1 parent 1ad8351 commit 2472d91

File tree

7 files changed

+85
-46
lines changed

7 files changed

+85
-46
lines changed

.circleci/config.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ aliases:
2222

2323
- &restore-cache-android-packages
2424
keys:
25-
- v1-android-sdkmanager-packages-{{ arch }}-api-26-alpha-{{ checksum "scripts/circle-ci-android-setup.sh" }}
25+
- v1-android-sdkmanager-packages-{{ arch }}-api-26-alpha-{{ checksum "scripts/android-setup.sh" }}
2626
- v1-android-sdkmanager-packages-{{ arch }}-api-26-alpha-
2727
- &save-cache-android-packages
2828
paths:
2929
- /opt/android/sdk
30-
key: v1-android-sdkmanager-packages-{{ arch }}-api-26-alpha-{{ checksum "scripts/circle-ci-android-setup.sh" }}
30+
key: v1-android-sdkmanager-packages-{{ arch }}-api-26-alpha-{{ checksum "scripts/android-setup.sh" }}
3131

3232
- &restore-cache-gradle
3333
keys:
@@ -56,12 +56,12 @@ aliases:
5656

5757
- &restore-cache-ndk
5858
keys:
59-
- v3-android-ndk-{{ arch }}-r10e-{{ checksum "scripts/circle-ci-android-setup.sh" }}
59+
- v3-android-ndk-{{ arch }}-r10e-{{ checksum "scripts/android-setup.sh" }}
6060
- v3-android-ndk-{{ arch }}-r10e-
6161
- &save-cache-ndk
6262
paths:
6363
- /opt/ndk
64-
key: v3-android-ndk-{{ arch }}-r10e-{{ checksum "scripts/circle-ci-android-setup.sh" }}
64+
key: v3-android-ndk-{{ arch }}-r10e-{{ checksum "scripts/android-setup.sh" }}
6565

6666
- &restore-cache-buck
6767
keys:
@@ -117,7 +117,7 @@ aliases:
117117
# Dependency Management
118118
- &install-ndk
119119
name: Install Android NDK
120-
command: source scripts/circle-ci-android-setup.sh && getAndroidNDK
120+
command: source scripts/android-setup.sh && getAndroidNDK
121121

122122
- &yarn
123123
|
@@ -174,7 +174,7 @@ aliases:
174174
175175
- &install-android-packages
176176
name: Install Android SDK Packages
177-
command: source scripts/circle-ci-android-setup.sh && getAndroidSDK
177+
command: source scripts/android-setup.sh && getAndroidPackages
178178

179179
- &install-android-build-dependencies
180180
name: Install Android Build Dependencies
@@ -223,16 +223,16 @@ aliases:
223223
224224
- &create-avd
225225
name: Create Android Virtual Device
226-
command: source scripts/circle-ci-android-setup.sh && createAVD
226+
command: source scripts/android-setup.sh && createAVD
227227

228228
- &launch-avd
229229
name: Launch Android Virtual Device in Background
230-
command: source scripts/circle-ci-android-setup.sh && launchAVD
230+
command: source scripts/android-setup.sh && launchAVD
231231
background: true
232232

233233
- &wait-for-avd
234234
name: Wait for Android Virtual Device
235-
command: source scripts/circle-ci-android-setup.sh && waitForAVD
235+
command: source scripts/android-setup.sh && waitForAVD
236236

237237
- &build-js-bundle
238238
name: Build JavaScript Bundle
@@ -253,7 +253,7 @@ aliases:
253253
if [[ ! -e ReactAndroid/src/androidTest/assets/AndroidTestBundle.js ]]; then
254254
echo "JavaScript bundle missing, cannot run instrumentation tests. Verify build-js-bundle step completed successfully."; exit 1;
255255
fi
256-
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
256+
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
257257
258258
- &collect-android-test-results
259259
name: Collect Test Results

ContainerShip/scripts/run-android-docker-instrumentation-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ watchman shutdown-server
2828
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
2929

3030
# build test APK
31-
source ./scripts/circle-ci-android-setup.sh && NO_BUCKD=1 retry3 buck install ReactAndroid/src/androidTest/buck-runner:instrumentation-tests --config build.threads=1
31+
source ./scripts/android-setup.sh && NO_BUCKD=1 retry3 buck install ReactAndroid/src/androidTest/buck-runner:instrumentation-tests --config build.threads=1
3232

3333
# run installed apk with tests
3434
node ./ContainerShip/scripts/run-android-ci-instrumentation-tests.js $*

runXcodeTests.sh

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
#!/bin/sh
2+
# This script should be run from the react-native root
23

3-
# Run from react-native root
4+
THIS_DIR=$(dirname "$0")
5+
source "scripts/.tests.env"
46

5-
set -e
6-
7-
if [ -z "$1" ]
7+
if [ -n "$1" ]
88
then
9-
echo "You must supply an OS version as the first arg, e.g. 8.1"
10-
exit 255
9+
echo "Overriding..."
10+
IOS_TARGET_OS="${1}"
11+
SDK="iphonesimulator${1}"
12+
DESTINATION="platform=iOS Simulator,OS=${IOS_TARGET_OS},name=${IOS_DEVICE}"
1113
fi
1214

13-
xctool \
14-
-project RNTester/RNTester.xcodeproj \
15-
-scheme RNTester \
16-
-sdk iphonesimulator${1} \
17-
-destination "platform=iOS Simulator,OS=${1},name=iPhone 5" \
15+
xcodebuild \
16+
-project "RNTester/RNTester.xcodeproj" \
17+
-scheme $SCHEME \
18+
-sdk $SDK \
19+
-destination "$DESTINATION" \
1820
build test

scripts/.tests.env

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# These should match the recommended versions listed in
2+
# https://facebook.github.io/react-native/docs/getting-started.html
3+
4+
5+
## ANDROID ##
6+
# Android SDK Build Tools revision
7+
export ANDROID_SDK_BUILD_TOOLS_REVISION=23.0.1
8+
# Android API Level we build with
9+
export ANDROID_SDK_BUILD_API_LEVEL="23"
10+
# Minimum Android API Level we target
11+
export ANDROID_SDK_TARGET_API_LEVEL="19"
12+
# Android Virtual Device name
13+
export AVD_NAME="testAVD"
14+
# ABI to use in Android Virtual Device
15+
export AVD_ABI=x86
16+
17+
## IOS ##
18+
export IOS_TARGET_OS="11.3"
19+
export IOS_DEVICE="iPhone 5s"
20+
21+
export SCHEME="RNTester"
22+
export SDK="iphonesimulator${IOS_TARGET_OS}"
23+
export DESTINATION="platform=iOS Simulator,OS=${IOS_TARGET_OS},name=${IOS_DEVICE}"
24+
25+
## CI OVERRIDES ##
26+
# Values to override when running in CI
27+
# $CI is set by Circle CI
28+
if [ $CI ]; then
29+
# Use ARM on Circle CI
30+
export AVD_ABI=armeabi-v7a
31+
fi
32+

scripts/circle-ci-android-setup.sh renamed to scripts/android-setup.sh

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
11
# inspired by https://github.com/Originate/guide/blob/master/android/guide/Continuous%20Integration.md
22

3-
# SDK Built Tools revision, per http://facebook.github.io/react-native/docs/getting-started.html
4-
ANDROID_SDK_BUILD_TOOLS_REVISION=23.0.1
5-
# API Level we build with
6-
ANDROID_SDK_BUILD_API_LEVEL="23"
7-
# Minimum API Level we target, used for emulator image
8-
ANDROID_SDK_TARGET_API_LEVEL="19"
9-
# Emulator name
10-
AVD_NAME="testAVD"
3+
source "scripts/.tests.env"
114

12-
function getAndroidSDK {
13-
export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$PATH"
5+
function getAndroidPackages {
6+
export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$ANDROID_HOME/tools.bin:$PATH"
147

158
DEPS="$ANDROID_HOME/installed-dependencies"
169

17-
if [ ! -e $DEPS ]; then
18-
echo "Installing Android API level $ANDROID_SDK_TARGET_API_LEVEL, Google APIs, ARM EABI v7a system image..."
19-
sdkmanager "system-images;android-$ANDROID_SDK_TARGET_API_LEVEL;google_apis;armeabi-v7a"
20-
# x86 image requires hardware acceleration, which is not supported when running within the CircleCI Docker image
21-
# echo "Installing Android API level $ANDROID_SDK_TARGET_API_LEVEL, Google APIs, Intel x86 Atom system image..."
22-
# sdkmanager "system-images;android-$ANDROID_SDK_TARGET_API_LEVEL;google_apis;x86"
10+
# Package names can be obtained using `sdkmanager --list`
11+
if [ ! -e $DEPS ] || [ ! $CI ]; then
12+
echo "Installing Android API level $ANDROID_SDK_TARGET_API_LEVEL, Google APIs, $AVD_ABI system image..."
13+
sdkmanager "system-images;android-$ANDROID_SDK_TARGET_API_LEVEL;google_apis;$AVD_ABI"
2314
echo "Installing build SDK for Android API level $ANDROID_SDK_BUILD_API_LEVEL..."
2415
sdkmanager "platforms;android-$ANDROID_SDK_BUILD_API_LEVEL"
2516
echo "Installing target SDK for Android API level $ANDROID_SDK_TARGET_API_LEVEL..."
@@ -30,7 +21,7 @@ function getAndroidSDK {
3021
sdkmanager "add-ons;addon-google_apis-google-$ANDROID_SDK_BUILD_API_LEVEL"
3122
echo "Installing Android Support Repository"
3223
sdkmanager "extras;android;m2repository"
33-
touch $DEPS
24+
$CI && touch $DEPS
3425
fi
3526
}
3627

@@ -50,13 +41,21 @@ function getAndroidNDK {
5041
}
5142

5243
function createAVD {
53-
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
44+
AVD_PACKAGES="system-images;android-$ANDROID_SDK_TARGET_API_LEVEL;google_apis;$AVD_ABI"
45+
echo "Creating AVD with packages $AVD_PACKAGES"
46+
echo no | avdmanager create avd --name $AVD_NAME --force --package $AVD_PACKAGES --tag google_apis --abi $AVD_ABI
5447
}
5548

5649
function launchAVD {
50+
export PATH="$ANDROID_HOME/emulator:$PATH"
51+
5752
# The AVD name here should match the one created in createAVD
58-
# emulator64-arm -avd $AVD_NAME -no-audio -no-window -no-boot-anim -gpu off
59-
emulator -avd $AVD_NAME -no-audio -no-window
53+
if [ $CI ]
54+
then
55+
emulator -avd $AVD_NAME -no-audio -no-window
56+
else
57+
emulator -avd $AVD_NAME
58+
fi
6059
}
6160

6261
function waitForAVD {

scripts/run-android-emulator.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
# The only reason to use this config is that it represents a known-good
66
# virtual device configuration.
77
# This is useful for running integration tests on a local machine.
8-
# TODO: make continuous integration use the precise same setup
8+
9+
THIS_DIR=$(dirname "$0")
910

1011
STATE=`adb get-state`
1112

@@ -14,6 +15,11 @@ if [ -n "$STATE" ]; then
1415
exit 1
1516
fi
1617

17-
echo "Creating virtual device..."
18-
echo no | android create avd -n testAVD -f -t android-23 --abi default/x86
19-
emulator -avd testAVD
18+
echo "Installing packages"
19+
source "${THIS_DIR}/android-setup.sh" && getAndroidPackages
20+
21+
echo "Creating Android virtual device..."
22+
source "${THIS_DIR}/android-setup.sh" && createAVD
23+
24+
echo "Launching Android virtual device..."
25+
source "${THIS_DIR}/android-setup.sh" && launchAVD

scripts/validate-android-device-env.sh

100644100755
File mode changed.

0 commit comments

Comments
 (0)