From 578827ac21907b3751fddf4a191a19b72b794bda Mon Sep 17 00:00:00 2001 From: Gabriel Fleischer Date: Mon, 11 Mar 2024 20:05:22 +0100 Subject: [PATCH] Add Sonar --- .github/workflows/ci.yml | 9 ++++++++- app/build.gradle.kts | 16 ++++++++++++++++ gradle/libs.versions.toml | 2 ++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4e2d4ce..e1b81b2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -101,4 +101,11 @@ jobs: # This step generates the coverage report which will be uploaded to sonar - name: Generate coverage run: | - ./gradlew jacocoTestReport \ No newline at end of file + ./gradlew jacocoTestReport + + # Upload the various reports to sonar + - name: Upload report to SonarCloud + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: ./gradlew sonar --info --parallel --build-cache \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts index ab3f89f..6627587 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -2,6 +2,7 @@ plugins { alias(libs.plugins.androidApplication) alias(libs.plugins.jetbrainsKotlinAndroid) alias(libs.plugins.ktfmt) + alias(libs.plugins.sonar) id("jacoco") } @@ -90,6 +91,21 @@ android { } } +sonar { + properties { + property("sonar.projectKey", "gf_android-sample") + property("sonar.projectName", "Android-Sample") + property("sonar.organization", "gabrielfleischer") + property("sonar.host.url", "https://sonarcloud.io") + // Comma-separated paths to the various directories containing the *.xml JUnit report files. Each path may be absolute or relative to the project base directory. + property("sonar.junit.reportPaths", "${project.layout.buildDirectory.get()}/test-results/testDebugunitTest/") + // Paths to xml files with Android Lint issues. If the main flavor is changed, this file will have to be changed too. + property("sonar.androidLint.reportPaths", "${project.layout.buildDirectory.get()}/reports/lint-results-debug.xml") + // Paths to JaCoCo XML coverage report files. + property("sonar.coverage.jacoco.xmlReportPaths", "${project.layout.buildDirectory.get()}/reports/jacoco/jacocoTestReport/jacocoTestReport.xml") + } +} + // When a library is used both by robolectric and connected tests, use this function fun DependencyHandlerScope.globalTestImplementation(dep: Any) { androidTestImplementation(dep) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d1b7174..a976b61 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -14,6 +14,7 @@ composeViewModel = "2.7.0" lifecycleRuntimeKtx = "2.7.0" kaspresso = "1.5.5" robolectric = "4.11.1" +sonar = "4.4.1.3373" [libraries] androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } @@ -44,3 +45,4 @@ robolectric = { module = "org.robolectric:robolectric", version.ref = "robolectr androidApplication = { id = "com.android.application", version.ref = "agp" } jetbrainsKotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } ktfmt = { id = "com.ncorti.ktfmt.gradle", version.ref = "ktfmt" } +sonar = { id = "org.sonarqube", version.ref = "sonar" }