Skip to content

Commit

Permalink
Update Travis CI configuration as an old one doesn't work anymore (pr…
Browse files Browse the repository at this point in the history
…ocess crashes)
  • Loading branch information
yvolk committed May 15, 2020
1 parent 772c3ce commit ffde4db
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 45 deletions.
150 changes: 106 additions & 44 deletions .travis.yml
@@ -1,39 +1,96 @@
language: android
jdk:
- oraclejdk8
# Based on https://travis-ci.org/ankidroid/Anki-Android/builds/624268367
# See also https://travis-ci.community/t/is-android-28-emulator-supported/1718/6
sudo: true
language: bash
# ignored on non-linux platforms, but bionic is required for nested virtualization
dist: bionic

stages:
- install
- unit_test # custom stage defined in jobs::include section
- test
- finalize_coverage # custom stage defined in jobs::include section
- cache

env:
global:
- ANDROID_API=29
- EMULATOR_API=24
- ANDROID_BUILD_TOOLS=29.0.2
android:
components:
- tools
- android-$EMULATOR_API
- platform-tools
- tools
- build-tools-$ANDROID_BUILD_TOOLS
- android-$ANDROID_API
- extra-android-support
- extra-android-m2repository
- extra-google-m2repository
- sys-img-armeabi-v7a-android-$EMULATOR_API
licenses:
- ".+"
before_script:
- echo "y" | android update sdk -a --no-ui --filter android-$EMULATOR_API
- echo "y" | android update sdk -a --no-ui --filter sys-img-armeabi-v7a-android-$EMULATOR_API
- android list targets | grep -E '^id:' | awk -F '"' '{$1=""; print $2}' # list all targets
- echo no | android create avd --force -n test -t android-$EMULATOR_API --abi armeabi-v7a
- emulator -avd test -no-skin -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &
- adb wait-for-device get-serialno
- cd ${TRAVIS_BUILD_DIR}
- chmod +x gradlew
- ./gradlew --version
- ./gradlew clean
- COMPILE_API=29
- ANDROID_BUILD_TOOLS=29.0.3
- ABI=x86_64
- ADB_INSTALL_TIMEOUT=8
- ANDROID_HOME=${HOME}/android-sdk
- ANDROID_TOOLS_URL="https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip"
- EMU_FLAVOR=default # use google_apis flavor if no default flavor emulator
- GRAVIS="https://raw.githubusercontent.com/DanySK/Gravis-CI/master/"
- JDK="1.8"
- TOOLS=${ANDROID_HOME}/tools
# PATH order is incredibly important. e.g. the 'emulator' script exists in more than one place!
- PATH=${ANDROID_HOME}:${ANDROID_HOME}/emulator:${TOOLS}:${TOOLS}/bin:${ANDROID_HOME}/platform-tools:${PATH}
- UNIT_TEST=FALSE # by default we don't run the unit tests, they are run only in specific builds
- FINALIZE_COVERAGE=FALSE # by default we don't finalize coverage, it is done in one specific build
matrix:
- API=24
- API=25
- API=27
- API=28
- API=29

before_install:
# This section may run on all platforms, and may run for unit tests or for coverage finalization
# It should not make assumptions about os platform or desired tool installation

# Set up JDK 8 for Android SDK - Java is universally needed: codacy, unit tests, emulators
- curl "${GRAVIS}.install-jdk-travis.sh" --output ~/.install-jdk-travis.sh
- export TARGET_JDK="${JDK}"
- JDK="1.8"
- source ~/.install-jdk-travis.sh

# Set up Android SDK - this is needed everywhere but coverage finalization, so toggle on that
- if [ "$FINALIZE_COVERAGE" = "FALSE" ]; then wget -q "${ANDROID_TOOLS_URL}" -O android-sdk-tools.zip; fi
- if [ "$FINALIZE_COVERAGE" = "FALSE" ]; then unzip -q android-sdk-tools.zip -d ${ANDROID_HOME}; fi
- if [ "$FINALIZE_COVERAGE" = "FALSE" ]; then rm android-sdk-tools.zip; fi
- if [ "$FINALIZE_COVERAGE" = "FALSE" ]; then mkdir ~/.android; fi # avoid harmless sdkmanager warning
- if [ "$FINALIZE_COVERAGE" = "FALSE" ]; then echo 'count=0' > ~/.android/repositories.cfg; fi # avoid harmless sdkmanager warning
- if [ "$FINALIZE_COVERAGE" = "FALSE" ]; then yes | sdkmanager --licenses >/dev/null; fi # accept all sdkmanager warnings
- if [ "$FINALIZE_COVERAGE" = "FALSE" ]; then echo y | sdkmanager --no_https "platform-tools" >/dev/null; fi
- if [ "$FINALIZE_COVERAGE" = "FALSE" ]; then echo y | sdkmanager --no_https "tools" >/dev/null; fi # A second time per Travis docs, gets latest versions
- if [ "$FINALIZE_COVERAGE" = "FALSE" ]; then echo y | sdkmanager --no_https "build-tools;${ANDROID_BUILD_TOOLS}" >/dev/null; fi # Implicit gradle dependency - gradle drives changes
- if [ "$FINALIZE_COVERAGE" = "FALSE" ]; then echo y | sdkmanager --no_https "platforms;android-${COMPILE_API}" >/dev/null; fi # We need the API of the current compileSdkVersion from gradle.properties

install:
# In our setup, install only runs on matrix entries we want full emulator tests on
# That only happens currently on linux, so this section can assume linux + emulator is desired
# Download required emulator tools
- echo y | sdkmanager --no_https "platforms;android-$API" >/dev/null # We need the API of the emulator we will run
- echo y | sdkmanager --no_https "emulator" >/dev/null
- echo y | sdkmanager --no_https "system-images;android-$API;$EMU_FLAVOR;$ABI" >/dev/null # install our emulator

# Set up KVM on linux for hardware acceleration. Manually here so it only happens for emulator tests, takes ~30s
- sudo -E apt-get -yq --no-install-suggests --no-install-recommends install bridge-utils libpulse0 libvirt-bin qemu-kvm virtinst ubuntu-vm-builder
- sudo adduser $USER libvirt
- sudo adduser $USER kvm

# Create an Android emulator
- echo no | avdmanager create avd --force -n test -k "system-images;android-$API;$EMU_FLAVOR;$ABI" -c 10M
- |
EMU_PARAMS="-verbose -no-snapshot -no-window -camera-back none -camera-front none -selinux permissive -qemu -m 2048"
EMU_COMMAND="emulator"
# This double "sudo" monstrosity is used to have Travis execute the
# emulator with its new group permissions and help preserve the rule
# of least privilege.
sudo -E sudo -u $USER -E bash -c "${ANDROID_HOME}/emulator/${EMU_COMMAND} -avd test ${AUDIO} ${EMU_PARAMS} &"
# Wait for emulator to be ready
- chmod +x ./tools/android-wait-for-emulator.sh
- ./tools/android-wait-for-emulator.sh
- adb shell input keyevent 82 &

# Switch back to our target JDK version to build and run tests
- JDK="${TARGET_JDK}"
- source ~/.install-jdk-travis.sh

script:
- chmod +x gradlew
- |
./gradlew build assembleAndroidTest
retval=$?
Expand Down Expand Up @@ -62,8 +119,10 @@ script:
# See https://developer.android.com/reference/android/test/InstrumentationTestRunner.html
# For testing one method only:
# - adb shell am instrument -w -r -e debug false -e class org.andstatus.app.service.CommandExecutorStrategyTest#testSearch org.andstatus.app.tests/androidx.test.runner.AndroidJUnitRunner

# See https://developer.android.com/studio/command-line/adb
- |
adb shell am instrument -w -r -e executionMode travisTest org.andstatus.app.tests/androidx.test.runner.AndroidJUnitRunner |& tee build/adb-test.log
adb shell am instrument -w -r -e debug false -e executionMode travisTest org.andstatus.app.tests/androidx.test.runner.AndroidJUnitRunner |& tee build/adb-test.log
retval=$?
if [ $retval -ne 0 ]; then
echo "error in adb, exit code: "$retval
Expand All @@ -81,15 +140,18 @@ script:
cat build/adb-test.log | grep "OK ("
fi
notifications:
email: false
after_success:
- ./gradlew sonarqube -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN -Dsonar.verbose=true

before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- curl "${GRAVIS}.clean_gradle_cache.sh" --output ~/.clean_gradle_cache.sh
- bash ~/.clean_gradle_cache.sh > /dev/null

cache:
directories:
- $HOME/.m2
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
- $HOME/.android/build-cache
before_install:
- yes | sdkmanager "platforms;android-$ANDROID_API"
after_success:
- ./gradlew sonarqube -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN -Dsonar.verbose=true
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/

notifications:
email: false
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -19,7 +19,7 @@ buildscript {

ext {
compileSdkVersion = 29 as int
buildToolsVersion = '29.0.2'
buildToolsVersion = '29.0.3'
minSdkVersion = 24 as int
targetSdkVersion = 29 as int

Expand Down
26 changes: 26 additions & 0 deletions tools/android-wait-for-emulator.sh
@@ -0,0 +1,26 @@
#!/bin/bash

# Originally written by Ralf Kistner <ralf@embarkmobile.com>, but placed in the public domain

set +e

bootanim=""
failcounter=0
timeout_in_sec=600 # 10 minutes

until [[ "$bootanim" =~ "stopped" ]]; do
bootanim=`adb -e shell getprop init.svc.bootanim 2>&1 &`
if [[ "$bootanim" =~ "device not found" || "$bootanim" =~ "device offline"
|| "$bootanim" =~ "running" || "$bootanim" =~ "error: no emulators found" ]]; then
let "failcounter += 1"
echo "Waiting for emulator to start"
if [[ $failcounter -gt timeout_in_sec ]]; then
echo "Timeout ($timeout_in_sec seconds) reached; failed to start emulator"
exit 1
fi
fi
sleep 1
done

echo "Emulator is ready"

0 comments on commit ffde4db

Please sign in to comment.