2017-03-24 16:49:07 +01:00
#!/bin/bash
# Bash version should >= 4 to be able to run this script.
2019-06-28 13:56:04 +07:00
IMAGE = " ${ DOCKER_ORG :- budtmo } /docker-android"
2017-03-24 16:49:07 +01:00
if [ -z " $1 " ] ; then
2017-04-19 13:24:42 +02:00
read -p "Task (test|build|push|all) : " TASK
2017-03-24 16:49:07 +01:00
else
TASK = $1
fi
if [ -z " $2 " ] ; then
2021-10-05 10:06:46 +02:00
read -p "Android version (6.0|7.0|7.1.1|8.0|8.1|9.0|10.0|11.0|12.0|all): " ANDROID_VERSION
2017-03-24 16:49:07 +01:00
else
2017-04-19 13:24:42 +02:00
ANDROID_VERSION = $2
2017-03-24 16:49:07 +01:00
fi
if [ -z " $3 " ] ; then
2017-04-19 13:24:42 +02:00
read -p "Release version: " RELEASE
else
2018-07-05 20:04:25 +02:00
RELEASE = $3
2017-04-19 13:24:42 +02:00
fi
declare -A list_of_levels =(
2017-03-28 12:31:14 +02:00
[ 6.0]= 23
2017-04-21 11:23:24 +02:00
[ 7.0]= 24
2017-04-21 15:06:53 +02:00
[ 7.1.1]= 25
2018-07-05 14:29:54 +02:00
[ 8.0]= 26
[ 8.1]= 27
2018-10-23 16:17:12 +02:00
[ 9.0]= 28
2019-09-17 14:51:02 +02:00
[ 10.0]= 29
2020-07-13 13:03:58 +02:00
[ 11.0]= 30
2021-08-03 16:15:59 -04:00
[ 12.0]= 31
2017-04-19 13:24:42 +02:00
)
2017-03-24 16:49:07 +01:00
2018-07-24 15:59:11 +02:00
# The version of the Chrome browser installed on the Android emulator needs to be known beforehand
# in order to chose the proper version of chromedriver (see http://chromedriver.chromium.org/downloads)
declare -A chromedriver_versions =(
[ 6.0]= "2.18"
[ 7.0]= "2.23"
[ 7.1.1]= "2.28"
[ 8.0]= "2.31"
[ 8.1]= "2.33"
2018-10-23 16:17:12 +02:00
[ 9.0]= "2.40"
2019-09-17 14:51:02 +02:00
[ 10.0]= "74.0.3729.6"
2020-07-13 13:03:58 +02:00
[ 11.0]= "83.0.4103.39"
2021-08-03 16:15:59 -04:00
[ 12.0]= "93.0.4577.15"
2018-07-24 15:59:11 +02:00
)
2017-04-19 13:24:42 +02:00
function get_android_versions() {
versions =()
if [ " $ANDROID_VERSION " == "all" ] ; then
for key in " ${ !list_of_levels[@] } " ; do
versions +=( $key )
done
else
for key in " ${ !list_of_levels[@] } " ; do
if [[ $key == *" $ANDROID_VERSION " * ]] ; then
versions +=( $key )
fi
done
fi
2017-03-24 16:49:07 +01:00
# If version cannot be found in the list
2017-04-19 13:24:42 +02:00
if [ -z " $versions " ] ; then
2021-10-05 10:06:46 +02:00
echo "Android version \" $ANDROID_VERSION \" is not found in the list or not supported! Support only version 6.0, 7.0, 7.1.1, 8.0, 8.1, 9.0, 10.0, 11.0, 12.0"
2017-03-24 16:49:07 +01:00
exit 1
fi
2017-04-19 13:24:42 +02:00
echo "Android versions: ${ versions [@] } "
2017-03-24 16:49:07 +01:00
}
2017-04-19 13:24:42 +02:00
get_android_versions
2018-07-05 21:06:00 +02:00
processor = x86
2017-03-24 16:49:07 +01:00
function test() {
2017-06-01 15:51:22 +02:00
# Prepare needed parameter to run tests
test_android_version = 7.1.1
test_api_level = 25
test_processor = x86
2018-07-05 20:04:25 +02:00
test_sys_img = $test_processor
2017-06-01 15:51:22 +02:00
test_img_type = google_apis
2017-06-14 15:06:01 +02:00
test_browser = chrome
2017-06-01 15:51:22 +02:00
test_image = test_img
test_container = test_con
2017-06-02 13:18:00 +02:00
# Run e2e tests
# E2E tests must be run only for linux OS / x86 image to reduce duration of test execution
if [ " $( uname -s) " == 'Linux' ] && [ " $E2E " = true ] ; then
2017-06-01 15:51:22 +02:00
echo "----BUILD TEST IMAGE----"
docker build -t $test_image --build-arg ANDROID_VERSION = $test_android_version \
2017-06-14 15:06:01 +02:00
--build-arg API_LEVEL = $test_api_level --build-arg PROCESSOR = $test_processor --build-arg SYS_IMG = $test_sys_img \
--build-arg IMG_TYPE = $test_img_type --build-arg BROWSER = $test_browser -f docker/Emulator_x86 .
2017-06-01 15:51:22 +02:00
2017-06-02 13:18:00 +02:00
echo "----REMOVE OLD TEST CONTAINER----"
docker kill $test_container && docker rm $test_container
echo "----PREPARE CONTAINER----"
docker run --privileged -d -p 4723:4723 -p 6080:6080 -e APPIUM = True -e DEVICE = "Samsung Galaxy S6" --name $test_container $test_image
docker cp example/sample_apk $test_container :/root/tmp
2017-06-01 15:51:22 +02:00
attempt = 0
while [ ${ attempt } -le 10 ] ; do
attempt = $(( $attempt + 1 ))
output = $( docker ps | grep healthy | grep test_con | wc -l)
if [[ " $output " == 1 ]] ; then
echo "Emulator is ready."
break
else
echo "Waiting 10 seconds for emulator to be ready (attempt: $attempt )"
sleep 10
fi
if [[ $attempt == 10 ]] ; then
echo "Failed!"
exit 1
fi
done
2017-06-02 13:18:00 +02:00
echo "----RUN E2E TESTS----"
2017-06-01 15:51:22 +02:00
nosetests src/tests/e2e -v
echo "----REMOVE TEST CONTAINER----"
docker kill $test_container && docker rm $test_container
fi
2017-06-02 13:18:00 +02:00
# Run unit tests (After e2e test to get coverage result)
echo "----UNIT TESTS----"
( export ANDROID_HOME = /root && export ANDROID_VERSION = $test_android_version && export API_LEVEL = $test_api_level \
&& export PROCESSOR = $test_processor && export SYS_IMG = $test_sys_img && export IMG_TYPE = $test_img_type \
&& nosetests src/tests/unit -v)
2017-03-24 16:49:07 +01:00
}
function build() {
# Remove pyc files
find . -name "*.pyc" -exec rm -f {} \;
2018-07-05 20:04:25 +02:00
# Build docker image
FILE_NAME = docker/Emulator_x86
2017-05-22 13:20:30 +02:00
2018-07-05 20:04:25 +02:00
for v in " ${ versions [@] } " ; do
2021-08-03 18:04:53 -04:00
level = ${ list_of_levels [ $v ] }
2018-07-05 20:04:25 +02:00
# Find image type and default web browser
2021-10-05 10:06:46 +02:00
if [ " $v " == "6.0" ] ; then
2018-07-05 20:04:25 +02:00
# It is because there is no ARM EABI v7a System Image for 6.0
IMG_TYPE = google_apis
BROWSER = browser
2020-06-17 17:14:50 +02:00
elif [ " $v " == "" ] ; then
IMG_TYPE = google_apis
2021-08-03 16:15:59 -04:00
BROWSER = chrome
2018-07-05 20:04:25 +02:00
else
2021-08-03 16:15:59 -04:00
#adb root cannot be run in IMG_TYPE=google_apis_playstore
2018-08-03 15:58:07 +02:00
IMG_TYPE = google_apis
2018-07-05 20:04:25 +02:00
BROWSER = chrome
2021-11-04 13:02:32 -04:00
# Android 9 & Android 11 had build issues that requires 64-bit
# Android 12+ Google dropped 32-bit support
if [ " $v " == "9.0" ] || [ $level -ge 30 ] ; then
2020-06-17 17:14:50 +02:00
processor = x86_64
fi
2018-07-05 20:04:25 +02:00
fi
echo "[BUILD] IMAGE TYPE: $IMG_TYPE "
echo "[BUILD] API Level: $level "
2018-07-05 21:06:00 +02:00
sys_img = $processor
2018-07-05 20:04:25 +02:00
echo "[BUILD] System Image: $sys_img "
2018-07-24 15:59:11 +02:00
chrome_driver = " ${ chromedriver_versions [ $v ] } "
echo "[BUILD] chromedriver version: $chrome_driver "
2020-06-17 17:14:50 +02:00
image_version = " $IMAGE -x86- $v : $RELEASE "
image_latest = " $IMAGE -x86- $v :latest"
2018-07-05 20:04:25 +02:00
echo "[BUILD] Image name: $image_version and $image_latest "
echo "[BUILD] Dockerfile: $FILE_NAME "
2019-05-06 18:33:13 +07:00
docker build -t $image_version --build-arg TOKEN = $TOKEN --build-arg ANDROID_VERSION = $v --build-arg API_LEVEL = $level \
2018-07-05 21:06:00 +02:00
--build-arg PROCESSOR = $processor --build-arg SYS_IMG = $sys_img --build-arg IMG_TYPE = $IMG_TYPE \
2018-10-26 15:00:46 +02:00
--build-arg BROWSER = $BROWSER --build-arg CHROME_DRIVER = $chrome_driver \
--build-arg APP_RELEASE_VERSION = $RELEASE -f $FILE_NAME .
2018-07-05 20:04:25 +02:00
docker tag $image_version $image_latest
2017-04-19 13:24:42 +02:00
done
2017-03-24 16:49:07 +01:00
}
function push() {
2017-04-19 13:24:42 +02:00
# Push docker image(s)
2018-07-05 20:04:25 +02:00
for v in " ${ versions [@] } " ; do
2020-06-17 17:14:50 +02:00
image_version = " $IMAGE -x86- $v : $RELEASE "
image_latest = " $IMAGE -x86- $v :latest"
2018-07-05 20:04:25 +02:00
echo "[PUSH] Image name: $image_version and $image_latest "
docker push $image_version
docker push $image_latest
2017-04-19 13:24:42 +02:00
done
2017-03-24 16:49:07 +01:00
}
case $TASK in
test )
test
;;
build)
build
;;
push)
push
;;
all)
test
build
push
;;
*)
echo "Invalid environment! Valid options: test, build, push, all"
;;
esac