feat: add merge-sarif #37

Merged
t.behrendt merged 5 commits from feat-add-merge-sarif into main 2026-02-15 12:07:03 +01:00
Showing only changes of commit 78561ae254 - Show all commits
+15 -10
View File
@@ -24,14 +24,19 @@ runs:
files="${{ inputs.files }}" files="${{ inputs.files }}"
output-file="${{ inputs.output-file }}" output-file="${{ inputs.output-file }}"
# Sarif files are easy to merge. They contain a "runs" array. We just need to concat the runs arrays and write the result to the output file. # Parse YAML list: lines like " - path/to/file" or "- file"
# Collect all the runs from all file_list=$(echo "$files" | sed -n 's/^[[:space:]]*-[[:space:]]*//p' | tr -d '"' | tr -d "'")
runs=()
for file in $files; do
runs+=($(jq -r '.runs' $file))
done
# Write the merged runs to the output file. # Collect all runs from all SARIF files (each run as one compact JSON line)
echo '{"version":"2.1.0","$schema":"https://raw.githubusercontent.com/oasis-tcs/sarif-spec/main/sarif-2.1/schema/sarif-schema-2.1.0.json","runs":[' > $output-file runs_json=$(while IFS= read -r file; do
echo "${runs[@]}" | jq -s '.' >> $output-file [ -z "$file" ] && continue
echo ']}' >> $output-file jq -c '.runs[]?' "$file" 2>/dev/null || true
done <<< "$file_list" | jq -s '.')
# Take first file for version/schema, replace .runs with merged array
first_file=$(echo "$file_list" | head -1)
if [ -z "$first_file" ]; then
echo "No input files given."
exit 1
fi
jq -n --argjson runs "$runs_json" --slurpfile first "$first_file" '$first[0] | .runs = $runs' > "$output-file"