Skip to content

Commit

Permalink
JaCoCo was added to github actions - now it shows the high-level code…
Browse files Browse the repository at this point in the history
… coverage my tests
  • Loading branch information
Vest authored Jan 31, 2025
1 parent 198ca33 commit e06d5b4
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 9 deletions.
40 changes: 33 additions & 7 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
name: Build PCGen with Gradle

on:
push:
branches: [ "gh_build" ] # use the current branch for testing purposes only
pull_request:
branches: [ "master" ]

jobs:
build:
Expand Down Expand Up @@ -45,14 +42,18 @@ jobs:
- uses: actions/cache@v4
with:
path: |
build/classes
build/jre
${{ github.workspace }}/build/jre
${{ github.workspace }}/build/libs
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
${{ runner.os }}-gradle
- name: Build with Gradle Wrapper
run: ./gradlew build test slowtest
run: ./gradlew build

- name: Run tests
run: ./gradlew test itest datatest slowtest

- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
Expand All @@ -63,6 +64,31 @@ jobs:
build/test-results/**/*.trx
build/test-results/**/*.json
- name: Run Coverage
run: ./gradlew testCoverage

- name: Upload Report to artifacts
uses: actions/upload-artifact@v4
with:
name: testCoverage
path: ${{ github.workspace }}/build/reports/jacoco/testCoverage/html

- name: Jacoco Report to PR
id: jacoco
uses: madrapps/[email protected]
with:
paths: |
${{ github.workspace }}/build/reports/jacoco/testCoverage/testCoverage.xml
token: ${{ secrets.GITHUB_TOKEN }}
title: '## :construction: PCGen Code Coverage'
update-comment: true
debug-mode: false

- name: Get the Coverage info
run: |
echo "Total coverage ${{ steps.jacoco.outputs.coverage-overall }}"
echo "Changed Files coverage ${{ steps.jacoco.outputs.coverage-changed-files }}"
# - name: Upload build artifacts
# uses: actions/upload-artifact@v4
# with:
Expand Down
24 changes: 22 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ plugins {
id 'com.dorongold.task-tree' version '4.0.0' // Prints the task dependency tree
id 'org.openjfx.javafxplugin' version '0.1.0' // JavaFX support
id 'org.beryx.runtime' version '1.13.1' // Creates custom runtimes
id 'jacoco' // Code coverage
}

/**
Expand All @@ -47,6 +48,10 @@ javafx {
modules = [ 'javafx.controls', 'javafx.web', 'javafx.swing', 'javafx.fxml', 'javafx.graphics' ]
}

jacoco {
toolVersion = '0.8.12'
}

// Set the groupId as it helps with Maven
group = 'net.sourceforge.pcgen'

Expand Down Expand Up @@ -750,8 +755,23 @@ tasks.named("jre") {
dependsOn downloadJRE, downloadJavaFXModules
}

tasks.withType(Test) {
testLogging.showStandardStreams = false
tasks.register("testCoverage", JacocoReport) {
dependsOn test
group = "Reporting"
description = "Generate Jacoco coverage reports for the test build."

reports {
html.required.set(true)
xml.required.set(true)
}

classDirectories.from = fileTree(dir: layout.buildDirectory.dir("classes/java/main"))

sourceDirectories.from = files([
"$project.projectDir/code/src/java"
])

executionData.from = fileTree(dir: layout.buildDirectory.dir("jacoco")).include("*.exec")
}

tasks.named("test", Test) {
Expand Down

0 comments on commit e06d5b4

Please sign in to comment.