From 3e8fef5567131224a615994b72d9071391c8ee00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Guillot?= Date: Tue, 22 Oct 2024 15:52:05 +0200 Subject: [PATCH] chore: fix JaCoCo report integration in SonarCloud (#233) * chore: update JaCoco settings to following Quarkus documentation and recommandations * chore: update Sonar settings with new JaCoCo report location * chore: run **all** tests on `main` branch --- .github/workflows/ci.yaml | 18 ++++++++++++------ apps/server/build.gradle.kts | 10 ---------- libs/server/domain/build.gradle.kts | 15 ++++++++------- libs/server/persistence/build.gradle.kts | 10 ---------- libs/server/storage/azure/build.gradle.kts | 10 ---------- libs/server/storage/core/build.gradle.kts | 10 ---------- libs/server/storage/gcs/build.gradle.kts | 10 ---------- libs/server/storage/s3/build.gradle.kts | 10 ---------- sonar-project.properties | 2 +- 9 files changed, 21 insertions(+), 74 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index dd760188..ca5cb6f0 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -80,16 +80,22 @@ jobs: - name: Setup build tools uses: ./.github/actions/setup-tools - - name: Run Test for affected projects + - name: Run Test for affected projects (PR) + if: github.ref != 'refs/heads/main' run: pnpm exec nx affected -t test env: NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }} -# - name: SonarCloud Scan -# uses: SonarSource/sonarcloud-github-action@eb211723266fe8e83102bac7361f0a05c3ac1d1b # v3.0.0 -# env: -# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} -# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + - name: Run Test for all projects (main) + if: github.ref == 'refs/heads/main' + run: pnpm exec nx run-many --target=test --all + env: + NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }} + + - name: SonarCloud Scan + uses: SonarSource/sonarcloud-github-action@383f7e52eae3ab0510c3cb0e7d9d150bbaeab838 # v3.1.0 + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} lint: runs-on: ubuntu-latest diff --git a/apps/server/build.gradle.kts b/apps/server/build.gradle.kts index 659884d5..b671eb31 100644 --- a/apps/server/build.gradle.kts +++ b/apps/server/build.gradle.kts @@ -5,7 +5,6 @@ plugins { kotlin("plugin.allopen") id("io.quarkus") id("com.diffplug.spotless") - id("jacoco") } repositories { @@ -69,15 +68,6 @@ java { tasks.withType { systemProperty("java.util.logging.manager", "org.jboss.logmanager.LogManager") - finalizedBy("jacocoTestReport") -} - -tasks.jacocoTestReport { - reports { - csv.required.set(false) - xml.required.set(true) - xml.outputLocation.set(layout.buildDirectory.file("reports/jacoco/jacoco.xml")) - } } allOpen { diff --git a/libs/server/domain/build.gradle.kts b/libs/server/domain/build.gradle.kts index cabf2aaa..bb0b003f 100644 --- a/libs/server/domain/build.gradle.kts +++ b/libs/server/domain/build.gradle.kts @@ -50,14 +50,15 @@ tasks.withType { tasks.withType { systemProperty("java.util.logging.manager", "org.jboss.logmanager.LogManager") - finalizedBy("jacocoTestReport") -} + finalizedBy(tasks.jacocoTestReport) + + configure { + excludeClassLoaders = listOf("*QuarkusClassLoader") + setDestinationFile(layout.buildDirectory.file("jacoco-quarkus.exec").get().asFile) + } -tasks.jacocoTestReport { - reports { - csv.required.set(false) - xml.required.set(true) - xml.outputLocation.set(layout.buildDirectory.file("reports/jacoco/jacoco.xml")) + tasks.jacocoTestReport { + enabled = false } } diff --git a/libs/server/persistence/build.gradle.kts b/libs/server/persistence/build.gradle.kts index 28574ff2..b79572f4 100644 --- a/libs/server/persistence/build.gradle.kts +++ b/libs/server/persistence/build.gradle.kts @@ -6,7 +6,6 @@ plugins { kotlin("plugin.noarg") id("io.quarkus") id("com.diffplug.spotless") - id("jacoco") } repositories { @@ -53,15 +52,6 @@ tasks.withType { tasks.withType { systemProperty("java.util.logging.manager", "org.jboss.logmanager.LogManager") - finalizedBy("jacocoTestReport") -} - -tasks.jacocoTestReport { - reports { - csv.required.set(false) - xml.required.set(true) - xml.outputLocation.set(layout.buildDirectory.file("reports/jacoco/jacoco.xml")) - } } allOpen { diff --git a/libs/server/storage/azure/build.gradle.kts b/libs/server/storage/azure/build.gradle.kts index b9a3e822..04f43d9f 100644 --- a/libs/server/storage/azure/build.gradle.kts +++ b/libs/server/storage/azure/build.gradle.kts @@ -5,7 +5,6 @@ plugins { kotlin("plugin.allopen") id("io.quarkus") id("com.diffplug.spotless") - id("jacoco") } repositories { @@ -57,15 +56,6 @@ tasks.withType { tasks.withType { systemProperty("java.util.logging.manager", "org.jboss.logmanager.LogManager") - finalizedBy("jacocoTestReport") -} - -tasks.jacocoTestReport { - reports { - csv.required.set(false) - xml.required.set(true) - xml.outputLocation.set(layout.buildDirectory.file("reports/jacoco/jacoco.xml")) - } } allOpen { diff --git a/libs/server/storage/core/build.gradle.kts b/libs/server/storage/core/build.gradle.kts index 72db446e..31a9f01f 100644 --- a/libs/server/storage/core/build.gradle.kts +++ b/libs/server/storage/core/build.gradle.kts @@ -5,7 +5,6 @@ plugins { kotlin("plugin.allopen") id("io.quarkus") id("com.diffplug.spotless") - id("jacoco") } repositories { @@ -48,15 +47,6 @@ tasks.withType { tasks.withType { systemProperty("java.util.logging.manager", "org.jboss.logmanager.LogManager") - finalizedBy("jacocoTestReport") -} - -tasks.jacocoTestReport { - reports { - csv.required.set(false) - xml.required.set(true) - xml.outputLocation.set(layout.buildDirectory.file("reports/jacoco/jacoco.xml")) - } } allOpen { diff --git a/libs/server/storage/gcs/build.gradle.kts b/libs/server/storage/gcs/build.gradle.kts index bcf2ae56..4010a4a2 100644 --- a/libs/server/storage/gcs/build.gradle.kts +++ b/libs/server/storage/gcs/build.gradle.kts @@ -5,7 +5,6 @@ plugins { kotlin("plugin.allopen") id("io.quarkus") id("com.diffplug.spotless") - id("jacoco") } repositories { @@ -55,15 +54,6 @@ tasks.withType { tasks.withType { systemProperty("java.util.logging.manager", "org.jboss.logmanager.LogManager") - finalizedBy("jacocoTestReport") -} - -tasks.jacocoTestReport { - reports { - csv.required.set(false) - xml.required.set(true) - xml.outputLocation.set(layout.buildDirectory.file("reports/jacoco/jacoco.xml")) - } } allOpen { diff --git a/libs/server/storage/s3/build.gradle.kts b/libs/server/storage/s3/build.gradle.kts index ea540a27..f4ccc191 100644 --- a/libs/server/storage/s3/build.gradle.kts +++ b/libs/server/storage/s3/build.gradle.kts @@ -5,7 +5,6 @@ plugins { kotlin("plugin.allopen") id("io.quarkus") id("com.diffplug.spotless") - id("jacoco") } repositories { @@ -54,15 +53,6 @@ tasks.withType { tasks.withType { systemProperty("java.util.logging.manager", "org.jboss.logmanager.LogManager") - finalizedBy("jacocoTestReport") -} - -tasks.jacocoTestReport { - reports { - csv.required.set(false) - xml.required.set(true) - xml.outputLocation.set(layout.buildDirectory.file("reports/jacoco/jacoco.xml")) - } } allOpen { diff --git a/sonar-project.properties b/sonar-project.properties index c514a28c..61689ea7 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,5 +1,5 @@ sonar.projectKey=clementguillot_nx-cloud-ce sonar.organization=clementguillot sonar.kotlin.source.version=2.0 -sonar.coverage.jacoco.xmlReportPaths=**/build/reports/jacoco/jacoco.xml +sonar.coverage.jacoco.xmlReportPaths=**/build/jacoco-report/jacoco.xml sonar.test.inclusions=**/src/test/kotlin/**/*.kt