diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 050ab36..f7b85c7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,14 @@ name: Java CI Pipeline on: push: branches: - - "**" + - main + - staging + - dev + pull_request: + branches: + - main + - staging + - dev workflow_dispatch: jobs: @@ -28,8 +35,10 @@ jobs: key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} restore-keys: | ${{ runner.os }}-gradle- + - name: Make gradlew executable run: chmod +x ./gradlew + - name: Build with Gradle run: | ./gradlew assemble @@ -84,4 +93,9 @@ jobs: ./gradlew jacocoTestReport env: PRODUCTION: test - # (Optional) Add steps for generating coverage report and other post-test tasks \ No newline at end of file + # (Optional) Add steps for generating coverage report and other post-test tasks + - name: SonarCloud Scan + env: + CI_BRANCH: ${{ github.ref_name }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: ./gradlew sonarqube -Dsonar.login=$SONAR_TOKEN \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 0572b5f..f124707 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,9 +1,9 @@ plugins { java + jacoco id("org.springframework.boot") version "3.2.5" id("io.spring.dependency-management") version "1.1.4" - jacoco - id("org.sonarqube") version "4.4.1.3373" + id("org.sonarqube") version "5.0.0.4638" } group = "snackscription" @@ -13,7 +13,6 @@ java { sourceCompatibility = JavaVersion.VERSION_21 } - configurations { compileOnly { extendsFrom(configurations.annotationProcessor.get()) @@ -38,31 +37,53 @@ dependencies { testImplementation("org.springframework.boot:spring-boot-starter-test") } -tasks.withType { - useJUnitPlatform() +sonar { + properties { + property("sonar.projectKey","ADPRO-C11_snackscription-review") + property("sonar.organization", "adpro-c11") + property("sonar.host.url", "https://sonarcloud.io") + property("sonar.branch.name", System.getenv("CI_BRANCH") ?: 'main') + } +} + +tasks.register("unitTest") { + description = "Runs unit tests." + group = "verification" + + filter { + excludeTestsMatching("*FunctionalTest") + } } -tasks.test { +tasks.register("functionalTest") { + description = "Runs functional tests." + group = "verification" + + filter { + includeTestsMatching("*FunctionalTest") + } +} + +tasks.withType().configureEach { useJUnitPlatform() +} + +tasks.test{ + filter{ + excludeTestsMatching("*FunctionalTest") + } + finalizedBy(tasks.jacocoTestReport) } + tasks.jacocoTestReport { classDirectories.setFrom(files(classDirectories.files.map { - fileTree(it) { exclude("**/*Application**")} + fileTree(it) { exclude("**/*Application**") } })) - dependsOn(tasks.test) + dependsOn(tasks.test) // tests are required to run before generating the report reports { xml.required.set(true) - html.required.set(true) - csv.required.set(false) + csv.required.set(true) html.outputLocation.set(layout.buildDirectory.dir("jacocoHtml")) } -} - -sonar { - properties { - property("sonar.projectKey","ADPRO-C11_snackscription-review") - property("sonar.organization", "adpro-c11") - property("sonar.host.url", "https://sonarcloud.io") - } } \ No newline at end of file