@@ -39,23 +39,84 @@ jobs:
39
39
- name : Process .ino files
40
40
if : matrix.language == 'cpp'
41
41
run : |
42
+ # Create a mapping file to track renamed files
43
+ echo "{}" > renamed_files.json
44
+
42
45
# Find all .ino files and process them
43
46
find . -name "*.ino" -type f | while read -r file; do
44
47
echo "Processing $file"
45
48
49
+ # Get the relative path from repository root
50
+ rel_path=$(realpath --relative-to=. "$file")
51
+ cpp_path="${rel_path%.ino}.cpp"
52
+
46
53
# Create new .cpp file with Arduino.h include
47
- echo "#include <Arduino.h>" > "${file%.ino}.cpp "
54
+ echo "#include <Arduino.h>" > "$cpp_path "
48
55
49
56
# Append the original content
50
- cat "$file" >> "${file%.ino}.cpp"
57
+ cat "$file" >> "$cpp_path"
58
+
59
+ # Update the mapping file
60
+ jq --arg ino "$rel_path" --arg cpp "$cpp_path" '. += {($cpp): $ino}' renamed_files.json > temp.json && mv temp.json renamed_files.json
51
61
52
62
# Remove the original .ino file
53
63
rm "$file"
54
64
55
- echo "Converted $file to ${file%.ino}.cpp "
65
+ echo "Converted $file to $cpp_path "
56
66
done
57
67
68
+ echo "Renamed files mapping:"
69
+ cat renamed_files.json
70
+
58
71
- name : Run CodeQL Analysis
59
72
uses : github/codeql-action/analyze@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2
60
73
with :
61
74
category : " Analysis: ${{ matrix.language }}"
75
+ output : sarif-results
76
+ upload : failure-only
77
+
78
+ - name : Process SARIF file
79
+ if : matrix.language == 'cpp'
80
+ run : |
81
+ sarif_file="sarif-results/${{ matrix.language }}.sarif"
82
+
83
+ if [ -f "$sarif_file" ] && [ -f "renamed_files.json" ]; then
84
+ echo "Processing SARIF file: $sarif_file"
85
+
86
+ # Read the renamed files mapping
87
+ renamed_files=$(cat renamed_files.json)
88
+
89
+ # Create a backup of the original SARIF
90
+ cp "$sarif_file" "${sarif_file}.backup"
91
+
92
+ # Process the SARIF file to rename files back to .ino and adjust line numbers
93
+ jq --argjson renamed "$renamed_files" '
94
+ .runs[0].results |= map(
95
+ if .locations[0].physicalLocation.artifactLocation.uri in $renamed then
96
+ .locations[0].physicalLocation.artifactLocation.uri = $renamed[.locations[0].physicalLocation.artifactLocation.uri] |
97
+ if .locations[0].physicalLocation.region.startLine then
98
+ .locations[0].physicalLocation.region.startLine = (.locations[0].physicalLocation.region.startLine - 1)
99
+ else .
100
+ end |
101
+ if .locations[0].physicalLocation.region.endLine then
102
+ .locations[0].physicalLocation.region.endLine = (.locations[0].physicalLocation.region.endLine - 1)
103
+ else .
104
+ end
105
+ else .
106
+ end
107
+ )
108
+ ' "$sarif_file" > "${sarif_file}.processed"
109
+
110
+ # Replace the original SARIF with the processed version
111
+ mv "${sarif_file}.processed" "$sarif_file"
112
+
113
+ echo "SARIF file processed successfully"
114
+ else
115
+ echo "SARIF file or renamed files mapping not found, skipping processing"
116
+ fi
117
+
118
+ - name : Upload SARIF file
119
+ uses : github/codeql-action/upload-sarif@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2
120
+ with :
121
+ sarif_file : sarif-results/${{ matrix.language }}.sarif
122
+ category : " Analysis: ${{ matrix.language }}"
0 commit comments