mirror of https://github.com/iSoron/uhabits.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
3.1 KiB
91 lines
3.1 KiB
#!/bin/bash
|
|
PACKAGE_NAME=org.isoron.uhabits
|
|
OUTPUT_DIR=app/build/outputs
|
|
|
|
AVD_NAME=$1
|
|
AVD_SERIAL=$2
|
|
|
|
ADB="${ANDROID_HOME}/platform-tools/adb -s emulator-${AVD_SERIAL}"
|
|
EMULATOR="${ANDROID_HOME}/tools/emulator"
|
|
GRADLE="./gradlew --no-daemon --stacktrace"
|
|
|
|
info() {
|
|
local COLOR='\033[1;32m'
|
|
local NC='\033[0m'
|
|
#echo -e " $COLOR*$NC $1"
|
|
echo "###teamcity[progressMessage '$1']"
|
|
}
|
|
|
|
fail() {
|
|
$ADB shell reboot -p
|
|
exit 1
|
|
}
|
|
|
|
#--------------------------------------------------------------------------------
|
|
info "Starting emulator"
|
|
$EMULATOR -avd ${AVD_NAME} -port ${AVD_SERIAL} -no-audio -no-window &
|
|
$ADB wait-for-device || fail
|
|
sleep 10
|
|
|
|
#--------------------------------------------------------------------------------
|
|
info "Running adb as root"
|
|
$ADB root
|
|
|
|
#--------------------------------------------------------------------------------
|
|
info "Cleaning output directory"
|
|
rm -rf ${OUTPUT_DIR}
|
|
mkdir -p ${OUTPUT_DIR}
|
|
|
|
#--------------------------------------------------------------------------------
|
|
info "Building instrumentation APKs"
|
|
$GRADLE --no-daemon assembleDebug assembleAndroidTest || fail
|
|
|
|
#--------------------------------------------------------------------------------
|
|
info "Installing APK"
|
|
$ADB install -r ${OUTPUT_DIR}/apk/app-debug.apk || fail
|
|
$ADB install -r ${OUTPUT_DIR}/apk/app-debug-androidTest.apk || fail
|
|
|
|
#--------------------------------------------------------------------------------
|
|
info "Granting permissions"
|
|
$ADB shell pm grant org.isoron.uhabits android.permission.SET_ANIMATION_SCALE || fail
|
|
|
|
#--------------------------------------------------------------------------------
|
|
info "Running instrumentation tests"
|
|
$ADB shell am instrument \
|
|
-e coverage true -e size medium \
|
|
-w ${PACKAGE_NAME}.test/android.support.test.runner.AndroidJUnitRunner \
|
|
| tee ${OUTPUT_DIR}/runner.txt || fail
|
|
grep -q "Error" ${OUTPUT_DIR}/runner.txt && failed=1
|
|
|
|
#--------------------------------------------------------------------------------
|
|
info "Fetching failed generated files"
|
|
mkdir -p ${OUTPUT_DIR}/failed
|
|
$ADB pull /mnt/sdcard/test-screenshots/ ${OUTPUT_DIR}/failed
|
|
$ADB pull /storage/sdcard/test-screenshots/ ${OUTPUT_DIR}/failed
|
|
$ADB pull /sdcard/Android/data/${PACKAGE_NAME}/files/test-screenshots/ ${OUTPUT_DIR}/failed
|
|
|
|
$ADB shell rm -r /mnt/sdcard/test-screenshots/
|
|
$ADB shell rm -r /storage/sdcard/test-screenshots/
|
|
$ADB shell rm -r /sdcard/Android/data/${PACKAGE_NAME}/files/test-screenshots/
|
|
|
|
#--------------------------------------------------------------------------------
|
|
info "Fetching logcat"
|
|
$ADB logcat -d > ${OUTPUT_DIR}/logcat.txt
|
|
|
|
#--------------------------------------------------------------------------------
|
|
info "Building coverage report"
|
|
mkdir -p ${OUTPUT_DIR}/code-coverage/connected/
|
|
$ADB pull /data/user/0/${PACKAGE_NAME}/files/coverage.ec \
|
|
${OUTPUT_DIR}/code-coverage/connected/
|
|
$GRADLE --no-daemon coverageReport || fail
|
|
|
|
#--------------------------------------------------------------------------------
|
|
info "Uninstalling test APK"
|
|
$ADB uninstall ${PACKAGE_NAME}.test || fail
|
|
|
|
#--------------------------------------------------------------------------------
|
|
info "Stopping emulator"
|
|
$ADB shell reboot -p
|
|
|
|
exit $failed
|