diff --git a/.github/workflows/sonar_cloud.yaml b/.github/workflows/sonar_cloud.yaml new file mode 100644 index 00000000..3ebd890e --- /dev/null +++ b/.github/workflows/sonar_cloud.yaml @@ -0,0 +1,46 @@ +name: SonarCloud + +on: + push: + branches: + - develop + pull_request: + types: [opened, synchronize, reopened] + +jobs: + build: + name: Build and analyze + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: corretto + + - name: Cache SonarCloud packages + uses: actions/cache@v3 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + + - name: Cache Gradle packages + uses: actions/cache@v3 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} + + - name: Grant execute permission for gradlew + run: chmod +x ./gradlew + + - name: Build And analyze Http Server + env: + GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: ./gradlew clean test jacocoTestReport sonar --info diff --git a/build.gradle.kts b/build.gradle.kts index 0b073e07..4c42fd31 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,6 +2,7 @@ plugins { id("jacoco") id("jacoco-report-aggregation") id("java-test-fixtures") + id(libs.plugins.sonarqube.get().pluginId) version libs.plugins.sonarqube.get().version.toString() id(libs.plugins.spring.boot.get().pluginId) version libs.plugins.spring.boot.get().version.toString() id(libs.plugins.spring.dependency.management.get().pluginId) version libs.plugins.spring.dependency.management.get().version.toString() id(libs.plugins.kotlin.jvm.get().pluginId) version libs.plugins.kotlin.jvm.get().version.toString() @@ -19,7 +20,9 @@ allprojects { } subprojects { + apply(plugin = "jacoco") apply(plugin = "java-test-fixtures") + apply(plugin = "org.sonarqube") apply(plugin = rootProject.libs.plugins.kotlin.jvm.get().pluginId) apply(plugin = rootProject.libs.plugins.kotlin.jpa.get().pluginId) apply(plugin = rootProject.libs.plugins.kotlin.spring.get().pluginId) @@ -64,3 +67,31 @@ subprojects { useJUnitPlatform() } } + +sonar { + properties { + property("sonar.projectKey", "3IDLES_idle-server") + property("sonar.organization", "3idles") + property("sonar.host.url", "https://sonarcloud.io") + property("sonar.java.coveragePlugin", "jacoco") + } +} + +val allProjects = project.allprojects + .asSequence() + .filter { it.name != "idle-server" } + .filter { it.name != "idle-support" } + .filter { it.name != "idle-domain" } + .filter { it.name != "idle-infrastructure" } + .filter { it.name != "idle-api" } + .toList() + +project(":idle-support:jacoco") { + apply(plugin = "jacoco-report-aggregation") + + dependencies { + allProjects.forEach { + add("jacocoAggregation", project(it.path)) + } + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b6206c82..66edafae 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -4,6 +4,7 @@ java = "17" spring-boot = "3.3.0" spring-boot-dependency-management = "1.1.4" kotlin = "1.9.21" +sonar-cloud = "4.4.1.3373" mockk = "1.13.7" spring-mockk = "4.0.2" @@ -39,6 +40,8 @@ kotest-extensions-testcontainers = { group = "io.kotest.extensions", name = "kot testcontainers-junit-jupiter = { group = "org.testcontainers", name = "junit-jupiter", version.ref = "testcontainers" } [plugins] + +sonarqube = { id = "org.sonarqube", version.ref = "sonar-cloud" } spring-boot = { id = "org.springframework.boot", version.ref = "spring-boot" } spring-dependency-management = { id = "io.spring.dependency-management", version.ref = "spring-boot-dependency-management" } kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } diff --git a/idle-support/jacoco/build.gradle.kts b/idle-support/jacoco/build.gradle.kts new file mode 100644 index 00000000..2e3ca6ab --- /dev/null +++ b/idle-support/jacoco/build.gradle.kts @@ -0,0 +1,3 @@ +dependencies { + +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 55fb05cd..fcd1fbd5 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -5,5 +5,6 @@ include( "idle-domain", "idle-infrastructure", "idle-support:common", - "idle-support:logging" + "idle-support:logging", + "idle-support:jacoco" )