Update sonarcloud.yml [skip ci]

This commit is contained in:
adhl-0216 2025-04-03 21:19:55 +00:00 committed by GitHub
parent 15ebe2c3f3
commit 1a193e0ed2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -13,43 +13,36 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis fetch-depth: 0
- name: Set up JDK 17 - name: Set up JDK 17
uses: actions/setup-java@v4 uses: actions/setup-java@v4
with: with:
java-version: 17 java-version: 17
distribution: 'zulu' distribution: 'zulu'
- name: Cache SonarQube packages - name: Cache SonarQube packages
uses: actions/cache@v4 uses: actions/cache@v4
with: with:
path: ~/.sonar/cache path: ~/.sonar/cache
key: ${{ runner.os }}-sonar key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages - name: Cache Maven packages
uses: actions/cache@v4 uses: actions/cache@v4
with: with:
path: ~/.m2 path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2 restore-keys: ${{ runner.os }}-m2
- name: Build and Test with Coverage - name: Build and Test with Coverage
env: env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} 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 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 - name: Check Code Coverage
run: | 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) 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%" echo "Code Coverage: $COVERAGE%"
if (( $(echo "$COVERAGE < 80" | bc -l) )); then if (( $(echo "$COVERAGE < 80" | bc -l) )); then
echo "Coverage $COVERAGE% is below 80%. Failing the build." echo "Coverage $COVERAGE% is below 80%. Failing the build."
exit 1 exit 1
fi fi
- name: Check SonarCloud Quality Gate - name: Check SonarCloud Quality Gate
uses: SonarSource/sonarcloud-github-action@master uses: SonarSource/sonarcloud-github-action@master
with: with:
@ -58,3 +51,9 @@ jobs:
-Dsonar.qualitygate.wait=true -Dsonar.qualitygate.wait=true
env: env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Send Slack Notification (SonarCloud Complete, Pending Docker Push Review)
uses: slackapi/slack-github-action@v1.24.0
with:
slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
channel-id: 'ci-notifications'
text: "SonarCloud Analysis Complete: ${{ job.status }} for commit ${{ github.sha }}. Docker Hub push is pending review in GitHub Actions."