Skip to content

Commit e40fec1

Browse files
authored
Merge pull request #9 from build-extensions-oss/coverage
Add code coverage
2 parents 04923ec + a37a15b commit e40fec1

File tree

5 files changed

+62
-2
lines changed

5 files changed

+62
-2
lines changed

.github/workflows/pre-merge.yaml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ on:
1111

1212
permissions:
1313
contents: read
14+
# kover-report action needs updating the PR report
15+
pull-requests: write
1416

1517
jobs:
1618
gradle:
1719
strategy:
20+
# don't fail immediately - otherwise failing build on Windows will cancel all other builds
21+
fail-fast: false
1822
matrix:
1923
# build project on some operating systems
20-
os: [ubuntu-latest, windows-latest, macos-latest]
24+
os: [ ubuntu-latest, windows-latest, macos-latest ]
2125
# build on different java versions
2226
jdk: [ 11, 17, 21 ]
2327
runs-on: ${{ matrix.os }}
@@ -53,3 +57,22 @@ jobs:
5357
# No need to use daemon (this is run once container), however we print detailed logs and stacktraces
5458
- name: Assemble the project
5559
run: ./gradlew build --stacktrace --info --no-daemon
60+
61+
- name: Generate kover coverage report
62+
run: ./gradlew koverXmlReport
63+
64+
# see https://github.com/marketplace/actions/kotlinx-kover-report
65+
- name: Add coverage report to PR
66+
id: kover
67+
uses: mi-kas/kover-report@v1
68+
with:
69+
# we aggregate everything in root project
70+
path: ${{ github.workspace }}/build/reports/kover/report.xml
71+
title: Code Coverage
72+
update-comment: true
73+
# We check that in root project - no need to repeat it once again
74+
# min-coverage-overall: ???
75+
# we can't validate this in Gradle - the report must do this on GitHub
76+
# We aren't ready yet
77+
# min-coverage-changed-files: 80
78+
coverage-counter-type: LINE

build.gradle.kts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
plugins {
2+
base
3+
// is defined in buildSrc
4+
id("org.jetbrains.kotlinx.kover")
5+
}
6+
7+
dependencies {
8+
subprojects.forEach {
9+
val projectName = it.name
10+
11+
// depend on all projects
12+
if (projectName != "bom") {
13+
kover(project(":${it.name}")) {}
14+
}
15+
}
16+
}
17+
18+
tasks {
19+
this.getByName("build") {
20+
// prohibit building without verification
21+
dependsOn(getByName("koverCachedVerify"))
22+
}
23+
}
24+
25+
kover.reports {
26+
verify {
27+
rule {
28+
bound {
29+
minValue.set(14)
30+
}
31+
}
32+
}
33+
}

buildSrc/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ repositories {
99
dependencies {
1010
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:${embeddedKotlinVersion}")
1111
implementation(libs.com.vanniktech.maven.publish.gradle.plugin)
12+
implementation(libs.org.jetbrains.kotlinx.kover)
1213
}

buildSrc/src/main/kotlin/kotlin-convention.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ plugins {
66
kotlin("jvm")
77
id("dependencies-lock")
88
id("dependencies-publishing")
9+
id("org.jetbrains.kotlinx.kover")
910
}
1011

1112
repositories {

gradle/libs.versions.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ reflections = { module = "org.reflections:reflections", version.ref = "reflectio
2121

2222
spek-dsl = { module = "org.spekframework.spek2:spek-dsl", version.ref = "spek2" }
2323

24+
org-jetbrains-kotlinx-kover = { module = "org.jetbrains.kotlinx:kover-gradle-plugin", version = "0.9.3" }
25+
2426
# this plugin is referenced in buildSrc
2527
com-vanniktech-maven-publish-gradle-plugin = { module = "com.vanniktech.maven.publish:com.vanniktech.maven.publish.gradle.plugin", version = "0.34.0" }
2628

27-
[plugins]
29+
[plugins]

0 commit comments

Comments
 (0)