-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: 코드 정적 분석을 위한 Jacoco 및 SonarCloud 도입 #147
Changes from 11 commits
68df0e1
3f5c09c
f2abe4f
3f05104
85eb5b8
8028a57
c190dad
cce4540
2bb9dd6
085f707
1ba4443
6903932
61893b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,8 @@ on: | |
- develop | ||
|
||
jobs: | ||
build: | ||
test: | ||
name: Code Quality Check | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
|
@@ -26,5 +27,21 @@ jobs: | |
- name: Grant execute permisson for gradlew | ||
run: chmod +x gradlew | ||
|
||
- name: Build with Gradle | ||
run: ./gradlew clean build | ||
- name: Cache SonarCloud packages | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.sonar/cache | ||
key: ${{ runner.os }}-sonar | ||
restore-keys: ${{ runner.os }}-sonar | ||
|
||
- name: Setup Gradle | ||
uses: gradle/gradle-build-action@v2 | ||
with: | ||
arguments: check | ||
cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/develop' }} | ||
|
||
- name: Build and analyze | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네 맞아요. SonarCloud에 대한 액세스를 인증하는데 사용되는 토큰입니다~ |
||
run: ./gradlew sonar --info --stacktrace |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ plugins { | |
id 'java' | ||
id 'org.springframework.boot' version '2.7.9' | ||
id 'io.spring.dependency-management' version '1.0.15.RELEASE' | ||
id 'jacoco' | ||
id 'org.sonarqube' version '4.2.1.3168' | ||
} | ||
|
||
group = 'mocacong' | ||
|
@@ -18,6 +20,96 @@ configurations { | |
} | ||
} | ||
|
||
jacoco { | ||
toolVersion = '0.8.8' | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
finalizedBy 'jacocoTestReport' | ||
} | ||
|
||
def Qdomains = [] | ||
for (qPattern in "**/QA" .. "**/QZ") { | ||
Qdomains.add(qPattern + "*") | ||
} | ||
|
||
sonar { | ||
properties { | ||
property 'sonar.host.url', 'https://sonarcloud.io' | ||
property 'sonar.organization', 'mocacong' | ||
property 'sonar.projectKey', 'mocacong_Mocacong-Backend' | ||
property 'sonar.coverage.jacoco.xmlReportPaths', 'build/reports/jacoco/index.xml' | ||
property 'sonar.sources', 'src' | ||
property 'sonar.language', 'java' | ||
property 'sonar.sourceEncoding', 'UTF-8' | ||
property 'sonar.exclusions', '**/test/**, **/resources/**, **/*Application*.java, **/*Controller*.java ,**/config/**, **/dto/**, ' + | ||
'**/exception/**, **/security/**, **/support/**, **/Q*.java' | ||
property 'sonar.test.inclusions', '**/*Test.java' | ||
property 'sonar.java.coveragePlugin', 'jacoco' | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 개인적으로는 jacoco 관련 설정이 아래로 가고 의존성 선언이 더 위쪽으로 왔으면 하는데 어떤가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋습니다. 안그래도 새로 생긴 태스크들 추가하면서 dependency 위치를 어디다 두어야 할지가 고민됐었네요 ㅎㅎ.. |
||
|
||
jacocoTestReport { | ||
dependsOn test | ||
reports{ | ||
html.required.set(true) | ||
xml.required.set(true) | ||
html.destination file("$buildDir/reports/jacoco/index.html") | ||
xml.destination file("$buildDir/reports/jacoco/index.xml") | ||
} | ||
|
||
afterEvaluate { | ||
classDirectories.setFrom( | ||
files(classDirectories.files.collect { | ||
fileTree(dir: it, excludes: | ||
[ | ||
"**/*Application*", | ||
"**/*Controller*", | ||
"**/config/*", | ||
"**/dto/*", | ||
"**/exception/*", | ||
"**/security/*", | ||
"**/support/*" | ||
Comment on lines
+94
to
+100
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 테스트 커비리지 제외하는 패키지로 이해했는데 맞을까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dto는 비즈니스로직만 테스트하여도 커버리지가 좀 나왔던 것 같은데, dto도 제외시키는게 좋을까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
]+ Qdomains) | ||
}) | ||
) | ||
} | ||
finalizedBy 'jacocoTestCoverageVerification' | ||
} | ||
|
||
jacocoTestCoverageVerification { | ||
violationRules { | ||
rule { | ||
failOnViolation = false | ||
enabled = true | ||
element = 'CLASS' | ||
|
||
limit { | ||
counter = 'LINE' | ||
value = 'COVEREDRATIO' | ||
minimum = 0.70 | ||
} | ||
|
||
limit { | ||
counter = 'BRANCH' | ||
value = 'COVEREDRATIO' | ||
minimum = 0.70 | ||
} | ||
|
||
excludes = [ | ||
'**.*Application*', | ||
'**.*Controller*', | ||
'**.config.*', | ||
'**.dto.*', | ||
'**.exception.*', | ||
'**.security.*', | ||
'**.support.*' | ||
] + Qdomains | ||
Comment on lines
+127
to
+135
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기도 마찬가지로 이유가 궁금합니다 :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 위에 남긴 코멘트 내용과 동일합니다~ 참고로 해당 태스크는 커버리지를 확인하는 태스크입니다. |
||
} | ||
} | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
@@ -44,7 +136,3 @@ dependencies { | |
testImplementation 'io.rest-assured:rest-assured' | ||
testImplementation 'it.ozimov:embedded-redis:0.7.2' | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cache-read-only
는 빌드 시에 gradle cache를 이용해서 하도록 적용하는 것으로 이해했는데 맞을까요?아래 이유가 궁금해서 코멘트 작성해봅니다 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분은 main과 develop 브랜치일때만
cache-read-only
가 false되게 설정한 부분입니다.cache-read-only
는 true일 경우 cache를 읽기만 하고 cache에 저장하지 않고 false일 경우는 읽기와 저장 모두 수행합니다.결국 main이나 develop 브랜치에서 푸시될 때만 캐시에 저장되고 다른 브랜치들에서는 캐시읽기만 허용한 것인데 주로 안정된 코드를 추가하는 주요 브랜치에서만 빌드 시간을 최적화하기 위해 이렇게 설정했습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오..이부분 read-only가 true일 때랑 false일 때랑 시간의 차이도 궁금하네요 👀 새로운 것을 알아갑니다 👍