Skip to content

Commit f25cf26

Browse files
committed
ci: PR 변경 라인 기준 diff coverage 게이트 추가
로직이 수정/추가돼도 테스트가 안 따라오는 경우를 CI가 기계적으로 잡을 방법이 없었음(기존 CI는 기존 테스트 통과 여부만 확인). - JaCoco로 커버리지 리포트(xml) 생성 - diff-cover로 PR에서 실제로 바뀐 라인만 커버리지 검사(70% 미만 시 CI 실패) - 전체 커버리지 게이트가 아니라 diff 기준이라, 기존 미테스트 코드가 발목잡지 않으면서 "새로 바뀐 부분"만 강제함 로컬에서 기존 PR #243 diff로 실제 검증: KakaoSignInService(0%), AppleSignInService(16.7%) 등 테스트 없이 들어간 라인을 정확히 잡아냄.
1 parent de33d80 commit f25cf26

3 files changed

Lines changed: 32 additions & 0 deletions

File tree

.github/workflows/prod-ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ jobs:
4040
4141
steps:
4242
- uses: actions/checkout@v3
43+
with:
44+
fetch-depth: 0
4345
- name: Set up JDK 11
4446
uses: actions/setup-java@v3
4547
with:
@@ -74,3 +76,12 @@ jobs:
7476
SPRING_DATASOURCE_USERNAME: runnect
7577
SPRING_DATASOURCE_PASSWORD: runnect_local_password
7678
SPRING_DATA_REDIS_HOST: localhost
79+
80+
# PR에서 새로 추가/수정된 라인만 커버리지를 검사한다 (전체 커버리지 게이트가 아님).
81+
# 로직이 바뀌었는데 테스트가 안 따라오는 경우를 CI에서 기계적으로 잡기 위함.
82+
- name: Diff coverage 게이트 (변경된 라인 기준)
83+
run: |
84+
pip install diff-cover
85+
diff-cover build/reports/jacoco/test/jacocoTestReport.xml \
86+
--compare-branch=origin/${{ github.base_ref }} \
87+
--fail-under=70

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,17 @@ public class SomeService {
212212

213213
yml에 키가 없으면 기본값은 비활성(`false`)이다.
214214

215+
### ✅ Diff Coverage 게이트
216+
217+
PR에서 새로 추가/수정된 라인이 테스트로 커버되는지 CI(`build` job)가 자동으로 확인한다 — 로직을 고쳤는데 관련 테스트가 안 따라오는 경우를 기계적으로 잡기 위함. 전체 커버리지가 아니라 **이번 PR에서 바뀐 라인만** 대상으로 하며, 기준은 70%다.
218+
219+
```bash
220+
# CI에서 실행되는 것과 동일한 방식으로 로컬에서 직접 확인
221+
./gradlew jacocoTestReport
222+
pip install diff-cover
223+
diff-cover build/reports/jacoco/test/jacocoTestReport.xml --compare-branch=origin/main
224+
```
225+
215226
</aside>
216227
<hr>
217228
</br>

build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
plugins {
22
id 'java'
3+
id 'jacoco'
34
id 'org.springframework.boot' version '2.7.14'
45
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
56
}
@@ -79,4 +80,13 @@ dependencies {
7980

8081
tasks.named('test') {
8182
useJUnitPlatform()
83+
finalizedBy jacocoTestReport
84+
}
85+
86+
jacocoTestReport {
87+
dependsOn test
88+
reports {
89+
xml.required = true
90+
html.required = true
91+
}
8292
}

0 commit comments

Comments
 (0)