Skip to content
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

[ANCHOR-413] Add jacoco test report to PR workflow #1062

Merged
merged 8 commits into from
Sep 5, 2023
Merged
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
17 changes: 16 additions & 1 deletion .github/workflows/sub_gradle_test_and_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ jobs:
gradle_test_and_build:
name: Gradle Test and Build
runs-on: ubuntu-22.04
# write to PR permission is required for jacocoTestReport Action to update comment
permissions:
JiahuiWho marked this conversation as resolved.
Show resolved Hide resolved
contents: read
pull-requests: write
steps:
# Checkout the code
- uses: actions/checkout@v3
Expand Down Expand Up @@ -51,7 +55,18 @@ jobs:
- name: Gradle test and build. (unit tests, integration tests, end-2-end tests and build)
env:
run_docker: false
run: ./gradlew clean build --no-daemon --stacktrace -x spotlessApply -x spotlessKotlinApply -x javadoc -x javadocJar -x sourcesJar
run: ./gradlew clean build jacocoTestReport --no-daemon --stacktrace -x spotlessApply -x spotlessKotlinApply -x javadoc -x javadocJar -x sourcesJar

- name: Add coverage to PR
id: jacoco
uses: madrapps/[email protected]
with:
paths: ${{ github.workspace }}/**/build/reports/jacoco/test/jacocoTestReport.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 40
min-coverage-changed-files: 60
Comment on lines +66 to +67
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this check be moved into the gradle build instead? That way, the developer can get feedback locally without publishing a PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, do we want to set coverage minimums by project? I think it would make sense to have the core project require higher coverage than the reference server, for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this check be moved into the gradle build instead? That way, the developer can get feedback locally without publishing a PR.

Yes The JacocoCoverageVerification task can be used to verify if code coverage metrics are met based on configured rules. However the build fails if any of the configured rules are not met and JaCoCo only reports the first violated rule. I will gradually implemented in the following PR.

Right now you can simply run jacocoTestReport in local to get an report but without the delta.

Also, do we want to set coverage minimums by project? I think it would make sense to have the core project require higher coverage than the reference server, for example.

I think that's part of the first question where we want enforce more granular test coverage rules.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes The JacocoCoverageVerification task can be used to verify if code coverage metrics are met based on configured rules. However the build fails if any of the configured rules are not met and JaCoCo only reports the first violated rule. I will gradually implemented in the following PR.

So once we enable JacocoCoverageVerification, do we still want to set min-coverage-overall and min-coverage-changed-files in the Github action?

title: Code Coverage
update-comment: true

- name: Stop docker containers
env:
Expand Down
11 changes: 11 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {
java
alias(libs.plugins.spotless)
alias(libs.plugins.kotlin.jvm) apply false
jacoco
}

tasks {
Expand All @@ -25,6 +26,7 @@ tasks {
subprojects {
apply(plugin = "java")
apply(plugin = "com.diffplug.spotless")
apply(plugin = "jacoco")

repositories {
mavenLocal()
Expand Down Expand Up @@ -62,6 +64,15 @@ subprojects {
}

kotlin { ktfmt("0.42").googleStyle() }

tasks.jacocoTestReport {
dependsOn(tasks.test) // tests are required to run before generating the report
reports {
xml.required.set(true)
csv.required.set(false)
html.required.set(true)
}
}
}

dependencies {
Expand Down
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ toml4j = "0.7.2"
spotless = "6.9.1"
spring-boot = "2.7.9"
spring-dependency-management = "1.1.0"
jacoco = "0.8.10"

[libraries]
abdera = { module = "org.apache.abdera:abdera-i18n", version.ref = "abdera" }
Expand Down Expand Up @@ -158,4 +159,5 @@ spring-boot = { id = "org.springframework.boot", version.ref = "spring-boot" }
spring-dependency-management = { id = "io.spring.dependency-management", version.ref = "spring-dependency-management" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
ktor = { id = "io.ktor.plugin", version.ref = "ktor" }
ktor = { id = "io.ktor.plugin", version.ref = "ktor" }
jacoco = { id = "jacoco", version.ref = "jacoco" }
Loading