Skip to content

Commit

Permalink
Fix SonarCloud
Browse files Browse the repository at this point in the history
  • Loading branch information
asteriskzie committed May 26, 2024
1 parent c8aac1a commit bdb67ca
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 20 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ name: Java CI Pipeline
on:
push:
branches:
- "**"
- main
- staging
- dev
pull_request:
branches:
- main
- staging
- dev
workflow_dispatch:

jobs:
Expand All @@ -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
Expand Down Expand Up @@ -84,4 +93,9 @@ jobs:
./gradlew jacocoTestReport
env:
PRODUCTION: test
# (Optional) Add steps for generating coverage report and other post-test tasks
# (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
57 changes: 39 additions & 18 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -13,7 +13,6 @@ java {
sourceCompatibility = JavaVersion.VERSION_21
}


configurations {
compileOnly {
extendsFrom(configurations.annotationProcessor.get())
Expand All @@ -38,31 +37,53 @@ dependencies {
testImplementation("org.springframework.boot:spring-boot-starter-test")
}

tasks.withType<Test> {
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<Test>("unitTest") {
description = "Runs unit tests."
group = "verification"

filter {
excludeTestsMatching("*FunctionalTest")
}
}

tasks.test {
tasks.register<Test>("functionalTest") {
description = "Runs functional tests."
group = "verification"

filter {
includeTestsMatching("*FunctionalTest")
}
}

tasks.withType<Test>().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")
}
}

0 comments on commit bdb67ca

Please sign in to comment.