-
Notifications
You must be signed in to change notification settings - Fork 7
CirrusCi
This projects needs to display offline map so we decided to use MapBox because the api of Google Maps doesn't provide this functionnality. MapBox is a free api which on the contrary provide this feature and much more but is working with OpenGL behind the scene.
The "problem" with this product is that it uses some c++ code internally and therefore requires NDK and some hardware acceleration to work. In the case where you want to test your code you then need a Ci/CD plateform which supports Hardware Acceleration otherwise it's not possible to test your which interract with MapBox.
The previous CI/CD plateform we used "Travis" doesn't offer this possibility yet and therefore it was not possible for us to test our which represent a big part of our project. The solution we have found is to use CirrusCI, this CI/CD doesn't have this restriction and there for enable us to fully test our code which is what we wanted.
One more advantage of this technology is that it offer the possibility to have lint warnings directly on GitHub during pull requests (Twitter announce).
First create the file .cirrus.yml
and then copy past the following code :
NOTE : The script create_mavsdk_server_script
is not neccesery and you can discard it. It is specific for our project as we need to run an instance of mavsdk_server
for our tests.
connected_check_task:
name: Run Android instrumented tests
env:
API_LEVEL: 28
TARGET: default
ARCH: x86
CC_TEST_REPORTER_ID: ENCRYPTED[437c27bfb64040626acf7f420701b9391f80e46bcdc9b1a11f5a8a8ed35ee5f66576f7289bb71ff7e18c822219e8a620]
GRADLE_OPTS: -Dkotlin.compiler.execution.strategy=in-process
container:
image: reactivecircus/android-emulator-${API_LEVEL}:latest
kvm: true
cpu: 8
memory: 24G
create_mavsdk_server_script:
- curl -L https://github.com/mavlink/MAVSDK/releases/download/v0.26.0/mavsdk_server_manylinux2010-x64 > ./mavsdk_server_manylinux1-x64
- chmod +x ./mavsdk_server_manylinux1-x64
- ./mavsdk_server_manylinux1-x64 -p 50051 &
create_device_script:
echo no | avdmanager create avd --force --name "api-${API_LEVEL}" --abi "${TARGET}/${ARCH}" --package "system-images;android-${API_LEVEL};${TARGET};${ARCH}"
start_emulator_background_script:
$ANDROID_SDK_ROOT/emulator/emulator -avd "api-${API_LEVEL}" -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim -camera-back none
assemble_instrumented_tests_script:
./gradlew assembleDebugAndroidTest
wait_for_emulator_script: |
adb wait-for-device
adb shell input keyevent 82
disable_animations_script: |
adb shell settings put global window_animation_scale 0.0
adb shell settings put global transition_animation_scale 0.0
adb shell settings put global animator_duration_scale 0.0
prepare_codeclimate_script:
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
run_instrumented_tests_script:
./gradlew check connectedCheck jacocoTestReport
report_codeclimate_script:
# Report test coverage to Code Climate
- export JACOCO_SOURCE_PATH=app/src/main/java/
- ./cc-test-reporter format-coverage ./app/build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml --input-type jacoco
- ./cc-test-reporter upload-coverage
android_lint_task:
container:
image: cirrusci/android-sdk:29
cpu: 4
memory: 10G
name: Android Lint
lint_script: ./gradlew lintDebug
always:
android-lint_artifacts:
path: ./app/build/reports/lint-results-debug.xml
type: text/xml
format: android-lint
As ou can see, we optimized our build process by running the build of our project before waiting for our emulator to start. This rearrange make us spare almost one minute(the time for the emulator to start).
The second part of cirrus.yml
configure a task which is going to run the linter. Once this is configure, you will automatically have the linter's feedback in GitHub. To see thoses feedback go to Files changed
.
This code is configure to use CodeClimate. In order to configure the CodeClimate Repport Key
you need to go to https://cirrus-ci.com/ and then in your corresponding repo.
There you can access to settings and encrypt some values. The things you need to do is to past your acces code of CodeClimate and encrypt it. Once you have your new string which should respect this format ENCRYPTED[437c27bfb64040626acf7f420701b9391f80e46bcdc9b1a11f5a8a8ed35ee5f66576f7289bb71ff7e18c822219e8a620]
then replace the value of the variable CC_TEST_REPORTER_ID
in .cirrus.yml
with you own generated key.
The settings for build succes is almost identically to Travis, go to your Github repo then settings and branches. There you can edit your master settings by unchecking the travis check and enable Run Android instrumented tests
(Do not enable CirrusCi
).
All documentation for badges is available here:
Cirrus supports natively httpcache to speed up your builds. To enable it, add the following lines inside your settings.gradle
file.
ext.isCiServer = System.getenv().containsKey("CIRRUS_CI")
ext.isMasterBranch = System.getenv()["CIRRUS_BRANCH"] == "master"
ext.buildCacheHost = System.getenv().getOrDefault("CIRRUS_HTTP_CACHE_HOST", "localhost:12321")
buildCache {
local {
enabled = !isCiServer
}
remote(HttpBuildCache) {
url = "http://${buildCacheHost}/"
enabled = isCiServer
push = isMasterBranch
}
}
It possible to speed up you build by updating your file gradle.properties
and adding the following properties :
org.gradle.jvmargs=-Dfile.encoding=UTF-8
org.gradle.daemon=true
org.gradle.caching=true
org.gradle.parallel=true
#org.gradle.configureondemand=true
The last property may not be relevant for all projects.