diff --git a/.github/workflows/sonar_cloud.yml b/.github/workflows/sonar_cloud.yml new file mode 100644 index 00000000..de080567 --- /dev/null +++ b/.github/workflows/sonar_cloud.yml @@ -0,0 +1,37 @@ +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@v4 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: 17 + distribution: 'temurin' # Alternative distribution options are available + - name: Cache SonarCloud packages + uses: actions/cache@v4 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + - name: Cache Gradle packages + uses: actions/cache@v4 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} + restore-keys: ${{ runner.os }}-gradle + - name: Build and analyze + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: ./gradlew build sonar --info diff --git a/build.gradle b/build.gradle index 25b7e9f6..ce787c3b 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,8 @@ plugins { id 'java' id 'org.springframework.boot' version '3.2.6' id 'io.spring.dependency-management' version '1.1.3' + id 'jacoco' + id "org.sonarqube" version "5.1.0.4882" } group = 'ddingdong' @@ -82,4 +84,47 @@ dependencies { tasks.named('test') { useJUnitPlatform() + finalizedBy 'jacocoTestReport' +} + +sonar { + properties { + property "sonar.projectKey", "COW-dev_ddingdong-be" + property "sonar.organization", "cow-dev" + property "sonar.host.url", "https://sonarcloud.io" + property "sonar.sourceEncoding", "UTF-8" + property "sonar.java.source", "${java.sourceCompatibility}" + property "sonar.coverage.jacoco.xmlReportPaths", "${layout.buildDirectory}/reports/jacoco/test/jacocoTestReport.xml" + property "sonar.junit.reportPaths", "${layout.buildDirectory}/test-results/test" + + property "sonar.exclusions", [ + "**/ddingdong/ddingdongBE/common/**", + "**/ddingdong/ddingdongBE/*Request*", + "**/ddingdong/ddingdongBE/*Response*", + "**/ddingdong/ddingdongBE/*Command*", + "**/ddingdong/ddingdongBE/*Query*", + "**/ddingdong/ddingdongBE/*Dto*" + ].join(',') + } +} + +jacocoTestReport { + dependsOn test + afterEvaluate { + classDirectories.setFrom(files(classDirectories.files.collect { + fileTree(dir: it, exclude: [ + "ddingdong/ddingdongBE/common/**", + "ddingdong/ddingdongBE/*Request*", + "ddingdong/ddingdongBE/*Response*", + "ddingdong/ddingdongBE/*Command*", + "ddingdong/ddingdongBE/*Query*", + "ddingdong/ddingdongBE/*Dto*" + ]) + })) + } + reports { + html.required = true + xml.required = true + csv.required = false + } }