Skip to content

Commit

Permalink
feat: 코드 정적 분석을 위한 Jacoco 및 SonarCloud 도입 (#147)
Browse files Browse the repository at this point in the history
* chore: add jacoco setting

* chore: add sonar cloud setting

* chore: change sonar cloud setting

* chore: integrate gradle build and SonarCloud analysis

* chore: fix sonar exclusions

* chore: add steps for upload test coverage

* fix: fix always() in ci scripts

* fix: rollback code

* style: delete unused setting

* chore: add sonar exclusions property path

* chore: change sonar cloud setting

* chore: delete dto from test coverage excludes

* chore: add dto in coverage
  • Loading branch information
Ji-soo708 authored Dec 26, 2023
1 parent 3e41d97 commit b4ed611
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 3 deletions.
23 changes: 20 additions & 3 deletions .github/workflows/ci-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ on:
- develop

jobs:
build:
test:
name: Code Quality Check
runs-on: ubuntu-latest

steps:
Expand All @@ -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 }}
run: ./gradlew sonar --info --stacktrace
88 changes: 88 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -45,6 +47,92 @@ dependencies {
testImplementation 'it.ozimov:embedded-redis:0.7.2'
}

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'
}
}

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/*"
]+ 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
}
}
}

0 comments on commit b4ed611

Please sign in to comment.