Skip to content

Commit b7271f6

Browse files
committed
Fix
1 parent 52296fc commit b7271f6

File tree

1 file changed

+64
-3
lines changed

1 file changed

+64
-3
lines changed

.github/workflows/codeql_nobuild.yml

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,84 @@ jobs:
3939
- name: Process .ino files
4040
if: matrix.language == 'cpp'
4141
run: |
42+
# Create a mapping file to track renamed files
43+
echo "{}" > renamed_files.json
44+
4245
# Find all .ino files and process them
4346
find . -name "*.ino" -type f | while read -r file; do
4447
echo "Processing $file"
4548
49+
# Get the relative path from repository root
50+
rel_path=$(realpath --relative-to=. "$file")
51+
cpp_path="${rel_path%.ino}.cpp"
52+
4653
# Create new .cpp file with Arduino.h include
47-
echo "#include <Arduino.h>" > "${file%.ino}.cpp"
54+
echo "#include <Arduino.h>" > "$cpp_path"
4855
4956
# 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
5161
5262
# Remove the original .ino file
5363
rm "$file"
5464
55-
echo "Converted $file to ${file%.ino}.cpp"
65+
echo "Converted $file to $cpp_path"
5666
done
5767
68+
echo "Renamed files mapping:"
69+
cat renamed_files.json
70+
5871
- name: Run CodeQL Analysis
5972
uses: github/codeql-action/analyze@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2
6073
with:
6174
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

Comments
 (0)