Skip to content

Commit 2585c06

Browse files
committed
[YS-39] chore: JaCoCo 및 소나클라우드 연동 (#10)
* chore: add Jacoco test coverage reporting and verification * chore: update ci script for jacoco * fix: sonar sources path * chore: update version in ci script * chore: add upload problems report as artifact step * chore: add continue on error in ci * chore: update version * chore: update Java toolchain configuration * chore: delete upload problems report step
1 parent 10db1db commit 2585c06

File tree

2 files changed

+107
-6
lines changed

2 files changed

+107
-6
lines changed

.github/workflows/ci-backend.yml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,37 @@ on:
1111
- dev
1212

1313
jobs:
14-
build:
14+
test:
15+
name: Code Quality Check
1516
runs-on: ubuntu-latest
1617

1718
steps:
18-
- uses: actions/checkout@v3
19+
- uses: actions/checkout@v4
1920

2021
- name: Set up JDK 17
21-
uses: actions/setup-java@v3
22+
uses: actions/setup-java@v4
2223
with:
2324
java-version: '17'
2425
distribution: 'temurin'
2526

2627
- name: Grant execute permission for gradlew
2728
run: chmod +x gradlew
2829

29-
- name: Build with Gradle
30-
run: ./gradlew clean build
30+
- name: Cache SonarCloud packages
31+
uses: actions/cache@v4
32+
with:
33+
path: ~/.sonar/cache
34+
key: ${{ runner.os }}-sonar
35+
restore-keys: ${{ runner.os }}-sonar
36+
37+
- name: Setup Gradle
38+
uses: gradle/gradle-build-action@v2
39+
with:
40+
arguments: check
41+
cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/dev' }}
42+
43+
- name: Build and analyze
44+
env:
45+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
47+
run: ./gradlew build sonar --info

build.gradle.kts

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ plugins {
33
kotlin("plugin.spring") version "1.9.25"
44
id("org.springframework.boot") version "3.4.1"
55
id("io.spring.dependency-management") version "1.1.7"
6+
id("jacoco")
7+
id("org.sonarqube") version "6.0.1.5171"
68
kotlin("plugin.jpa") version "1.9.25"
79
}
810

@@ -11,7 +13,7 @@ version = "0.0.1-SNAPSHOT"
1113

1214
java {
1315
toolchain {
14-
languageVersion = JavaLanguageVersion.of(17)
16+
languageVersion.set(JavaLanguageVersion.of(17))
1517
}
1618
}
1719

@@ -71,6 +73,88 @@ allOpen {
7173
annotation("jakarta.persistence.Embeddable")
7274
}
7375

76+
jacoco {
77+
toolVersion = "0.8.8"
78+
}
79+
7480
tasks.withType<Test> {
7581
useJUnitPlatform()
82+
finalizedBy(tasks.jacocoTestReport)
83+
}
84+
85+
sonar {
86+
properties {
87+
property("sonar.projectKey", "YAPP-Github_25th-Web-Team-2-BE")
88+
property("sonar.organization", "yapp-github")
89+
property("sonar.host.url", "https://sonarcloud.io")
90+
property("sonar.coverage.jacoco.xmlReportPaths", "build/reports/jacoco/index.xml")
91+
property("sonar.sources", "src/main/kotlin")
92+
property("sonar.sourceEncoding", "UTF-8")
93+
property("sonar.exclusions", "**/test/**, **/resources/**, **/*Application*.kt, **/*Controller*.kt, **/*Config.kt, **/*Repository*.kt, **/*Dto*.kt, **/*Response*.kt, **/*Request*.kt, **/*Exception*.kt")
94+
property("sonar.test.inclusions", "**/*Test.kt")
95+
property("sonar.kotlin.coveragePlugin", "jacoco")
96+
}
97+
}
98+
99+
tasks.jacocoTestReport {
100+
dependsOn(tasks.test)
101+
reports{
102+
html.required.set(true)
103+
xml.required.set(true)
104+
html.outputLocation.set(file(layout.buildDirectory.dir("reports/jacoco/index.html").get().asFile))
105+
xml.outputLocation.set(file(layout.buildDirectory.dir("reports/jacoco/index.xml").get().asFile))
106+
}
107+
108+
classDirectories.setFrom(
109+
files(
110+
classDirectories.files.flatMap { dir ->
111+
fileTree(dir) {
112+
exclude(
113+
"**/*Application*",
114+
"**/config/*",
115+
"**/domain/exception/*",
116+
"**/domain/gateway/*",
117+
"**/domain/model/*",
118+
"**/infrastructure/*",
119+
"**/presentation/*",
120+
"**/util/*"
121+
)
122+
}.files
123+
}
124+
)
125+
)
126+
finalizedBy(tasks.jacocoTestCoverageVerification)
127+
}
128+
129+
tasks.jacocoTestCoverageVerification {
130+
violationRules {
131+
rule {
132+
isFailOnViolation = false
133+
isEnabled = true
134+
element = "CLASS"
135+
136+
limit {
137+
counter = "LINE"
138+
value = "COVEREDRATIO"
139+
minimum = 0.70.toBigDecimal()
140+
}
141+
142+
limit {
143+
counter = "BRANCH"
144+
value = "COVEREDRATIO"
145+
minimum = 0.70.toBigDecimal()
146+
}
147+
148+
excludes = listOf(
149+
"**.*Application*",
150+
"**.config.*",
151+
"**.domain.exception.*",
152+
"**.domain.gateway.*",
153+
"**.domain.model.*",
154+
"**.infrastructure.*",
155+
"**.presentation.*",
156+
"**.util.*"
157+
)
158+
}
159+
}
76160
}

0 commit comments

Comments
 (0)