diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 16415da7..3039bcc0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,6 +7,11 @@ on: - develop - 'weekly/**' +permissions: + contents: write + issues: write + pull-requests: write + jobs: build-and-test: runs-on: ubuntu-22.04 @@ -36,17 +41,6 @@ jobs: - name: Checkout Repository uses: actions/checkout@v2 -# - name: Cache Gradle dependencies -# uses: actions/cache@v3 -# with: -# path: | -# ~/.gradle/caches/modules-2/files-2.1 -# ~/.gradle/wrapper -# key: gradle-${{ runner.os }}-${{ hashFiles('build.gradle', 'settings.gradle') }} -# restore-keys: | -# gradle-${{ runner.os }}- - - - name: Decode env.properties from GitHub Secrets run: | echo "${{ secrets.ENV_FILE }}" | base64 --decode > ./src/main/resources/env.properties @@ -87,4 +81,33 @@ jobs: run: ./gradlew clean build -Dspring.profiles.active=test - name: Run Tests - run: ./gradlew test -Dspring.profiles.active=test \ No newline at end of file + run: ./gradlew test -Dspring.profiles.active=test + + - name: Generate JaCoCo Coverage Report + run: ./gradlew jacocoTestReport + + - name: Generate Coverage Badge and Summary + uses: cicirello/jacoco-badge-generator@v2 + with: + jacoco-csv-file: 'build/reports/jacoco/test/jacocoTestReport.csv' + badges-directory: 'badges' + generate-branches-badge: true + generate-summary: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Display Coverage Summary JSON + run: | + cat badges/coverage-summary.json + + - name: Extract Coverage Information + if: ${{ github.event_name == 'pull_request' }} + run: | + COVERAGE=$(jq '.coverage' badges/coverage-summary.json) + BRANCH_COVERAGE=$(jq '.branches' badges/coverage-summary.json) + FORMATTED_COVERAGE=$(printf "%.2f" $COVERAGE) + FORMATTED_BRANCH_COVERAGE=$(printf "%.2f" $BRANCH_COVERAGE) + curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -X POST \ + -d "{\"body\": \"### 코드 커버리지\n- Coverage: ${FORMATTED_COVERAGE}%\n- Branches: ${FORMATTED_BRANCH_COVERAGE}%\n\"}" \ + "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" diff --git a/build.gradle b/build.gradle index 388226ec..d5def0b7 100644 --- a/build.gradle +++ b/build.gradle @@ -3,9 +3,10 @@ plugins { id 'org.springframework.boot' version '3.3.3' id 'io.spring.dependency-management' version '1.1.6' id 'com.google.protobuf' version '0.9.4' - + id 'jacoco' } + group = 'com.splanet' version = '0.0.1-SNAPSHOT' @@ -18,6 +19,7 @@ java { test { useJUnitPlatform() systemProperty 'spring.profiles.active', 'test' + finalizedBy jacocoTestReport } configurations { @@ -93,6 +95,7 @@ dependencies { tasks.named('test') { useJUnitPlatform() + finalizedBy jacocoTestReport } protobuf { @@ -119,4 +122,30 @@ sourceSets { srcDirs 'build/generated/source/proto/main/java', 'build/generated/source/proto/main/grpc' } } +} + +jacoco { + toolVersion = "0.8.10" +} + +jacocoTestReport { + dependsOn test + reports { + xml.required.set(true) + html.required.set(true) + csv.required.set(true) + } + classDirectories.setFrom( + files(classDirectories.files.collect { + fileTree(dir: it, exclude: [ + '**/dto/**', // dto 패키지 제외 + '**/config/**', // config 패키지 제외 + '**/exception/**', // exception 패키지 제외 + '**/core/**', // core 패키지 제외 + '**/mapper/**', // mapper 패키지 제외 + '**/grpc/**', // grpc 패키지 제외 + '**/log/**', // log 패키지 제외 + ]) + }) + ) } \ No newline at end of file