Skip to content

Commit b6ad390

Browse files
committed
fix
1 parent b7271f6 commit b6ad390

File tree

2 files changed

+44
-35
lines changed

2 files changed

+44
-35
lines changed

.github/scripts/sarif_nobuild.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
3+
# This script is used to process the SARIF file to rename files back to .ino and adjust line numbers
4+
5+
# Get the SARIF file and the renamed files mapping
6+
sarif_file=$1
7+
renamed_files_file=$2
8+
9+
# Read the renamed files mapping
10+
renamed_files=$(cat $renamed_files_file)
11+
12+
# Check if files exist
13+
if [ ! -f "$sarif_file" ] || [ ! -f "$renamed_files_file" ]; then
14+
echo "SARIF file or renamed files mapping not found, skipping processing"
15+
exit 0
16+
fi
17+
18+
echo "Processing SARIF file: $sarif_file"
19+
20+
# Create a backup of the original SARIF
21+
cp "$sarif_file" "${sarif_file}.backup"
22+
23+
# Process the SARIF file to rename files back to .ino and adjust line numbers
24+
jq --argjson renamed "$renamed_files" '
25+
.runs[0].results |= map(
26+
if .locations[0].physicalLocation.artifactLocation.uri in $renamed then
27+
.locations[0].physicalLocation.artifactLocation.uri = $renamed[.locations[0].physicalLocation.artifactLocation.uri] |
28+
if .locations[0].physicalLocation.region.startLine then
29+
.locations[0].physicalLocation.region.startLine = (.locations[0].physicalLocation.region.startLine - 1)
30+
else .
31+
end |
32+
if .locations[0].physicalLocation.region.endLine then
33+
.locations[0].physicalLocation.region.endLine = (.locations[0].physicalLocation.region.endLine - 1)
34+
else .
35+
end
36+
else .
37+
end
38+
)' "$sarif_file" > "${sarif_file}.processed"
39+
40+
# Replace the original SARIF with the processed version
41+
mv "${sarif_file}.processed" "$sarif_file"
42+
43+
echo "SARIF file processed successfully"

.github/workflows/codeql_nobuild.yml

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -79,41 +79,7 @@ jobs:
7979
if: matrix.language == 'cpp'
8080
run: |
8181
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
82+
.github/scripts/sarif_nobuild.sh "$sarif_file" "renamed_files.json"
11783
11884
- name: Upload SARIF file
11985
uses: github/codeql-action/upload-sarif@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2

0 commit comments

Comments
 (0)