Skip to content

Commit

Permalink
add jacoco action
Browse files Browse the repository at this point in the history
  • Loading branch information
JiahuiWho committed Aug 28, 2023
1 parent 6222445 commit 9bf2340
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/sub_jacoco_coverage_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Jacoco Coverage Report

on:
workflow_dispatch:
workflow_call:

jobs:
jacoco_coverage_report:
name: Jacoco Coverage Report
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'adopt'

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Run Coverage
run: ./gradlew jacocoTestReport

- 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: Get the Coverage info
run: |
echo "Total coverage ${{ steps.jacoco.outputs.coverage-overall }}"
echo "Changed Files coverage ${{ steps.jacoco.outputs.coverage-changed-files }}"
9 changes: 6 additions & 3 deletions .github/workflows/wf_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ on:
pull_request:

jobs:
gradle_test_and_build:
uses: ./.github/workflows/sub_gradle_test_and_build.yml
# gradle_test_and_build:
# uses: ./.github/workflows/sub_gradle_test_and_build.yml

jacoco_coverage_report:
uses: ./.github/workflows/sub_jacoco_coverage_report.yml

complete:
if: always()
needs: [gradle_test_and_build]
needs: [jacoco_coverage_report]
runs-on: ubuntu-22.04
steps:
- if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
Expand Down
12 changes: 12 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 All @@ -36,6 +38,7 @@ subprojects {

/** Specifies JDK-11 */
java { toolchain { languageVersion.set(JavaLanguageVersion.of(11)) } }
jacoco { toolVersion = "0.8.10" }

spotless {
val javaVersion = System.getProperty("java.version")
Expand All @@ -62,6 +65,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(false)
}
}
}

dependencies {
Expand Down

0 comments on commit 9bf2340

Please sign in to comment.