Skip to content

chore: Script files cleanup #497

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 3 commits into from
Nov 27, 2020
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
10 changes: 6 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ jobs:
working_directory: example/ios
command: pod install
- save-cache: *cache_save_pods
- run:
name: Boot simulator
background: true
command: ./scripts/ios_e2e.sh 'run_simulator'
- run:
name: Build iOS app
command: yarn build:e2e:ios
Expand Down Expand Up @@ -206,9 +210,7 @@ jobs:
command: yarn bundle:android --dev false
- run:
name: Build APK
working_directory: example/android
command: ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release --max-workers 2

command: yarn build:e2e:android
- persist_to_workspace:
root: ~/async_storage
paths:
Expand Down Expand Up @@ -275,7 +277,7 @@ jobs:
-logcat '*:W' | grep -i "ReactNative"
- run:
name: Wait for emulator to boot
command: yarn build:e2e:android
command: ./scripts/android_e2e.sh 'wait_for_emulator'
- run:
name: Wake device
command: |
Expand Down
14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@
"start:web": "expo start:web",
"start:macos": "react-native start --use-react-native-macos",
"start:windows": "react-native start --use-react-native-windows",
"build:e2e:android": "detox build -c android.emu.release",
"build:e2e:ios": "detox build -c ios.sim.release",
"build:e2e:macos": "scripts/run_macos_e2e.sh 'build'",
"bundle:android": "react-native bundle --entry-file index.js --platform android --bundle-output example/index.android.jsbundle",
"bundle:ios": "react-native bundle --entry-file index.js --platform ios --bundle-output example/index.ios.jsbundle",
"build:e2e:android": "scripts/android_e2e.sh 'build'",
"build:e2e:ios": "scripts/ios_e2e.sh 'build'",
"build:e2e:macos": "scripts/macos_e2e.sh 'build'",
"bundle:android": "scripts/android_e2e.sh 'bundle'",
"bundle:ios": "scripts/ios_e2e.sh 'bundle'",
"test": "yarn test:lint && yarn test:flow",
"test:flow": "flow check",
"test:lint": "eslint src/**/*.js example/**/*.js jest/*.js",
"test:e2e:android": "detox test -c android.emu.release --maxConcurrency 1",
"test:e2e:ios": "detox test -c ios.sim.release --maxConcurrency 1",
"test:e2e:macos": "scripts/run_macos_e2e.sh 'test'"
"test:e2e:macos": "scripts/macos_e2e.sh 'test'"
},
"peerDependencies": {
"react": "^16.8",
Expand Down Expand Up @@ -105,7 +105,6 @@
"configurations": {
"ios.sim.release": {
"binaryPath": "example/ios/build/Build/Products/Release-iphonesimulator/ReactTestApp.app",
"build": ".circleci/scripts/run_ios_e2e.sh \"iPhone 11\"",
"type": "ios.simulator",
"device": {
"type": "iPhone 11"
Expand All @@ -114,7 +113,6 @@
"android.emu.release": {
"binaryPath": "example/android/app/build/outputs/apk/release/app-release.apk",
"testBinaryPath": "example/android/app/build/outputs/apk/androidTest/release/app-release-androidTest.apk",
"build": ".circleci/scripts/run_android_e2e.sh",
"type": "android.emulator",
"device": {
"avdName": "Emu_E2E"
Expand Down
38 changes: 24 additions & 14 deletions .circleci/scripts/run_android_e2e.sh → scripts/android_e2e.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#!/bin/bash

# On CI, waits for emu to be booted
# Locally, builds apk

ROOT_DIR=$PWD

INTERVAL=5 # 5 secs between each check
MAX_RETRIES=60 # wait max 5 minutes for emu to boot

build_apk() {
echo
echo "[Detox e2e] Building APK"
yarn bundle:android --dev false
cd example/android
./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release
cd ${ROOT_DIR}
(cd example/android; ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release --max-workers 2)
}

bundle_js() {
extraArgs="$@"
echo
echo "[Detox e2e] Bundling JS"
react-native bundle --entry-file index.js --platform android --bundle-output example/index.android.jsbundle $extraArgs
}

wait_for_emulator_to_boot() {
Expand All @@ -41,8 +40,19 @@ wait_for_emulator_to_boot() {
echo "[Detox e2e] Emulator booted."
}

if [[ -n $CIRCLECI ]]; then
wait_for_emulator_to_boot # Run it on CI
else
build_apk # Run locally
fi

case $1 in
wait_for_emulator)
wait_for_emulator_to_boot
;;
build)
build_apk
;;
bundle)
shift; bundle_js $@
;;
*)
echo -n "Unknown argument: $1"
;;
esac

57 changes: 26 additions & 31 deletions .circleci/scripts/run_ios_e2e.sh → scripts/ios_e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ RESOURCE_DIR="$PWD/example/ios/build/Build/Products/Release-iphonesimulator/Reac
ENTRY_FILE="example/index.js"
BUNDLE_FILE="$RESOURCE_DIR/main.jsbundle"
EXTRA_PACKAGER_ARGS="--entry-file=$ENTRY_FILE"
SIMULATOR_NAME="iPhone 11"

build_project() {
echo "[Detox e2e] Building iOS project"
Expand All @@ -18,19 +19,6 @@ build_project() {
}

run_simulator() {
if [[ -n $1 ]]; then
deviceName=$1
else
echo "[Detox e2e] Device name not passed!" >&2;
exit;
fi


if [[ $2 = "headless" ]]; then
runHeadless=1
else
runHeadless=0
fi

# Find simulator
devDir=`xcode-select -p`
Expand All @@ -39,40 +27,47 @@ run_simulator() {
# parse output
availableDevices=$(
eval "xcrun simctl list devices" |\
eval "sed '/"$deviceName"/!d'" |\
eval "sed '/"$SIMULATOR_NAME"/!d'" |\
eval "sed '/unavailable/d'" |\
eval "sed 's/(Shutdown)//; s/(Shutting Down)//; s/(Booted)//; s/ (/*/; s/)//'"
)

IFS='*' read -a deviceInfo <<< "$availableDevices"

if [[ $deviceInfo == "" ]]; then
echo "[Detox e2e] Could not find device: $deviceName" >&2
echo "[Detox e2e] Could not find device: $SIMULATOR_NAME" >&2
exit;
fi


deviceUUID=${deviceInfo[1]}

echo "[Detox e2e] Booting up $deviceName (id: $deviceUUID)"
echo "[Detox e2e] Booting up $SIMULATOR_NAME (id: $deviceUUID)"

# Booting emulator in headless mode
eval "open $devDir --args -CurrentDeviceUDID $deviceUUID"

# Decide if should run headless or not
if [ "$runHeadless" -eq 0 ]; then
Copy link
Member Author

Choose a reason for hiding this comment

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

we never used this one, so removed

eval "xcrun instruments -w $deviceUUID" >/dev/null 2>&1
else
echo "[Detox e2e] Running simulator in headless mode."
fi
eval "xcrun instruments -w $deviceUUID" >/dev/null 2>&1
exit 0
}

build_project

sleep 2

run_simulator "$1" "$2"
bundle_js() {
extraArgs="$@"
echo
echo "[Detox e2e] Bundling JS"
react-native bundle --entry-file index.js --platform ios --bundle-output example/index.ios.jsbundle $extraArgs
}

sleep 10

exit 0
case $1 in
build)
build_project
;;
run_simulator)
run_simulator
;;
bundle)
shift; bundle_js $@
;;
*)
echo -n "Unknown argument: $1"
;;
esac
File renamed without changes.