From 89c3a524d3dad261a7d0acab953054e544376b25 Mon Sep 17 00:00:00 2001 From: "Kenneth J. Shackleton" Date: Fri, 15 Sep 2023 20:13:34 +0100 Subject: [PATCH] Publish coverage to SonarCloud. Signed-off-by: Kenneth J. Shackleton --- .github/workflows/continuous-integration.yml | 4 +++- build.gradle.kts | 19 +++++++++++++++++++ buildSrc/src/main/kotlin/Versions.kt | 3 ++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index b69f2ac3f4..6ac0dcd02e 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -60,7 +60,7 @@ jobs: path: | **/build/reports/detekt - name: 'Unit tests' - run: ./gradlew :selekt-android:testDebugUnitTest :selekt-java:test :koverHtmlReport -x integrationTest ${{ env.SCAN }} + run: ./gradlew :selekt-android:testDebugUnitTest :selekt-java:test :koverHtmlReport :koverXmlReport -x integrationTest ${{ env.SCAN }} - uses: actions/upload-artifact@v3 if: always() with: @@ -69,6 +69,8 @@ jobs: build/reports/kover/html selekt-android/build/reports/tests/testDebugUnitTest selekt-java/build/reports/tests/test + - name: 'Publish coverage' + run: ./gradlew :sonar -Dsonar.host.url=https://sonarcloud.io - name: 'Build Selekt' run: | ./gradlew assembleRelease ${{ env.SCAN }} diff --git a/build.gradle.kts b/build.gradle.kts index 5a03d021ca..a8af729eb0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -31,6 +31,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jlleitschuh.gradle.ktlint.KtlintExtension import org.jlleitschuh.gradle.ktlint.reporter.ReporterType import org.jlleitschuh.gradle.ktlint.tasks.GenerateReportsTask +import org.sonarqube.gradle.SonarTask plugins { base @@ -41,6 +42,7 @@ plugins { id("org.jetbrains.qodana") version Versions.QODANA_PLUGIN.version id("org.jlleitschuh.gradle.ktlint") version Versions.KTLINT_GRADLE_PLUGIN.version id("org.jetbrains.gradle.plugin.idea-ext") version Versions.IDE_EXT_GRADLE_PLUGIN.version + id("org.sonarqube") version Versions.SONAR.version } repositories { @@ -217,6 +219,23 @@ allprojects { } } +sonar { + properties { + property("sonar.organization", "Bloomberg") + property("sonar.projectKey", "com.bloomberg.selekt") + property("sonar.projectName", "Selekt") + property("sonar.projectVersion", selektVersionName) + property( + "sonar.coverage.jacoco.xmlReportPaths", + "${layout.buildDirectory.get()}/reports/kover/report.xml" + ) + } +} + +tasks.withType().configureEach { + mustRunAfter("koverXmlReport") +} + koverReport { defaults { filters { diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index c00cf2c37e..aad290a783 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -48,7 +48,8 @@ enum class Versions( MOCKITO_KOTLIN("5.0.0", URL("https://github.com/mockito/mockito-kotlin")), NEXUS_PLUGIN("1.3.0", URL("https://github.com/gradle-nexus/publish-plugin")), QODANA_PLUGIN("0.1.12", URL("https://www.jetbrains.com/help/qodana/qodana-gradle-plugin.html")), - ROBOLECTRIC_ANDROID_ALL("12.1-robolectric-8229987", URL("https://github.com/robolectric/robolectric")); + ROBOLECTRIC_ANDROID_ALL("12.1-robolectric-8229987", URL("https://github.com/robolectric/robolectric")), + SONAR("4.0.0.2929", URL("https://docs.sonarsource.com/sonarqube/latest")); override fun toString() = version