Skip to content

Commit a4fc0eb

Browse files
committed
Integrate jacoco report
1 parent 8ee14c8 commit a4fc0eb

File tree

4 files changed

+62
-4
lines changed

4 files changed

+62
-4
lines changed

.github/workflows/BuildTest.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ on:
1010
pull_request:
1111
branches:
1212
- 'staging'
13-
1413
jobs:
1514
build_test:
1615
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
pull-requests: write
1719
steps:
1820
- name: Checkout code
1921
uses: actions/checkout@v4
@@ -68,10 +70,25 @@ jobs:
6870
path: lib/build/test-results/testDebugUnitTest
6971

7072
- name: Run Lib Compose Unit Test
71-
run: ./gradlew lib-compose:testDebugUnitTest
73+
run: ./gradlew lib-compose:jacocoTestReport
7274

7375
- name: Upload Lib Compose Test Results
7476
uses: actions/upload-artifact@v4
7577
with:
7678
name: lib-compose-test-results
77-
path: lib-compose/build/test-results/testDebugUnitTest
79+
path: lib-compose/build/reports/jacoco/jacocoTestReport
80+
81+
- name: Jacoco Report to PR
82+
if: github.event.pull_request.base.ref == 'epic/**'
83+
id: jacoco
84+
uses: madrapps/[email protected]
85+
with:
86+
paths: ${{ github.workspace }}/**/build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml
87+
token: ${{ secrets.GITHUB_TOKEN }}
88+
min-coverage-overall: 40
89+
min-coverage-changed-files: 60
90+
title: ':lobster: Coverage Report'
91+
update-comment: true
92+
pass-emoji: ':green_square:'
93+
fail-emoji: ':red_square:'
94+
debug-mode: true

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ buildscript {
55
classpath(libs.ktlint.gradle)
66
classpath(libs.sonarqube.gradle.plugin)
77
classpath(libs.kotlin.gradle.plugin)
8+
classpath(libs.jacoco.core)
89
}
910
}
1011

gradle/libs.versions.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ junit4 = "4.13.2"
2121
mockk = "1.13.10"
2222
androidxCoreTesting = "1.6.1"
2323
androidArchCoreTesting = "2.2.0"
24+
jacocoVersion = "0.8.11"
2425

2526
#Compose
2627
androidxComposeBom = "2024.10.00"
@@ -66,6 +67,7 @@ androidx-core-testing = { module = "androidx.arch.core:core-testing", version.re
6667
junit4 = { group = "junit", name = "junit", version.ref = "junit4" }
6768
mockk = { group = "io.mockk", name = "mockk", version.ref = "mockk" }
6869
truth = { module = "com.google.truth:truth", version.ref = "truth" }
70+
jacoco-core = { module = "org.jacoco:org.jacoco.core", version.ref = "jacocoVersion" }
6971

7072
#Compose
7173
androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "androidxComposeBom" }
@@ -106,4 +108,5 @@ compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "
106108
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
107109
maven-publish = { id = "maven-publish" }
108110
signing = { id = "signing" }
109-
kotlin-parcelize = { id = "kotlin-parcelize" }
111+
kotlin-parcelize = { id = "kotlin-parcelize" }
112+
jacoco = { id = "jacoco" }

lib-compose/build.gradle.kts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ plugins {
88
alias(libs.plugins.dokka)
99
alias(libs.plugins.compose.compiler)
1010
id(libs.plugins.kotlin.parcelize.get().pluginId)
11+
id(libs.plugins.jacoco.get().pluginId)
1112
}
1213

1314
/**
@@ -38,6 +39,9 @@ android {
3839
"proguard-rules.pro"
3940
)
4041
}
42+
debug {
43+
enableUnitTestCoverage = true
44+
}
4145
}
4246
compileOptions {
4347
sourceCompatibility = JavaVersion.VERSION_1_8
@@ -59,6 +63,39 @@ android {
5963
}
6064
}
6165

66+
jacoco {
67+
toolVersion = libs.versions.jacocoVersion.get()
68+
}
69+
70+
tasks.register<JacocoReport>("jacocoTestReport") {
71+
dependsOn(tasks.withType<Test>().named("testDebugUnitTest"))
72+
73+
reports {
74+
xml.required.set(true)
75+
html.required.set(true)
76+
}
77+
78+
val fileFilter = listOf(
79+
"**/R.class",
80+
"**/R$*.class",
81+
"**/BuildConfig.*",
82+
"**/Manifest*.*"
83+
)
84+
85+
val javaTree = fileTree("${buildDir}/intermediates/javac/debug") {
86+
exclude(fileFilter)
87+
}
88+
val kotlinTree = fileTree("${buildDir}/tmp/kotlin-classes/debug") {
89+
exclude(fileFilter)
90+
}
91+
92+
sourceDirectories.setFrom(files("${project.projectDir}/src/main/java", "${project.projectDir}/src/main/kotlin"))
93+
classDirectories.setFrom(files(javaTree, kotlinTree))
94+
executionData.setFrom(fileTree("${buildDir}/outputs/unit_test_code_coverage/debugUnitTest").apply {
95+
include("testDebugUnitTest.exec")
96+
})
97+
}
98+
6299
tasks.register("checkSnapshotDependencies") {
63100
doLast {
64101
val snapshotDependencies = allprojects.flatMap { project ->

0 commit comments

Comments
 (0)