diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e9a1708..20dc058 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ jobs: Run-PR-Test: runs-on: ubuntu-latest permissions: - contents: read + contents: write pull-requests: write checks: write @@ -24,6 +24,13 @@ jobs: java-version: '21' distribution: 'temurin' + - name: Cache SonarQube packages + uses: actions/cache@v4 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + - name: Gradle cache uses: actions/cache@v4 with: @@ -43,7 +50,9 @@ jobs: echo "${{ secrets.FIREBASE_ADMINSDK_ACCOUNT_KEY }}" > src/main/resources/firebase/firebase-adminsdk-account.json - name: Run Gradle Test - run: ./gradlew clean test + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: ./gradlew clean test jacocoTestReport sonar - name: Publish Unit Test Results if: always() @@ -53,3 +62,11 @@ jobs: check_name: '테스트 결과 🛠️' check_run_annotations: 'none' comment_mode: 'off' + + - name: Comment coverage on PR + uses: madrapps/jacoco-report@v1.6 + with: + paths: build/reports/jacoco/test/jacocoTestReport.xml + token: ${{ secrets.GITHUB_TOKEN }} + min-coverage-overall: 90 + min-coverage-changed-files: 100 diff --git a/build.gradle b/build.gradle index 2eb6b76..8e84767 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,7 @@ plugins { id 'java' + id 'jacoco' + id "org.sonarqube" version "7.2.0.6526" id 'org.springframework.boot' version '3.5.3' id 'io.spring.dependency-management' version '1.1.7' } @@ -7,6 +9,17 @@ plugins { group = 'com.daedan' version = '0.0.1-SNAPSHOT' +jacoco { + toolVersion = "0.8.14" +} + +sonar { + properties { + property "sonar.projectKey", "festabook_backend" + property "sonar.organization", "festabook" + } +} + java { toolchain { languageVersion = JavaLanguageVersion.of(21) @@ -88,3 +101,28 @@ tasks.named('test') { springBoot { buildInfo() } + +test { + useJUnitPlatform() +} + +jacocoTestReport { + dependsOn test + + classDirectories.setFrom( + files(classDirectories.files.collect { + fileTree(dir: it, exclude: [ + "**/*Application*", + "**/*Config*", + "**/*Aspect*", + "**/*Logging*" + ]) + }) + ) + + reports { + html.required = true + xml.required = true + csv.required = false + } +}