Skip to content

Commit

Permalink
feat: JaCoCo 설정 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
kanguk01 committed Nov 14, 2024
1 parent ce1eeee commit 9184d63
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 47 deletions.
46 changes: 12 additions & 34 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,40 +80,18 @@ jobs:
- name: Build with Gradle
run: ./gradlew clean build -Dspring.profiles.active=test

- name: Run Tests and Generate Code Coverage Report
run: ./gradlew test jacocoTestReport -Dspring.profiles.active=test
- name: Run Tests
run: ./gradlew test -Dspring.profiles.active=test

- name: Upload Jacoco Report
uses: actions/upload-artifact@v3
with:
name: jacoco-report
path: build/reports/jacoco/test/jacocoTestReport.xml
- name: Generate JaCoCo Coverage Report
run: ./gradlew jacocoTestReport

- name: Post Coverage Comment to PR
uses: actions/github-script@v6
- name: Generate Coverage Badge and Comment
uses: cicirello/jacoco-badge-generator@v2
with:
script: |
const fs = require('fs');
const coverageReport = fs.readFileSync('build/reports/jacoco/test/jacocoTestReport.xml', 'utf8');
const match = coverageReport.match(/<counter type="INSTRUCTION" missed="(\d+)" covered="(\d+)"\/>/);
if (match) {
const missed = parseInt(match[1]);
const covered = parseInt(match[2]);
const coverage = ((covered / (missed + covered)) * 100).toFixed(2);
const comment = `### Code Coverage Report\n\n- **Coverage**: ${coverage}%\n\n`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
} else {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "### Code Coverage Report\n\nUnable to parse coverage report."
});
}
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 }}
19 changes: 6 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ java {
test {
useJUnitPlatform()
systemProperty 'spring.profiles.active', 'test'
finalizedBy jacocoTestReport
}

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

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

protobuf {
Expand Down Expand Up @@ -122,20 +124,11 @@ sourceSets {
}
}

jacoco {
toolVersion = "0.8.10"
}

tasks.jacocoTestReport {
jacocoTestReport {
dependsOn test

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

tasks.build {
dependsOn jacocoTestReport
}

0 comments on commit 9184d63

Please sign in to comment.