Skip to content

[MOB-10999] - JaCoCo Reporting and Codecov #892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 52 additions & 2 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,54 @@
codecov:
require_ci_to_pass: yes
notify:
after_n_builds: 2
wait_for_ci: yes

coverage:
precision: 2
round: down
range: "70...100"
status:
project: off
patch: off
project:
default:
target: auto
threshold: 1%
informational: false
patch:
default:
target: auto
threshold: 1%
informational: false

parsers:
gcov:
branch_detection:
conditional: yes
loop: yes
method: no
macro: no

ignore:
- "**/test/**/*"
- "**/androidTest/**/*"
- "**/*Test.java"
- "**/R.class"
- "**/R$*.class"
- "**/BuildConfig.class"
- "**/Manifest*.*"
- "**/*$ViewInjector*.*"

flags:
iterableapi:
paths:
- iterableapi/src/main/
iterableapi-ui:
paths:
- iterableapi-ui/src/main/

comment:
layout: "reach,diff,flags,files,footer"
behavior: default
require_changes: no
require_base: no
require_head: yes
141 changes: 78 additions & 63 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,15 @@ jobs:
- run: touch local.properties

- name: Test
# run: ./gradlew :iterableapi:jacocoTestDebugUnitTestReport :app:jacocoDebugTestReport
run: ./gradlew :iterableapi:testDebugUnitTest :app:testDebugUnitTest

# Coverage reporting temporarily disabled
# - name: Upload coverage data
# uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
# with:
# name: unit-tests
# path: |
# ./**/build/**/jacoco*.xml
# ./**/build/**/report.xml
run: ./gradlew :iterableapi:jacocoTestDebugUnitTestReport :iterableapi-ui:jacocoTestDebugUnitTestReport :app:jacocoDebugTestReport

- name: Upload coverage data
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
with:
name: unit-tests
path: |
./**/build/**/jacoco*.xml
./**/build/**/report.xml

instrumentation-tests:
name: Instrumentation tests
Expand All @@ -76,57 +74,74 @@ jobs:
- run: touch local.properties

- name: Test
uses: reactivecircus/android-emulator-runner@6b0df4b0efb23bb0ec63d881db79aefbc976e4b2 # v2.30.1
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 28
script: ./gradlew :iterableapi:connectedCheck

# Coverage reporting temporarily disabled
# - name: Upload coverage data
# uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
# with:
# name: instrumentation-tests
# path: |
# ./**/build/**/jacoco*.xml
# ./**/build/**/report.xml

# Coverage reporting temporarily disabled
# report-coverage:
# name: Report coverage
# runs-on: ubuntu-latest
# needs: [unit-tests, instrumentation-tests]
# env:
# JACOCO_SOURCE_PATH: "iterableapi/src/main/java iterableapi-ui/src/main/java"
# steps:
# - name: Checkout
# uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
# with:
# fetch-depth: 0
#
# - name: Configure JDK
# uses: actions/setup-java@d202f5dbf7256730fb690ec59f6381650114feb2 # v1.4.3
# with:
# java-version: 17
#
# - run: curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
# - run: chmod +x ./cc-test-reporter
# - run: ./cc-test-reporter before-build
#
# - name: Download unit tests coverage
# uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7
# with:
# name: unit-tests
#
# - name: Download instrumentation tests coverage
# uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7
# with:
# name: instrumentation-tests
#
# - run: bash <(curl -s https://codecov.io/bash)
# - run: ./cc-test-reporter format-coverage app/build/reports/jacoco/jacocoDebugTestReport/jacocoDebugTestReport.xml --input-type jacoco -d
# - run: ./cc-test-reporter format-coverage iterableapi/build/reports/coverage/androidTest/debug/connected/report.xml --input-type jacoco -d
# - run: ./cc-test-reporter format-coverage iterableapi/build/jacoco/jacoco.xml --input-type jacoco -d
# - run: ./cc-test-reporter format-coverage app/build/reports/jacoco/jacocoDebugAndroidTestReport/jacocoDebugAndroidTestReport.xml --input-type jacoco -d
# - run: ./cc-test-reporter upload-coverage
# env:
# CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
arch: x86_64
profile: Nexus 6
cores: 4
memory: 4096
emulator-options: -no-window -no-snapshot -noaudio -no-boot-anim -gpu swiftshader_indirect -memory 4096
script: ./gradlew :iterableapi:connectedCheck -Pandroid.testInstrumentationRunnerArguments.numShards=4 -Pandroid.testInstrumentationRunnerArguments.shardIndex=0

- name: Upload coverage data
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
with:
name: instrumentation-tests
path: |
./**/build/**/jacoco*.xml
./**/build/**/report.xml

report-coverage:
name: Report coverage
runs-on: ubuntu-latest
needs: [unit-tests, instrumentation-tests]
env:
JACOCO_SOURCE_PATH: "iterableapi/src/main/java iterableapi-ui/src/main/java"
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0

- name: Configure JDK
uses: actions/setup-java@d202f5dbf7256730fb690ec59f6381650114feb2 # v1.4.3
with:
java-version: 17

- name: Download unit tests coverage
uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7
with:
name: unit-tests

- name: Download instrumentation tests coverage
uses: actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e # v4.1.7
with:
name: instrumentation-tests

# Codecov integration
- name: Upload to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: |
./iterableapi/build/reports/jacoco/jacocoTestDebugUnitTestReport/jacocoTestDebugUnitTestReport.xml,
./iterableapi-ui/build/reports/jacoco/jacocoTestDebugUnitTestReport/jacocoTestDebugUnitTestReport.xml,
./app/build/reports/jacoco/jacocoDebugTestReport/jacocoDebugTestReport.xml,
./iterableapi/build/reports/coverage/androidTest/debug/connected/report.xml
fail_ci_if_error: false
verbose: true

# Fallback using bash uploader with explicit token
- name: Upload to Codecov via bash uploader
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: bash <(curl -s https://codecov.io/bash) -v

- uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: gradle-${{ runner.os }}-
39 changes: 39 additions & 0 deletions iterableapi-ui/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'jacoco'

android {
compileSdk 34
Expand Down Expand Up @@ -81,3 +82,41 @@ afterEvaluate {
javadoc.classpath += files(android.libraryVariants.collect { variant -> "build/generated/source/r/${variant.flavorName}/${variant.buildType.name}" })
javadoc.classpath += files(android.libraryVariants.collect { variant -> "build/generated/source/buildConfig/${variant.flavorName}/${variant.buildType.name}" })
}

tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
jacoco.excludes = ['jdk.internal.*']
}

task jacocoTestDebugUnitTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest']) {
group = "reporting"
description = "Generate Jacoco code coverage report"
reports {
xml.required = true
html.required = true
csv.required = false
}
def fileFilter = [
'**/*Test*.*',
'**/AutoValue_*.*',
'**/R.class',
'**/R$*.class',
'**/Manifest*.*',
'android/**/*.*',
'**/BuildConfig.*',
'**/Lambda$*.class',
'**/Lambda.class',
'**/*Lambda.class',
'**/*Lambda*.class'
]

def debugTree = fileTree(dir: "${buildDir}/intermediates/javac/debug/classes", excludes: fileFilter)
def kotlinDebugTree = fileTree(dir: "${buildDir}/tmp/kotlin-classes/debug", excludes: fileFilter)
def mainSrc = "${project.projectDir}/src/main/java"

sourceDirectories.from = files([mainSrc])
classDirectories.from = files([debugTree, kotlinDebugTree])
executionData.from = fileTree(dir: "$buildDir", includes: [
"jacoco/testDebugUnitTest.exec"
])
}
39 changes: 39 additions & 0 deletions iterableapi/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'checkstyle'
apply plugin: 'jacoco'

android {
compileSdk 34
Expand Down Expand Up @@ -118,4 +119,42 @@ afterEvaluate {
javadoc.classpath += files(android.libraryVariants.collect { variant -> variant.javaCompile.classpath.files })
javadoc.classpath += files(android.libraryVariants.collect { variant -> "build/generated/source/r/${variant.flavorName}/${variant.buildType.name}" })
javadoc.classpath += files(android.libraryVariants.collect { variant -> "build/generated/source/buildConfig/${variant.flavorName}/${variant.buildType.name}" })
}

tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
jacoco.excludes = ['jdk.internal.*']
}

task jacocoTestDebugUnitTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest']) {
group = "reporting"
description = "Generate Jacoco code coverage report"
reports {
xml.required = true
html.required = true
csv.required = false
}
def fileFilter = [
'**/*Test*.*',
'**/AutoValue_*.*',
'**/R.class',
'**/R$*.class',
'**/Manifest*.*',
'android/**/*.*',
'**/BuildConfig.*',
'**/Lambda$*.class',
'**/Lambda.class',
'**/*Lambda.class',
'**/*Lambda*.class'
]

def debugTree = fileTree(dir: "${buildDir}/intermediates/javac/debug/classes", excludes: fileFilter)
def kotlinDebugTree = fileTree(dir: "${buildDir}/tmp/kotlin-classes/debug", excludes: fileFilter)
def mainSrc = "${project.projectDir}/src/main/java"

sourceDirectories.from = files([mainSrc])
classDirectories.from = files([debugTree, kotlinDebugTree])
executionData.from = fileTree(dir: "$buildDir", includes: [
"jacoco/testDebugUnitTest.exec"
])
}
Loading