diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 438163a..75c2ff0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,6 +16,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + with: + fetch-depth: 0 - name: Set up JDK 21 uses: actions/setup-java@v5 with: @@ -31,6 +33,15 @@ jobs: - name: API Check run: ./gradlew apiCheck + - name: Generate Kover reports + run: ./gradlew koverXmlReport + + - name: Run SonarCloud Analysis + run: ./gradlew sonar + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + GIT_BRANCH: ${{ github.ref_name }} + publish: name: Publish needs: unit-test diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 7363b88..0fce22a 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -9,6 +9,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 + with: + fetch-depth: 0 - name: Set up JDK 21 uses: actions/setup-java@v5 with: @@ -24,6 +26,17 @@ jobs: - name: API Check run: ./gradlew apiCheck + - name: Generate Kover reports + run: ./gradlew koverXmlReport + + - name: Run SonarCloud Analysis + run: ./gradlew sonar + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + GIT_BRANCH: ${{ github.ref_name}} + GIT_BRANCH_DEST: ${{ github.base_ref }} + PULL_REQUEST: ${{ github.event.pull_request.number }} + publish: name: Publish needs: unit-test diff --git a/README.md b/README.md index 03bbb91..4db1a15 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ [![Maven Central](https://img.shields.io/maven-central/v/org.hisp.dhis.lib.expression/expression-parser?label=maven%20central)](https://central.sonatype.com/artifact/org.hisp.dhis.lib.expression/expression-parser) [![NPM Version](https://img.shields.io/npm/v/@dhis2/expression-parser)](https://www.npmjs.com/package/@dhis2/expression-parser) +[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=dhis2_expression-parser&metric=coverage&branch=main)](https://sonarcloud.io/summary/overall?id=dhis2_expression-parser&branch=main) [![KDoc link](https://img.shields.io/badge/API_reference-KDoc-blue)](https://dhis2.github.io/expression-parser/api/) # Expression Parser diff --git a/build.gradle.kts b/build.gradle.kts index 82945a6..7e3411e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,6 +3,8 @@ plugins { id("maven-publish-conventions") id("npm-publish-conventions") alias(libs.plugins.api.compatibility) + alias(libs.plugins.kover) + alias(libs.plugins.sonarqube) } repositories { @@ -80,3 +82,29 @@ kotlin { val nativeTest by getting } } + +sonarqube { + properties { + val branch = System.getenv("GIT_BRANCH") + val targetBranch = System.getenv("GIT_BRANCH_DEST") + val pullRequestId = System.getenv("PULL_REQUEST") + + property("sonar.host.url", "https://sonarcloud.io") + property("sonar.organization", "dhis2") + property("sonar.projectKey", "dhis2_expression-parser") + property("sonar.projectName", "expression-parser") + property("sonar.coverage.jacoco.xmlReportPaths", "${layout.buildDirectory.get()}/reports/kover/report.xml") + + if (pullRequestId.isNullOrEmpty()) { + property("sonar.branch.name", branch) + } else { + property("sonar.pullrequest.base", targetBranch) + property("sonar.pullrequest.branch", branch) + property("sonar.pullrequest.key", pullRequestId) + } + } +} + +tasks.named("sonar").configure { + dependsOn(":koverXmlReport") +} \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 56fea25..98d7efc 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -4,6 +4,8 @@ dokka = "2.0.0" nexusPublish = "2.0.0" npmPublish = "3.5.2" apiCompatibility ="0.17.0" +kover = "0.9.8" +sonarqube = "7.2.3.7755" kotlinxDatetime = "0.7.1" bignum = "0.3.10" kotlinJsWrappers = "1.0.0-pre.830" @@ -20,5 +22,7 @@ kotlinWrappers-js = { group = "org.jetbrains.kotlin-wrappers", name = "kotlin-js [plugins] api-compatibility = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "apiCompatibility" } +kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover" } +sonarqube = { id = "org.sonarqube", version.ref = "sonarqube" } [bundles]