Skip to content

Commit

Permalink
[ANCHOR-413] Add jacoco test report to PR workflow (#1062)
Browse files Browse the repository at this point in the history
### Description

This is to add jacococ test report to PR workflow, to monitor test
coverage change

### Testing

After PR being published, there should be a github-action bot comment in
your PR with test coverage.

Please see
#1081 (comment)
for example.
Note that this PR is published from a branch on original repo instead of
a forked repo.

### Known limitations

1. For now Github only grant apps write permission (which is needed to
make comment) to original repo, and read permission to forked repo, that
mean this action will only works on PR created from original repo. I
have created a ticket https://stellarorg.atlassian.net/browse/ANCHOR-433
to follow up on this and try to find a work around for forked repo
For more info about github permission please refer to
https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token

2. Currently the min-coverage-overall is set to 40 and
min-coverage-changed-files is 60, this is just for testing, will be
changed accordingly.

---------

Co-authored-by: Reece Markowsky <[email protected]>
Co-authored-by: Philip Liu <[email protected]>
  • Loading branch information
3 people authored Sep 5, 2023
1 parent d39481d commit 8463b4b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
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:
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
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" }

0 comments on commit 8463b4b

Please sign in to comment.