From 590ad00aa29cae3a02d38e7336fd26ffbfe98bab Mon Sep 17 00:00:00 2001 From: Peter Nied Date: Fri, 22 Nov 2024 17:49:51 +0000 Subject: [PATCH] Report the issues as error annotations Signed-off-by: Peter Nied --- .github/workflows/sonar-qube.yml | 15 +++++++++++++-- sonar-project.properties | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/workflows/sonar-qube.yml b/.github/workflows/sonar-qube.yml index 8d8dba203b..2dd0ed08aa 100644 --- a/.github/workflows/sonar-qube.yml +++ b/.github/workflows/sonar-qube.yml @@ -61,9 +61,20 @@ jobs: - name: Collect issues from the server run: | curl -s -u admin:admin "http://localhost:9000/api/issues/search?componentKeys=local_project" -o issues.json - echo "SonarQube Issues Cmdline Report:" + + echo "::group::SonarQube Issues" jq -r '.issues[] | "File: \(.component):\(.line), Rule: \(.rule), Message: \(.message)"' issues.json | sort - ISSUE_COUNT=$(jq '.issues | length' issues.json) + echo "::endgroup::" + + # Annotate issue on the PR + jq -c '.issues[]' issues.json | while read -r issue; do + FILE=$(echo "$issue" | jq -r '.component | split(":")[1]') + LINE=$(echo "$issue" | jq -r '.line') + MESSAGE=$(echo "$issue" | jq -r '.message') + RULE=$(echo "$issue" | jq -r '.rule') + + echo "::error file=$FILE,line=$LINE,title=$RULE::$MESSAGE" + done if [ "$ISSUE_COUNT" -gt 0 ]; then echo "❌ Build failed: Found $ISSUE_COUNT issues." diff --git a/sonar-project.properties b/sonar-project.properties index 1642d5ff13..66ce6689d7 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -261,7 +261,7 @@ sonar.issue.ignore.multicriteria.f8.ruleKey = java:S899 sonar.issue.ignore.multicriteria.f8.resourceKey = **/BlockingTrafficSource.java -# We use some base Docker images that run as root; changing the default user in these contaiers +# We use some base Docker images that run as root; changing the default user in these containers # doesn't make sense sonar.issue.ignore.multicriteria.d1.ruleKey = docker:S6471 sonar.issue.ignore.multicriteria.d1.resourceKey = **/Dockerfile \ No newline at end of file