From acf0d145a778c58de09bba13d4e5b96248b409c4 Mon Sep 17 00:00:00 2001 From: Jeffrey Mello Date: Tue, 18 Nov 2025 12:30:23 -0500 Subject: [PATCH 1/2] Add JaCoCo coverage reporting to CI workflow Integrates JaCoCo test coverage reporting into the GitHub Actions workflow and build configuration. Adds tasks for generating coverage reports, configures filtering and inclusion of specific classes, and uploads the coverage report as an artifact. --- .github/workflows/gradle.yml | 10 ++++++ TeamCode/build.gradle | 68 ++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 3bd520a..0bbb834 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -38,6 +38,10 @@ jobs: - name: Run unit tests run: ./gradlew :TeamCode:testReleaseUnitTest --no-daemon --stacktrace + - name: Run JaCoCo + run: + ./gradlew :TeamCode:jacocoTestReport + - name: Build Release APK run: ./gradlew assembleRelease --no-daemon --stacktrace @@ -48,6 +52,12 @@ jobs: name: test-report-debug path: TeamCode/build/reports/tests/testDebugUnitTest + - name: Upload JaCoCo Report + uses: actions/upload-artifact@v4 + with: + name: Upload JaCoCo Report + path: build/reports/jacoco/jacocoTestReport/**/* + - name: Upload Release APK uses: actions/upload-artifact@v4 with: diff --git a/TeamCode/build.gradle b/TeamCode/build.gradle index d4dbfd4..4a768e4 100644 --- a/TeamCode/build.gradle +++ b/TeamCode/build.gradle @@ -3,6 +3,7 @@ apply from: '../build.dependencies.gradle' apply plugin: 'de.mannodermaus.android-junit5' apply plugin: 'jacoco' + android { namespace = 'org.firstinspires.ftc.teamcode' @@ -19,6 +20,73 @@ jacoco { toolVersion = "0.8.10" } +tasks.register("testWithCoverage") { + dependsOn("testDebugUnitTest", "jacocoTestReport") +} + +tasks.withType(Test).configureEach { + jacoco.includeNoLocationClasses = true + jacoco.excludes = [ + 'jdk.internal.*' + ] +} + +tasks.register("jacocoTestReport", JacocoReport) { + // You are running debug unit tests + def variant = "debug" + def testVariant = "debugUnitTest" + + dependsOn "test${testVariant.capitalize()}" + + reports { + xml.required = true + html.required = true + } + + def allowedClasses = files( + "$buildDir/intermediates/javac/release/compileReleaseJavaWithJavac/classes/org/firstinspires/ftc/teamcode/TeleOpMain.class", + "$buildDir/intermediates/javac/release/compileReleaseJavaWithJavac/classes/org/firstinspires/ftc/teamcode/TeleOpMain\$*.class", + + "$buildDir/intermediates/javac/release/compileReleaseJavaWithJavac/classes/org/firstinspires/ftc/teamcode/AutoMain.class", + "$buildDir/intermediates/javac/release/compileReleaseJavaWithJavac/classes/org/firstinspires/ftc/teamcode/AutoMain\$*.class", + + "$buildDir/intermediates/javac/release/compileReleaseJavaWithJavac/classes/org/firstinspires/ftc/teamcode/Utils_13233" + ) + + + def fileFilter = [ + '**/R.class', '**/R$*.class', '**/BuildConfig.*', + '**/Manifest*.*', 'android/**/*.*', + '**/org/firstinspires/ftc/teamcode/tuning/**', + '**/org/firstinspires/ftc/teamcode/**', + ] + + + // Main (non-test) code classes + def mainClasses = fileTree( + dir: "$buildDir/intermediates/javac/${variant}/compile${variant.capitalize()}JavaWithJavac/classes", + excludes: fileFilter + ) + + classDirectories.setFrom( + files([ + mainClasses, // everything minus excluded dirs + allowedClasses // add back specific classes + ]) + ) + + + sourceDirectories.setFrom(files([ + "src/main/java" + ])) + + executionData.setFrom(fileTree( + dir: buildDir, + includes: ["jacoco/test${testVariant.capitalize()}.exec"] + )) +} + + repositories { maven { url = 'https://maven.brott.dev/' From 722499cff1af36a042294976e7a99c4963f179a1 Mon Sep 17 00:00:00 2001 From: Jeffrey Mello Date: Tue, 18 Nov 2025 12:34:46 -0500 Subject: [PATCH 2/2] Update JaCoCo report upload path in CI workflow Changed the artifact upload path for the JaCoCo report to use the TeamCode directory in the Gradle GitHub Actions workflow. This ensures the correct report files are uploaded from the intended build location. --- .github/workflows/gradle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 0bbb834..2714a3d 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -56,7 +56,7 @@ jobs: uses: actions/upload-artifact@v4 with: name: Upload JaCoCo Report - path: build/reports/jacoco/jacocoTestReport/**/* + path: TeamCode/build/reports/jacoco/jacocoTestReport/**/* - name: Upload Release APK uses: actions/upload-artifact@v4