From 092a29dd8b13c2b04b0b7c259446ab697201dd5e Mon Sep 17 00:00:00 2001 From: David Cole <40234707+DavidArthurCole@users.noreply.github.com> Date: Thu, 26 Sep 2024 03:56:44 -0400 Subject: Backend: Dekekt (#2547) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Linnea Gräf Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Co-authored-by: Cal --- .github/scripts/process_detekt_sarif.sh | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/scripts/process_detekt_sarif.sh (limited to '.github/scripts/process_detekt_sarif.sh') diff --git a/.github/scripts/process_detekt_sarif.sh b/.github/scripts/process_detekt_sarif.sh new file mode 100644 index 000000000..7fb4f7e4e --- /dev/null +++ b/.github/scripts/process_detekt_sarif.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# This script processes the Detekt SARIF file and outputs results in a format +# suitable for annotation in CI/CD systems. + +SARIF_FILE="$1" + +# Check if SARIF file exists +if [ ! -f "$SARIF_FILE" ]; then + echo "SARIF file not found: $SARIF_FILE" + exit 1 +fi + +# Define jq command to parse SARIF file +read -r -d '' jq_command <<'EOF' +.runs[].results[] | +{ + "full_path": .locations[].physicalLocation.artifactLocation.uri | sub("file://$(pwd)/"; ""), + "file_name": (.locations[].physicalLocation.artifactLocation.uri | split("/") | last), + "l": .locations[].physicalLocation, + "level": .level, + "message": .message.text, + "ruleId": .ruleId +} | +( + "::" + (.level) + + " file=" + (.full_path) + + ",line=" + (.l.region.startLine|tostring) + + ",title=" + (.ruleId) + + ",col=" + (.l.region.startColumn|tostring) + + ",endColumn=" + (.l.region.endColumn|tostring) + + "::" + (.message.text) +) +EOF + +# Run jq command to format the output +jq -r "$jq_command" < "$SARIF_FILE" -- cgit