From 3b2507bce0d4849046745b2f09d5f9dfce304ec0 Mon Sep 17 00:00:00 2001 From: BHyeonKim Date: Fri, 30 May 2025 10:27:25 +0900 Subject: [PATCH 1/2] =?UTF-8?q?config:=20sonarqube=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/code-analyze-pr.yml | 71 +++++++++++++++++++++++++ .github/workflows/code-analyze-push.yml | 46 ++++++++++++++++ build.gradle | 25 +++++++++ 3 files changed, 142 insertions(+) create mode 100644 .github/workflows/code-analyze-pr.yml create mode 100644 .github/workflows/code-analyze-push.yml diff --git a/.github/workflows/code-analyze-pr.yml b/.github/workflows/code-analyze-pr.yml new file mode 100644 index 00000000..aad1f2cc --- /dev/null +++ b/.github/workflows/code-analyze-pr.yml @@ -0,0 +1,71 @@ +name: Code Analyze Pull Request + +run-name: Run code analyze triggered with pull request by ${{github.actor}} + +on: + pull_request: + types: [opened, reopened, synchronize] + branches: + - main + - dev + +jobs: + build: + name: Build and analyze + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: 21 + distribution: 'temurin' # Alternative distribution options are available. + - name: Cache SonarQube packages + uses: actions/cache@v4 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + - name: Cache Gradle packages + uses: actions/cache@v4 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} + restore-keys: ${{ runner.os }}-gradle + - name: Build with tests + env: + JWT_SECRET: ${{ secrets.JWT_SECRET }} + continue-on-error: true + run: ./gradlew build --info + + - name: SonarQube Analysis + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_URL }} + JWT_SECRET: ${{ secrets.JWT_SECRET }} + run: ./gradlew sonar --info + + - name: Comment SonarQube URL on PR + uses: actions/github-script@v7 + env: + SONAR_URL: ${{ secrets.SONAR_URL }} + PROJECT_KEY: "CleanEngine_cleanengine-be_2b6f2f63-fa39-426c-b9c7-8aa127fd14d8" + PR_NUMBER: ${{ github.event.pull_request.number }} + with: + script: | + const { SONAR_URL, PROJECT_KEY, PR_NUMBER } = process.env + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: `## 소나큐브 코드 분석 결과 🔍 + + 소나큐브 분석이 완료되었습니다. 아래 링크에서 결과를 확인하세요: + + 🔗 [소나큐브 분석 결과 보기](${SONAR_URL}/dashboard?id=${PROJECT_KEY}) + + 테스트 결과에 관계없이 코드 품질 분석이 실행되었습니다.` + }) \ No newline at end of file diff --git a/.github/workflows/code-analyze-push.yml b/.github/workflows/code-analyze-push.yml new file mode 100644 index 00000000..6892517d --- /dev/null +++ b/.github/workflows/code-analyze-push.yml @@ -0,0 +1,46 @@ +name: Code Analyze Push + +run-name: Run code analyze triggered with push by ${{github.actor}} + +on: + push: + branches: + - dev +jobs: + build: + name: Build and analyze + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: 21 + distribution: 'temurin' # Alternative distribution options are available. + - name: Cache SonarQube packages + uses: actions/cache@v4 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + - name: Cache Gradle packages + uses: actions/cache@v4 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} + restore-keys: ${{ runner.os }}-gradle + - name: Build with tests + env: + JWT_SECRET: ${{ secrets.JWT_SECRET }} + continue-on-error: true + run: ./gradlew build --info + + - name: SonarQube Analysis + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_URL }} + JWT_SECRET: ${{ secrets.JWT_SECRET }} + run: ./gradlew sonar --info \ No newline at end of file diff --git a/build.gradle b/build.gradle index bf5d0264..0f21eb39 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,8 @@ plugins { id 'java' id 'org.springframework.boot' version '3.4.5' id 'io.spring.dependency-management' version '1.1.7' + id "org.sonarqube" version "6.0.1.5171" + id 'jacoco' } group = 'com.cleanengine' @@ -59,4 +61,27 @@ dependencies { tasks.named('test') { useJUnitPlatform() + finalizedBy jacocoTestReport } + +jacocoTestReport { + reports { + xml.required = true + html.required = true + } + dependsOn test +} + +sonar { + properties { + property "sonar.projectKey", "CleanEngine_cleanengine-be_2b6f2f63-fa39-426c-b9c7-8aa127fd14d8" + property "sonar.projectName", "cleanengine-be" + property "sonar.host.url", System.getenv('SONAR_URL') ?: 'http://localhost:9000' + property "sonar.token", System.getenv('SONAR_TOKEN') ?: '' + property "sonar.java.source", '21' + property "sonar.java.target", '21' + property "sonar.sourceEncoding", "UTF-8" + property "sonar.java.coveragePlugin", "jacoco" + property "sonar.coverage.jacoco.xmlReportPaths", "${project.buildDir}/reports/jacoco/test/jacocoTestReport.xml" + } +} \ No newline at end of file From da70d655933740dd6478cd1a8ea4fd0f6ad347c8 Mon Sep 17 00:00:00 2001 From: BHyeonKim Date: Fri, 30 May 2025 13:09:10 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20host=20url=20=ED=99=98=EA=B2=BD?= =?UTF-8?q?=EB=B3=80=EC=88=98=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20=EC=8A=A4?= =?UTF-8?q?=ED=81=AC=EB=A6=BD=ED=8A=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/code-analyze-pr.yml | 24 +----------------------- .github/workflows/code-analyze-push.yml | 2 +- build.gradle | 2 +- 3 files changed, 3 insertions(+), 25 deletions(-) diff --git a/.github/workflows/code-analyze-pr.yml b/.github/workflows/code-analyze-pr.yml index aad1f2cc..08f369c6 100644 --- a/.github/workflows/code-analyze-pr.yml +++ b/.github/workflows/code-analyze-pr.yml @@ -44,28 +44,6 @@ jobs: - name: SonarQube Analysis env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - SONAR_HOST_URL: ${{ secrets.SONAR_URL }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} JWT_SECRET: ${{ secrets.JWT_SECRET }} run: ./gradlew sonar --info - - - name: Comment SonarQube URL on PR - uses: actions/github-script@v7 - env: - SONAR_URL: ${{ secrets.SONAR_URL }} - PROJECT_KEY: "CleanEngine_cleanengine-be_2b6f2f63-fa39-426c-b9c7-8aa127fd14d8" - PR_NUMBER: ${{ github.event.pull_request.number }} - with: - script: | - const { SONAR_URL, PROJECT_KEY, PR_NUMBER } = process.env - github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: `## 소나큐브 코드 분석 결과 🔍 - - 소나큐브 분석이 완료되었습니다. 아래 링크에서 결과를 확인하세요: - - 🔗 [소나큐브 분석 결과 보기](${SONAR_URL}/dashboard?id=${PROJECT_KEY}) - - 테스트 결과에 관계없이 코드 품질 분석이 실행되었습니다.` - }) \ No newline at end of file diff --git a/.github/workflows/code-analyze-push.yml b/.github/workflows/code-analyze-push.yml index 6892517d..900bcde7 100644 --- a/.github/workflows/code-analyze-push.yml +++ b/.github/workflows/code-analyze-push.yml @@ -41,6 +41,6 @@ jobs: - name: SonarQube Analysis env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - SONAR_HOST_URL: ${{ secrets.SONAR_URL }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} JWT_SECRET: ${{ secrets.JWT_SECRET }} run: ./gradlew sonar --info \ No newline at end of file diff --git a/build.gradle b/build.gradle index eb8ffa51..3a6710c0 100644 --- a/build.gradle +++ b/build.gradle @@ -80,7 +80,7 @@ sonar { properties { property "sonar.projectKey", "CleanEngine_cleanengine-be_2b6f2f63-fa39-426c-b9c7-8aa127fd14d8" property "sonar.projectName", "cleanengine-be" - property "sonar.host.url", System.getenv('SONAR_URL') ?: 'http://localhost:9000' + property "sonar.host.url", System.getenv('SONAR_HOST_URL') ?: 'http://localhost:9000' property "sonar.token", System.getenv('SONAR_TOKEN') ?: '' property "sonar.java.source", '21' property "sonar.java.target", '21'