Skip to content

Commit

Permalink
[merge]: 코드 커버리지 측정 자동화 (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
kanguk01 authored Nov 15, 2024
2 parents b30a6c0 + 344817d commit c88dd28
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 13 deletions.
47 changes: 35 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ on:
- develop
- 'weekly/**'

permissions:
contents: write
issues: write
pull-requests: write

jobs:
build-and-test:
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -87,4 +81,33 @@ jobs:
run: ./gradlew clean build -Dspring.profiles.active=test

- name: Run Tests
run: ./gradlew test -Dspring.profiles.active=test
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"
31 changes: 30 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -18,6 +19,7 @@ java {
test {
useJUnitPlatform()
systemProperty 'spring.profiles.active', 'test'
finalizedBy jacocoTestReport
}

configurations {
Expand Down Expand Up @@ -93,6 +95,7 @@ dependencies {

tasks.named('test') {
useJUnitPlatform()
finalizedBy jacocoTestReport
}

protobuf {
Expand All @@ -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 패키지 제외
])
})
)
}

0 comments on commit c88dd28

Please sign in to comment.