Update sonarcloud.yml [skip ci]

This commit is contained in:
adhl-0216 2025-04-03 11:51:12 +00:00 committed by GitHub
parent 4abc65fff8
commit c458c3309a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5,6 +5,7 @@ on:
- main
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
name: Build and analyze
@ -13,24 +14,47 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'zulu' # Alternative distribution options are available.
distribution: 'zulu'
- name: Cache SonarQube packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build and analyze
- name: Build and Test with Coverage
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -B verify jacoco:report org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=adhl-0216_MTU-DevOps-spring-petclinic
- name: Check Code Coverage
run: |
# Extract coverage percentage from JaCoCo report
COVERAGE=$(mvn jacoco:report -q -Dquiet=true && grep -oP '(?<=<td class="right" data-value=")[0-9.]+(?=")' target/site/jacoco/index.html | head -1)
echo "Code Coverage: $COVERAGE%"
if (( $(echo "$COVERAGE < 80" | bc -l) )); then
echo "Coverage $COVERAGE% is below 80%. Failing the build."
exit 1
fi
- name: Check SonarCloud Quality Gate
uses: SonarSource/sonarcloud-github-action@master
with:
args: >
-Dsonar.projectKey=adhl-0216_MTU-DevOps-spring-petclinic
-Dsonar.qualitygate.wait=true
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=adhl-0216_MTU-DevOps-spring-petclinic