@@ -46,17 +46,32 @@ elif [[ "$OSTYPE" == "msys"* ]] || [[ "$OSTYPE" == "cygwin"* ]]; then
4646 sed -i ' s|/C:/Users/runner/work/codacy-cli-v2/codacy-cli-v2/|/|g' actual.sarif
4747 # Convert Windows paths to forward slashes
4848 sed -i ' s|\\|/|g' actual.sarif
49+
50+ # Windows-specific: Ensure the SARIF file is properly terminated
51+ # Remove any trailing commas and ensure proper JSON structure
52+ sed -i ' s/,\s*$//' actual.sarif
53+ # Ensure the file ends with proper JSON closing brackets
54+ if ! grep -q ' ^}$' actual.sarif; then
55+ echo " }" >> actual.sarif
56+ fi
4957else
5058 # Linux
5159 sed -i ' s|file:///home/runner/work/codacy-cli-v2/codacy-cli-v2/|file:///|g' actual.sarif
5260 sed -i ' s|/home/runner/work/codacy-cli-v2/codacy-cli-v2/|/|g' actual.sarif
5361fi
5462
55-
5663# Sort all fields in both files, handling null rules array
57- echo " 📊 Sorting SARIF outputs..."
58- jq --sort-keys ' if .runs[0].tool.driver.rules == null then . else .runs[0].tool.driver.rules |= sort_by(.id) end' " $EXPECTED_SARIF " > expected.sorted.json || { echo " Failed to sort expected SARIF" ; exit 1; }
59- jq --sort-keys ' if .runs[0].tool.driver.rules == null then . else .runs[0].tool.driver.rules |= sort_by(.id) end' actual.sarif > actual.sorted.json || { echo " Failed to sort actual SARIF" ; exit 1; }
64+ if [[ " $OSTYPE " == " msys" * ]] || [[ " $OSTYPE " == " cygwin" * ]]; then
65+ # Windows-specific: Validate JSON before processing
66+ if ! jq ' .' actual.sarif > /dev/null 2>&1 ; then
67+ echo " Error: Invalid JSON in actual.sarif"
68+ cat actual.sarif
69+ exit 1
70+ fi
71+ fi
72+
73+ jq --sort-keys ' if .runs[0].tool.driver.rules == null then . else .runs[0].tool.driver.rules |= sort_by(.id) end' " $EXPECTED_SARIF " > expected.sorted.json
74+ jq --sort-keys ' if .runs[0].tool.driver.rules == null then . else .runs[0].tool.driver.rules |= sort_by(.id) end' actual.sarif > actual.sorted.json
6075
6176# Normalize paths in both files
6277if [[ " $OSTYPE " == " darwin" * ]]; then
0 commit comments