Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore #63] Jacoco 세팅하기 #64

Merged
merged 9 commits into from
Aug 21, 2024
Merged
32 changes: 18 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,22 @@ jobs:
- name: Check the timezone
run: date

# 자바 버전 설정
- name: Set up JDK 17
- name: 자바 버전 17 설정
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

# test 경로 application.yml 파일 생성
- name: Generate application.yml
- name: test 경로 application.yml 파일 생성
run: |
mkdir -p ./src/test/resources
echo "${{ secrets.TEST_APPLICATION_YML }}" > ./src/test/resources/application.yml

# gradle 권한 부여
- name: Grant execute permission for gradlew
- name: gradle 권한 부여
run: chmod +x ./gradlew
shell: bash

# 빌드 시 캐시 적용
- name: Gradle Caching
- name: 빌드 시 캐시 적용
uses: actions/cache@v3
with:
path: |
Expand All @@ -48,19 +44,27 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-

# 빌드
- name: Build with Gradle
- name: 빌드
run: ./gradlew build

# 테스트 결과 PR 코멘트에 등록
- name: Register the test results as PR comments
- name: Jacoco 테스트 결과 출력
id: jacoco
uses: madrapps/[email protected]
with:
title: Code Coverage
paths: ${{ github.workspace }}/**/build/reports/jacocoReport/test/jacocoTestReport.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 60
min-coverage-changed-files: 60
update-comment: true

- name: 테스트 결과 PR 코멘트에 등록
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: '**/build/test-results/test/TEST-*.xml'

# 테스트 실패시 코드 라인에 대한 체크 추가
- name: If test fail, add check comment on failed code line
- name: 테스트 실패시 코드 라인에 대한 체크 추가
uses: mikepenz/action-junit-report@v3
if: always()
with:
Expand Down
64 changes: 63 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id 'java'
id 'org.springframework.boot' version '3.2.8'
id 'io.spring.dependency-management' version '1.1.6'
id 'jacoco'
}

group = 'com.dnd'
Expand All @@ -23,6 +24,67 @@ repositories {
mavenCentral()
}

test {
useJUnitPlatform()
finalizedBy jacocoTestReport
}

jacoco {
toolVersion = "0.8.12"
reportsDirectory = layout.buildDirectory.dir('jacocoReport')
}

def QDomains = []

for (qPattern in '**/QA'..'**/QZ') {
QDomains.add(qPattern + '*')
}

jacocoTestReport {
dependsOn test

classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, excludes: [
'**/*Application*',
'**/exception/**',
'**/config/**',
'**/dto/**',
'**/s3/**'
] + QDomains)
}))

reports {
html.required.set(true)
xml.required.set(true)
csv.required.set(true)
}
}

jacocoTestCoverageVerification {
violationRules {
rule {
enabled = true
element = 'CLASS'

limit {
counter = 'LINE'
value = 'COVERERDRATIO'
minimum = 0.7
}
}

rule {
excludes = [
'**/*Application*',
'**/exception/**',
'**/config/**',
'**/dto/**',
'**/s3/**'
] + QDomains
}
}
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
Expand Down Expand Up @@ -66,7 +128,7 @@ dependencies {

// mail
implementation 'org.springframework.boot:spring-boot-starter-mail'

//swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0'

Expand Down
Loading