Automatic test, build and push from travis

This commit is contained in:
butomo1989 2017-04-19 13:24:42 +02:00
parent d6a2738620
commit cd155015d1
3 changed files with 101 additions and 49 deletions

View file

@ -5,7 +5,7 @@ python:
install: "pip install -r requirements.txt" install: "pip install -r requirements.txt"
script: bash release.sh test 5.0 x86 script: bash travis.sh
branches: branches:
only: only:

126
release.sh Normal file → Executable file
View file

@ -5,91 +5,129 @@ IMAGE="butomo1989/docker-android"
LATEST_BUILD_TOOL=25.0.2 LATEST_BUILD_TOOL=25.0.2
if [ -z "$1" ]; then if [ -z "$1" ]; then
read -p "Environment (test|build|push|all) : " TASK read -p "Task (test|build|push|all) : " TASK
else else
TASK=$1 TASK=$1
fi fi
if [ -z "$2" ]; then if [ -z "$2" ]; then
read -p "Android version: " GIVEN_VERSION read -p "Android version (5.0.1|5.1.1|6.0|all): " ANDROID_VERSION
else else
GIVEN_VERSION=$2 ANDROID_VERSION=$2
fi fi
if [ -z "$3" ]; then if [ -z "$3" ]; then
read -p "Processor type (x86|arm): " PROCESSOR read -p "Processor type (x86|arm|all): " PROCESSOR
else else
PROCESSOR=$3 PROCESSOR=$3
fi fi
function api_level() { if [ -z "$4" ]; then
declare -A levels=( read -p "Release version: " RELEASE
else
RELEASE=$4
fi
declare -A list_of_levels=(
[5.0.1]=21 [5.0.1]=21
[5.1.1]=22 [5.1.1]=22
[6.0]=23 [6.0]=23
[7.0]=24
[7.1.1]=25
) )
for key in "${!levels[@]}"; do declare -A list_of_processors=(
if [[ $key == *"$GIVEN_VERSION"* ]]; then [arm]=armeabi-v7a
version=$key [x86]=x86_64
)
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 fi
done done
fi
# If version cannot be found in the list # If version cannot be found in the list
if [ -z "$version" ]; then if [ -z "$versions" ]; then
echo "Version is not found in the list or not supported! Support only version 5.0.1, 5.1.1, 6.0, 7.0, 7.1.1" echo "Android version \"$ANDROID_VERSION\" is not found in the list or not supported! Support only version 5.0.1, 5.1.1, 6.0, 7.0, 7.1.1"
exit 1 exit 1
fi fi
echo "Android version: $version" echo "Android versions: ${versions[@]}"
level=${levels[$version]}
echo "Api level: $level"
} }
function system_image() { function get_processors() {
case $PROCESSOR in processors=()
x86)
sys_img=x86_64 if [ "$PROCESSOR" == "all" ]; then
;; for key in "${!list_of_processors[@]}"; do
arm) processors+=($key)
sys_img=armeabi-v7a done
;; else
*) for key in "${!list_of_processors[@]}"; do
echo "Invalid processor! Valid options: x86, arm" if [[ $key == *"$PROCESSOR"* ]]; then
processors+=($key)
fi
done
fi
# If version cannot be found in the list
if [ -z "$processors" ]; then
echo "Invalid processor \"$PROCESSOR\"! Valid options: x86, arm"
exit 1 exit 1
;; fi
esac
echo "Processor: $PROCESSOR" echo "Processors: ${processors[@]}"
echo "System Image: $sys_img"
} }
function init() { get_android_versions
api_level get_processors
system_image
}
init
echo "Build tool: $build_tool"
IMAGE_NAME="$IMAGE-$PROCESSOR-$version"
echo "Image tag: $TAG"
function test() { function test() {
(export ANDROID_HOME=/root && export ANDROID_VERSION=$version && export API_LEVEL=$level \ (export ANDROID_HOME=/root && export ANDROID_VERSION=5.0.1 && export API_LEVEL=21 \
&& export PROCESSOR=$PROCESSOR && export SYS_IMG=$sys_img && nosetests -v) && export PROCESSOR=x86 && export SYS_IMG=x86_64 && nosetests -v)
} }
function build() { function build() {
# Remove pyc files # Remove pyc files
find . -name "*.pyc" -exec rm -f {} \; find . -name "*.pyc" -exec rm -f {} \;
docker build -t $IMAGE_NAME --build-arg ANDROID_VERSION=$version --build-arg BUILD_TOOL=$LATEST_BUILD_TOOL \ # Build docker image(s)
--build-arg API_LEVEL=$level --build-arg PROCESSOR=$PROCESSOR --build-arg SYS_IMG=$sys_img . for p in "${processors[@]}"; do
for v in "${versions[@]}"; do
level=${list_of_levels[$v]}
echo "[BUILD] API Level: $level"
sys_img=${list_of_processors[$p]}
echo "[BUILD] System Image: $sys_img"
image_version="$IMAGE-$p-$v:$RELEASE"
image_latest="$IMAGE-$p-$v:latest"
echo "[BUILD] Image name: $image_version and $image_latest"
docker build -t $image_version --build-arg ANDROID_VERSION=$v --build-arg BUILD_TOOL=$LATEST_BUILD_TOOL \
--build-arg API_LEVEL=$level --build-arg PROCESSOR=$p --build-arg SYS_IMG=$sys_img .
docker build -t $image_latest --build-arg ANDROID_VERSION=$v --build-arg BUILD_TOOL=$LATEST_BUILD_TOOL \
--build-arg API_LEVEL=$level --build-arg PROCESSOR=$p --build-arg SYS_IMG=$sys_img .
done
done
} }
function push() { function push() {
docker push $IMAGE_NAME # Push docker image(s)
for p in "${processors[@]}"; do
for v in "${versions[@]}"; do
image_version="$IMAGE-$p-$v:$RELEASE"
image_latest="$IMAGE-$p-$v:latest"
echo "[PUSH] Image name: $image_version and $image_latest"
docker push $image_version
docker push $image_latest
done
done
} }
case $TASK in case $TASK in

14
travis.sh Executable file
View file

@ -0,0 +1,14 @@
#!/bin/bash
# Bash version should >= 4 to be able to run this script.
if [ -z "$TRAVIS_TAG" ]; then
echo "UNIT TEST ONLY"
bash release.sh test all all 0.1
else
echo "Log in to docker hub"
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
echo "RUN UNIT TEST, BUILD DOCKER IMAGES AND PUSH THOSE TO DOCKER HUB"
bash release.sh all all all $TRAVIS_TAG
echo "Log out of docker hub"
docker logout
fi