0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-20 12:02:16 +02:00
Anki-Android/.travis.yml
Mike Hardy fd0742cd30 NF: update Travis CI build toold / platform to 29
These were missed in the forward port to API29 which caused non-retry
downloads of build tools and android platform SDK during build instead
of before the build

updating the old API28 download to be the needed 29 ones and commenting
build.gradle to note the cross-dependency for next time
2020-10-23 14:38:48 -05:00

203 lines
11 KiB
YAML

language: bash
# ignored on non-linux platforms, but bionic is required for nested virtualization
dist: bionic
workspaces:
use: apk_cache
stages:
- install
- unit_test # custom stage defined in jobs::include section
- test
- finalize_coverage # custom stage defined in jobs::include section
- cache
env:
global:
- 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
- LOCALE="NONE"
- GRAVIS_REPO="https://github.com/DanySK/Gravis-CI.git"
- GRAVIS="$HOME/gravis"
- JDK="1.8"
- TOOLS=${ANDROID_HOME}/tools
- APK_CACHE_FILE=com.ichi2.anki.apk
- APK_TEST_CACHE_FILE=com.ichi2.anki.tests.apk
# 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
- LINT=FALSE # by default we don't lint, they are run only in specific builds
- FINALIZE_COVERAGE=FALSE # by default we don't finalize coverage, it is done in one specific build
- CLEAR_APK_CACHE=FALSE # by default we don't clear the APK cache, it is done in one specific build
- TERM=dumb
matrix:
- API=16 ABI=x86 AUDIO=-no-audio LOCALE="ko_KR"
- API=17 ABI=x86 LOCALE="it_IT"
#- API=18 ABI=x86 # frequently flaky: test run failed: 'Instrumentation run failed due to 'java.lang.SecurityException''
- API=19 ABI=x86 LOCALE="vi_VN"
# API 20 was Android Wear only
- API=21 LOCALE="pl_PL"
- API=22 LOCALE="ja_JP"
- API=23 LOCALE="ru_RU"
- API=24 LOCALE="zh_CN"
- API=25 LOCALE="es_ES"
#- API=26 # Fails with unrecognized tests? orchestrator change or something?
#- API=27 LOCALE="fr_FR" # API27 has become very flaky recently, disabling 2020/08/20
- API=28 # API28 does not handle locale changes for some reason, so it is our default locale test
- API=29 LOCALE="pt_BR"
- API=30 EMU_FLAVOR=google_apis LOCALE="de_DE" # This will be API30 when released, until now it is R, with intermittent failure
- API=24 JDK="1.11" # make sure we work in future dev environments
- API=24 JDK="1.14" # make sure we work in future dev environments
jobs:
fast_finish: true # Report success without waiting for jobs that allowed to fail.
include:
# The "test" stage is implicit and gets the main matrix. This adds extra stages/jobs
- stage: unit_test
name: "Unit Tests - Windows"
env: UNIT_TEST=TRUE API=NONE
install: skip
os: windows
- stage: unit_test
name: "Unit Tests - macOS"
env: UNIT_TEST=TRUE API=NONE
install: skip
os: osx
- stage: unit_test
name: "Unit Tests - Linux"
env: UNIT_TEST=TRUE API=NONE
install: skip
os: linux
- stage: unit_test
name: "Lint - Release"
env: LINT=Release API=NONE
workspaces:
create:
name: apk_cache
paths:
- com.ichi2.anki.apk
- AnkiDroid-x86_64-debug.apk
- com.ichi2.anki.tests.apk
- test-metadata.json
- output-metadata.json
install: skip
os: linux
- stage: unit_test
name: "Lint - Debug (expected to fail - all errors since last baseline)"
env: LINT=Debug API=NONE
install: skip
os: linux
- stage: finalize_coverage
env: FINALIZE_COVERAGE=TRUE API=NONE
name: "Finalize Codacy Coverage Uploads"
install: skip
script: echo finalize codacy coverage uploads
allow_failures:
- env: API=30 EMU_FLAVOR=google_apis LOCALE="de_DE" # unreleased Android API30 is failing in local builds, let's expose that on Travis
- env: API=24 JDK="1.11" # non-default JDKs should not hold up success reporting
- env: API=24 JDK="1.14" # non-default JDKs should not hold up success reporting
- env: LINT=Debug API=NONE # we want to see the full lint report vs baseline but not fail on it
- env: FINALIZE_COVERAGE=TRUE API=NONE # finalizing coverage should not hold up success reporting
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
- travis_retry git clone --depth 1 $GRAVIS_REPO $GRAVIS
- export TARGET_JDK="${JDK}"
- JDK="adopt@1.8"
- source $GRAVIS/install-jdk
- if [ "$API" != "NONE" ] && [[ ! -f "${APK_CACHE_FILE}" || ! -f ${APK_TEST_CACHE_FILE} ]]; then travis_terminate 12; fi
# Set up Android SDK - this is needed everywhere but coverage finalization, so toggle on that
- if [ "$FINALIZE_COVERAGE" = "FALSE" ]; then travis_retry 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 | travis_retry sdkmanager --licenses >/dev/null; fi # accept all sdkmanager warnings
- if [ "$FINALIZE_COVERAGE" = "FALSE" ]; then echo y | travis_retry sdkmanager --no_https "platform-tools" >/dev/null; fi
- if [ "$FINALIZE_COVERAGE" = "FALSE" ]; then echo y | travis_retry sdkmanager --no_https "tools" >/dev/null; fi # A second time per Travis docs, gets latest versions
- if [ "$FINALIZE_COVERAGE" = "FALSE" ]; then echo y | travis_retry sdkmanager --no_https "build-tools;29.0.2" >/dev/null; fi # Implicit gradle dependency - gradle drives changes
- if [ "$FINALIZE_COVERAGE" = "FALSE" ]; then echo y | travis_retry sdkmanager --no_https "platforms;android-29" >/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 | travis_retry sdkmanager --no_https "platforms;android-$API" >/dev/null # We need the API of the emulator we will run
- echo y | travis_retry sdkmanager --no_https "emulator" >/dev/null
- echo y | travis_retry 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
- travis_retry 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
- ./tools/android-wait-for-emulator.sh
- adb shell input keyevent 82 &
# Switch locale
- if [ "$LOCALE" != "NONE" ]; then adb shell am broadcast -a com.android.intent.action.SET_LOCALE --es com.android.intent.extra.LOCALE "$LOCALE" com.android.customlocale2; fi
# Switch back to our target JDK version to build and run tests
- JDK="adopt@${TARGET_JDK}"
- source $GRAVIS/install-jdk
- mkdir -p ${TRAVIS_BUILD_DIR}/AnkiDroid/build/outputs/apk/debug/
- mkdir -p ${TRAVIS_BUILD_DIR}/AnkiDroid/build/outputs/apk/androidTest/debug/
- cp output-metadata.json ${TRAVIS_BUILD_DIR}/AnkiDroid/build/outputs/apk/debug/output-metadata.json
- cp ${APK_CACHE_FILE} ${TRAVIS_BUILD_DIR}/AnkiDroid/build/outputs/apk/debug/AnkiDroid-x86-debug.apk
- cp AnkiDroid-x86_64-debug.apk ${TRAVIS_BUILD_DIR}/AnkiDroid/build/outputs/apk/debug/AnkiDroid-x86_64-debug.apk
- cp test-metadata.json ${TRAVIS_BUILD_DIR}/AnkiDroid/build/outputs/apk/androidTest/debug/output-metadata.json
- cp ${APK_TEST_CACHE_FILE} ${TRAVIS_BUILD_DIR}/AnkiDroid/build/outputs/apk/androidTest/debug/AnkiDroid-debug-androidTest.apk
script:
- if [ "$API" = "NONE" ]; then travis_retry ./gradlew :AnkiDroid:compileReleaseJavaWithJavac compileLint; fi # warm gradle w/travis_retry to handle network blips
- if [ "$UNIT_TEST" = "TRUE" ]; then travis_retry ./gradlew robolectricSdkDownload; fi # pre-download robolectric jars w/travis_retry to handle network blips
- if [ "$UNIT_TEST" = "TRUE" ]; then ./gradlew jacocoUnitTestReport; fi
- if [ "$LINT" != "FALSE" ]; then ./gradlew lint$LINT; fi
# apks are copied from the workspace
- if [ "$API" != "NONE" ]; then ./gradlew jacocoAndroidTestReport -x packageDebugAndroidTest -x packageDebug; fi
- if [ "$LINT" = "Release" ]; then ./gradlew assembleDebug assembleAndroidTest; fi # generate APKs to cache
- if [ "$LINT" = "Release" ]; then echo "copying APKs to cache"; fi
- if [ "$LINT" = "Release" ]; then cp ${TRAVIS_BUILD_DIR}/AnkiDroid/build/outputs/apk/debug/AnkiDroid-x86-debug.apk ${APK_CACHE_FILE}; fi
- if [ "$LINT" = "Release" ]; then cp ${TRAVIS_BUILD_DIR}/AnkiDroid/build/outputs/apk/debug/AnkiDroid-x86_64-debug.apk AnkiDroid-x86_64-debug.apk; fi
- if [ "$LINT" = "Release" ]; then cp ${TRAVIS_BUILD_DIR}/AnkiDroid/build/outputs/apk/debug/output-metadata.json output-metadata.json; fi
- if [ "$LINT" = "Release" ]; then cp ${TRAVIS_BUILD_DIR}/AnkiDroid/build/outputs/apk/androidTest/debug/AnkiDroid-debug-androidTest.apk ${APK_TEST_CACHE_FILE}; fi
- if [ "$LINT" = "Release" ]; then cp ${TRAVIS_BUILD_DIR}/AnkiDroid/build/outputs/apk/androidTest/debug/output-metadata.json test-metadata.json; fi
after_success:
- if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then travis_retry bash tools/upload-codacy-report.sh; fi
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- $GRAVIS/clean-gradle-cache
cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
notifications:
email:
- github@mikehardy.net