Skip to content

Commit

Permalink
#11 sonar scanner 설정을 sonar-project.properties 에서 하도록 변경 (#48)
Browse files Browse the repository at this point in the history
* #11 test fail

* #11 sonarqube dependsOn test

* #11 pr test 수정

* #11 불필요 pr task 제거

* #11 sonar scanner 변경

* #11 sonar scanner 변경

* #11 sonar scanner 변경

* #11 sonar scanner 변경

* #11 sonar scanner 변경

* #11 sonar scanner 변경

* #11 sonar scanner 변경

* #11 파일 제거

* #11 revert

* #11 properties 수정

* #11 properties 수정

* #11 properties 수정

* #11 properties 수정

* #11 properties 수정

* #11 properties 수정

* #11 properties 수정

* #11 properties 수정

* #11 properties 수정

* #11 properties 수정

* #11 test coverage 제외

* #11 test inclusion

* #11 test coverage 제외

* #11 test coverage 제외

* #11 불필요 설정 제거

* #11 jacocoTestReport를 sonarqube 가 자동 detect 하도록 변경

* #11 revert

* #11 revert

* #11 sonarqube tests

* #11 불필요 설정 제거

* #11 build test

* #11 build scanner 적용

* #11 main 만 빌드

* #11 jib 외 설정 제거

* #11 GITHUB_TOKEN revert

* #11 debugging

* #11 info 옵션만 제거

---------

Co-authored-by: hanjoo96.cho <[email protected]>
  • Loading branch information
chohanjoo and hanjoo96.cho authored Nov 25, 2023
1 parent 27a5283 commit f573c04
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 38 deletions.
31 changes: 4 additions & 27 deletions .github/workflows/PullRequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ jobs:
overwrite-settings: true
job-status: success

# Setup sonar-scanner
- name: Setup SonarQube
uses: warchant/setup-sonar-scanner@v5

- name: Cache SonarQube packages
uses: actions/cache@v1
with:
Expand All @@ -54,38 +50,19 @@ jobs:
USERNAME: ${{secrets.USERNAME}}
TOKEN: ${{secrets.TOKEN}}
GITHUB_TOKEN: ${{ secrets.TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
run: ./gradlew clean test jacocoTestReport --stacktrace --profile

- name: SonarQube Scan
run: |
sonar-scanner \
-Dsonar.host.url=${{ secrets.SONAR_HOST_URL }} \
-Dsonar.login=${{ secrets.SONAR_LOGIN }} \
-Dsonar.password=${{ secrets.SONAR_PASSWORD }} \
-Dsonar.projectKey=book-server \
-Dsonar.sourceEncoding=UTF-8 \
-Dsonar.language=java \
-Dsonar.java.source=11 \
-Dsonar.verbose=true \
-Dsonar.scm.revision=${{ github.event.pull_request.head.sha }} \
-Dsonar.scm.provider=git \
-Dsonar.pullrequest.key=${{ github.event.pull_request.number }} \
-Dsonar.pullrequest.branch=${{ github.event.pull_request.head.ref }} \
-Dsonar.pullrequest.base=${{ github.base_ref }} \
-Dsonar.pullrequest.github.repository=${{ github.repository }} \
-Dsonar.sources=api/src \
-Dsonar.java.binaries=api/build/classes \
-Dsonar.log.level=INFO \
uses: sonarsource/sonarqube-scan-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}

- name: Test Coverage
env:
USERNAME: ${{ secrets.USERNAME }}
TOKEN: ${{ secrets.TOKEN }}
GITHUB_TOKEN: ${{ secrets.TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
run: ./gradlew jacocoTestCoverageVerification --stacktrace --profile

- name: Add coverage to PR
Expand Down
24 changes: 21 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,57 @@ on:
push:
branches:
- main
- '#11-test-coverage'


jobs:
build:
name: Build
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11

- name: Cache SonarQube packages
uses: actions/cache@v1
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Cache Gradle packages
uses: actions/cache@v1
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle

- name: Docker Login
run: echo "${{ secrets.TOKEN }}" | docker login ghcr.io -u ${{ secrets.USERNAME }} --password-stdin

- name: Build with Gradle
env:
USERNAME: ${{secrets.USERNAME}}
TOKEN: ${{secrets.TOKEN}}
GITHUB_TOKEN: ${{ secrets.TOKEN }} # Needed to get PR information, if any
run: ./gradlew clean test jacocoTestReport --stacktrace --profile

- name: SonarQube Scan
uses: sonarsource/sonarqube-scan-action@master
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}

- name: Build with Gradle and Jib
env:
USERNAME: ${{secrets.USERNAME}}
TOKEN: ${{secrets.TOKEN}}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
GITHUB_TOKEN: ${{ secrets.TOKEN }} # Needed to get PR information, if any
run: ./gradlew jib --image=ghcr.io/${{ github.repository }}:${{ github.sha }} sonar --info
run: ./gradlew jib --image=ghcr.io/${{ github.repository }}:${{ github.sha }}
7 changes: 0 additions & 7 deletions api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,6 @@ configurations {
}
//querydsl 추가 끝

sonar {
properties {
property "sonar.projectKey", "book-server"
property "sonar.projectName", "book-server"
}
}

jacoco {
toolVersion = "0.8.10"
reportsDirectory = layout.buildDirectory.dir("$buildDir/reports/jacoco")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@SpringBootTest
@ActiveProfiles("test")
class BookServerApplicationTests {
class BookServerApplicationTest {
private static final GenericContainer<?> redisContainer = new GenericContainer<>(DockerImageName.parse("redis:6.2.5"))
.withExposedPorts(6379);

Expand Down
11 changes: 11 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
sonar.projectKey=book-server

# relative paths to source directories. More details and properties are described
# at https://docs.sonarqube.org/latest/project-administration/narrowing-the-focus/
sonar.sources=api/src/main
sonar.tests=api/src/test
sonar.java.binaries=api/build/classes
sonar.language=java
sonar.java.source=11
sonar.coverage.jacoco.xmlReportPaths=api/build/reports/jacoco.xml
sonar.coverage.exclusions=**/*Supplier.java, **/config/*, **/*Exception.java

0 comments on commit f573c04

Please sign in to comment.