Skip to content

Commit

Permalink
Merge pull request #371 from onaio/code-cov-refactor
Browse files Browse the repository at this point in the history
[DNM] Code coverage refactor
  • Loading branch information
ndegwamartin authored Sep 18, 2024
2 parents 3465b99 + 6f97d0e commit 93c3eb6
Show file tree
Hide file tree
Showing 75 changed files with 794 additions and 869 deletions.
79 changes: 62 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,87 @@ on:
branches: [ master ]
pull_request:
branches: [ master ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
unit_tests:
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}

runs-on: macos-latest
runs-on: ubuntu-latest
strategy:
matrix:
api-level: [34]

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
- name: Checkout 🛎️
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 11
distribution: temurin
java-version: 17

- name: Enable KVM
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Create local.properties file
run: touch local.properties && echo "mapbox.repo.token=${{ secrets.MAPBOX_SDK_REPO_TOKEN }}" >> local.properties

- name: Print Java version
run: java -version

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Git show commit count
run: git fetch origin master && git rev-list --first-parent --count origin/master
- name: Download Robolectric deps
run: chmod +x download-robolectric-deps.sh && ./download-robolectric-deps.sh
- name: Clean project
run: ./gradlew clean --stacktrace
- name: Build project skipping tests
run: ./gradlew build -x test --stacktrace
- name: Run Instrumented Tests manually

- name: Load AVD cache
uses: actions/cache@v4
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-${{ matrix.api-level }}

- name: Create AVD and generate snapshot for caching
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 22
script: ./gradlew connectedDebug --stacktrace --info
- name: Run jacocoTestReport for each module
run: ./gradlew jacocoTestReport --stacktrace --info
api-level: ${{ matrix.api-level }}
arch: x86_64
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: false
script: echo "Generated AVD snapshot for caching."

- name: Run instrumentation tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
arch: x86_64
force-avd-creation: true
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
script: ./gradlew clean connectedDebugAndroidTest --stacktrace

- name: Run unit tests for each module
run: ./gradlew testDebugUnitTest --stacktrace

- name: Generate jacocoTestReport for each module
run: ./gradlew jacocoTestReport --stacktrace

- name: Merge jacoco reports from all modules
run: ./gradlew jacocoFullReport --stacktrace

- name: Upload coverage to Coveralls with Gradle
run: ./gradlew coveralls --stacktrace
run: ./gradlew coveralls --stacktrace
28 changes: 7 additions & 21 deletions .github/workflows/library.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,16 @@ jobs:
- name: Cancel previous workflow runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
access_token: ${{ github.token }}

- name: Checkout 🛎️
uses: actions/checkout@v2
with:
fetch-depth: 2
uses: actions/checkout@v4

- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
distribution: temurin
java-version: 17

- name: Create local.properties file
run: touch local.properties && echo "mapbox.repo.token=${{ secrets.MAPBOX_SDK_REPO_TOKEN }}" >> local.properties
Expand All @@ -45,25 +44,12 @@ jobs:

- name: Git show commit count
run: git fetch origin master && git rev-list --first-parent --count origin/master

- name: Download Robolectric deps
run: chmod +x download-robolectric-deps.sh && ./download-robolectric-deps.sh


- name: Clean project
run: ./gradlew clean --stacktrace

- name: Build project skipping tests
run: ./gradlew build -x test --stacktrace

- name: Run Instrumented Tests manually
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 22
script: ./gradlew :library:connectedDebug --stacktrace --info
run: ./gradlew clean --stacktrace

- name: Run unit tests with Gradle
run: ./gradlew :library:clean :library:testDebugUnitTest --stacktrace

- name: Generate & upload library snapshot artifact AAR (Android Archive) file
run: ./gradlew :library:clean --stacktrace && ./gradlew :library:assembleRelease --stacktrace && ./gradlew :library:publishMavenJavaPublicationToMavenCentralRepository --stacktrace

Expand All @@ -73,4 +59,4 @@ jobs:
- name: Github Release
uses: softprops/action-gh-release@v1
with:
prerelease: ${{ contains(github.ref, '-alpha') || contains(github.ref, '-beta') }}
prerelease: ${{ contains(github.ref, '-alpha') || contains(github.ref, '-beta') }}
27 changes: 7 additions & 20 deletions .github/workflows/utils.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,16 @@ jobs:
- name: Cancel previous workflow runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
access_token: ${{ github.token }}

- name: Checkout 🛎️
uses: actions/checkout@v2
with:
fetch-depth: 2
uses: actions/checkout@v4

- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 11
distribution: temurin
java-version: 17

- name: Create local.properties file
run: touch local.properties && echo "mapbox.repo.token=${{ secrets.MAPBOX_SDK_REPO_TOKEN }}" >> local.properties
Expand All @@ -45,22 +44,10 @@ jobs:

- name: Git show commit count
run: git fetch origin master && git rev-list --first-parent --count origin/master

- name: Download Robolectric deps
run: chmod +x download-robolectric-deps.sh && ./download-robolectric-deps.sh


- name: Clean project
run: ./gradlew clean --stacktrace

- name: Build project skipping tests
run: ./gradlew build -x test --stacktrace

- name: Run Instrumented Tests manually
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 22
script: ./gradlew :utils:connectedDebug --stacktrace

- name: Generate & upload utils snapshot artifact AAR (Android Archive) file to Sonatype
run: ./gradlew :utils:clean --stacktrace && ./gradlew :utils:assembleRelease --stacktrace && ./gradlew :utils:publishMavenJavaPublicationToMavenCentralRepository --stacktrace

Expand All @@ -70,4 +57,4 @@ jobs:
- name: Github Release
uses: softprops/action-gh-release@v1
with:
prerelease: ${{ contains(github.ref, '-alpha') || contains(github.ref, '-beta') }}
prerelease: ${{ contains(github.ref, '-alpha') || contains(github.ref, '-beta') }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Kujaku (Peacock) ![Build Status](https://github.com/onaio/kujaku/actions/workflows/ci.yml/badge.svg) ![Download](https://badgen.net/maven/v/maven-central/io.ona.kujaku/library) [![Coverage Status](https://coveralls.io/repos/github/onaio/kujaku/badge.svg)](https://coveralls.io/github/onaio/kujaku)

A mapping and check-in library for Android using **MapBox SDK (Version 8.3.3)**
A mapping and check-in library for Android using **MapBox SDK (Version 9.7.1)**

## IMPORTANT UPDATE

Expand Down
39 changes: 26 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
buildscript {
repositories {
google()
jcenter()
mavenCentral()
maven{ url "https://plugins.gradle.org/m2/" }
}

dependencies {

classpath 'com.android.tools.build:gradle:7.1.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
classpath 'com.android.tools.build:gradle:8.4.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
classpath 'gradle.plugin.org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.12.0'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.1'
classpath 'gradle.plugin.org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.12.2'
classpath 'com.google.firebase:firebase-crashlytics-gradle:3.0.2'
//classpath 'com.palantir:jacoco-coverage:0.4.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -27,14 +25,15 @@ apply from: 'configs.gradle'
allprojects {
repositories {
google()
jcenter()
mavenCentral()
mavenLocal()
maven { url "https://jitpack.io" }
maven { url "https://repository.liferay.com/nexus/content/repositories/public" }
maven {
url "https://dl.cloudsmith.io/public/terraframe/geoprism-registry/maven/"
}
maven {
url 'https://api.mapbox.com/downloads/v2/releases/maven'
url "https://api.mapbox.com/downloads/v2/releases/maven"
authentication {
basic(BasicAuthentication)
}
Expand All @@ -46,6 +45,8 @@ allprojects {
password = localProperties['mapbox.repo.token'] ?: ""
}
}
maven{url "https://oss.sonatype.org/content/repositories/snapshots"}
maven{url "https://s01.oss.sonatype.org/content/repositories/snapshots"}
}

}
Expand All @@ -58,14 +59,27 @@ task clean(type: Delete) {
apply plugin: 'java'

coveralls {
jacocoReportPath = "${buildDir}/reports/jacoco/jacocoFullReport/jacocoFullReport.xml"
jacocoReportPath = layout.buildDirectory.dir("reports/jacoco/jacocoFullReport/jacocoFullReport.xml")
sourceDirs += ["utils/src/main/java"
, "library/src/main/java"
, "sample/src/main/java"
, "wrapper/src/main/java"]
}

task jacocoFullReport(type: JacocoReport, group: 'Coverage reports') {

mustRunAfter ":library:testDebugUnitTest"
mustRunAfter ":utils:testDebugUnitTest"
mustRunAfter ":sample:testDebugUnitTest"

mustRunAfter ":library:connectedDebugAndroidTest"
mustRunAfter ":utils:connectedDebugAndroidTest"
mustRunAfter ":sample:connectedDebugAndroidTest"

mustRunAfter ":library:jacocoTestReport"
mustRunAfter ":utils:jacocoTestReport"
mustRunAfter ":sample:jacocoTestReport"

description = 'Generates an aggregate report from all subprojects'

additionalSourceDirs.from = files(subprojects.sourceSets.main.allSource.srcDirs)
Expand Down Expand Up @@ -94,12 +108,11 @@ task jacocoFullReport(type: JacocoReport, group: 'Coverage reports') {
sourceDirectories.from = sourcePaths
classDirectories.from = classPaths

getReports().getXml().setDestination(file("${buildDir}/reports/jacoco/jacocoFullReport/jacocoFullReport.xml"))
getReports().getHtml().setDestination(file("${buildDir}/reports/jacoco/jacocoFullReport/html"))

reports {
html.enabled true
xml.enabled true
xml.required.set(true)
html.required.set(true)
xml.outputLocation = layout.buildDirectory.file("reports/jacoco/jacocoFullReport/jacocoFullReport.xml")
html.outputLocation = layout.buildDirectory.dir("reports/jacoco/jacocoFullReport/html")
}

jacocoClasspath = files(jacocoClasspathPaths)
Expand Down
23 changes: 10 additions & 13 deletions configs.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -104,31 +104,28 @@ ext {

// Dependency and other versions
androidxTestCoreVersion = "1.4.0"
buildToolsVersion = "30.0.3"
compileSdkVersion = 28
jacocoVersion = "0.8.8"
junitVersion = "4.12"
compileSdkVersion = 34
jacocoVersion = "0.8.11"
junitVersion = "4.13.2"
mapboxAnnotationPluginVersion = "0.9.0"
mapboxSdkVersion = "9.7.1"
robolectricShadowsMultidexVersion = "4.3.1"
robolectricVersion = "4.3.1"
mapboxSdkTurfVersion = "7.2.0"
robolectricShadowsMultidexVersion = "4.13"
robolectricVersion = "4.13"
supportVersion = "1.0.0"
volleyVersion = "1.2.0"
targetSdkVersion = 27
volleyVersion = "1.2.1"
targetSdkVersion = 34

// Dependency names
androidxTestCore = "androidx.test:core:$androidxTestCoreVersion"
junit = "junit:junit:$junitVersion"
mapboxSDK = "com.mapbox.mapboxsdk:mapbox-android-sdk:$mapboxSdkVersion"
mapboxSDKTurf = "com.mapbox.mapboxsdk:mapbox-sdk-turf:4.8.0"
mapboxSDKTurf = "com.mapbox.mapboxsdk:mapbox-sdk-turf:$mapboxSdkTurfVersion"
mapboxAnnotationPlugin = "com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v9:$mapboxAnnotationPluginVersion"
robolectric = "org.robolectric:robolectric:$robolectricVersion"
robolectricShadowsMultidex = "org.robolectric:shadows-multidex:$robolectricShadowsMultidexVersion"
}


//ext.mapboxSDK = "com.mapbox.maps:android:10.7.0"

ext.mapboxDependencies = { instance, configuration ->

configuration.implementation("com.mapbox.maps:android:$mapboxSdkVersion") {
Expand All @@ -142,7 +139,7 @@ ext.mapboxDependencies = { instance, configuration ->
// The local build has an issue fetching this library for some reason which
// is a dependency of the mapbox-android-sdk. The mapbox-sdk-turf is declared as
// a runtime dependency
configuration.implementation 'com.mapbox.mapboxsdk:mapbox-sdk-turf:4.8.0'
configuration.implementation "com.mapbox.mapboxsdk:mapbox-sdk-turf:$instance.mapboxSdkTurfVersion"
configuration.implementation "com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v7:${instance.mapboxAnnotationPluginVersion}"

}
Expand Down
16 changes: 0 additions & 16 deletions download-robolectric-deps.sh

This file was deleted.

3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ POM_SETTING_DEVELOPER_ID=opensrp
POM_SETTING_DEVELOPER_NAME=OpenSRP Onadev
android.useAndroidX=true
android.enableJetifier=true
android.nonFinalResIds=false

android.jetifier.ignorelist=shadows,bcprov-jdk15on
android.jetifier.ignorelist=shadows,bcprov-jdk18on
#android.jetifier.blacklist=shadows,bcprov-jdk15on

# android.debug.obsoleteApi=true
Expand Down
Loading

0 comments on commit 93c3eb6

Please sign in to comment.