Skip to content

develop - Report Sonar Results #219

develop - Report Sonar Results

develop - Report Sonar Results #219

name: "Report Sonar Results"
# we have multiple workflows - this helps to distinguish for them
run-name: "${{ github.event.workflow_run.pull_requests[0].title && github.event.workflow_run.pull_requests[0].title || github.event.workflow_run.head_branch }} - Report Sonar Results"
on:
workflow_run:
workflows: ["Build & Test"] # runs after build and test workflow
types:
- completed
jobs:
#
# Collect and upload sonar report with coverage generated by the Build & Test workflow
#
sonar-report:
name: Sonar-Report
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# repository: ${{ github.event.workflow_run.head_repository.full_name }}
ref: ${{ github.event.workflow_run.head_branch }}
fetch-depth: 0
- name: Setup - Java 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'
# Download jacoco overall coverage from build & test output
- name: Download - Jacoco Overall Coverage
uses: actions/download-artifact@v4
with:
github-token: ${{ secrets.BOT_ACCESS_TOKEN }}
run-id: ${{ github.event.workflow_run.id }} # download artifacts from build and test workflow
pattern: jacoco-coverage-overall # uses artifact of build and test workflow
merge-multiple: true
path: ${{ github.workspace }}/target/site/jacoco-overall-coverage
- name: Sonar - Analyze
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
mvn --batch-mode -DskipTests compile sonar:sonar \
-Dsonar.scm.revision=${{ github.event.workflow_run.head_sha }} \
-Dsonar.pullrequest.key=${{ github.event.workflow_run.pull_requests[0].number }} \
-Dsonar.pullrequest.branch=${{ github.event.workflow_run.pull_requests[0].head.ref }} \
-Dsonar.pullrequest.base=${{ github.event.workflow_run.pull_requests[0].base.ref }} \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.organization=ehrbase \
-Dsonar.projectKey=ehrbase_openEHR_SDK \
-Dsonar.exclusions=test/** \
-Dsonar.coverage.exclusions=test/**,test-data/**/*,opt-14/**/*,response-dto/**/* \
-Dsonar.coverage.jacoco.xmlReportPaths=${{ github.workspace }}/target/site/jacoco-overall-coverage/jacoco.xml