Skip to content

Commit 0d8c451

Browse files
committed
fix
1 parent b6ad390 commit 0d8c451

File tree

3 files changed

+78
-44
lines changed

3 files changed

+78
-44
lines changed

.github/scripts/sarif_nobuild.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env python3
2+
3+
import json
4+
import sys
5+
import os
6+
7+
def process_sarif_file(sarif_file, renamed_files_file):
8+
"""
9+
Process SARIF file to rename files back to .ino and adjust line numbers
10+
"""
11+
# Read the renamed files mapping
12+
with open(renamed_files_file, 'r') as f:
13+
renamed_files = json.load(f)
14+
15+
# Read the SARIF file
16+
with open(sarif_file, 'r') as f:
17+
sarif_data = json.load(f)
18+
19+
# Process each result
20+
if 'runs' in sarif_data and len(sarif_data['runs']) > 0:
21+
results = sarif_data['runs'][0].get('results', [])
22+
23+
for result in results:
24+
if 'locations' in result and len(result['locations']) > 0:
25+
location = result['locations'][0]
26+
27+
if 'physicalLocation' in location:
28+
physical_location = location['physicalLocation']
29+
30+
if 'artifactLocation' in physical_location:
31+
uri = physical_location['artifactLocation'].get('uri')
32+
33+
# Check if this file was originally a .ino file
34+
if uri in renamed_files:
35+
# Rename the file back to .ino
36+
physical_location['artifactLocation']['uri'] = renamed_files[uri]
37+
38+
# Adjust line numbers if they exist
39+
if 'region' in physical_location:
40+
region = physical_location['region']
41+
42+
if 'startLine' in region:
43+
region['startLine'] = max(1, region['startLine'] - 1)
44+
45+
if 'endLine' in region:
46+
region['endLine'] = max(1, region['endLine'] - 1)
47+
48+
# Write the processed SARIF file
49+
with open(sarif_file, 'w') as f:
50+
json.dump(sarif_data, f, indent=2)
51+
52+
def main():
53+
if len(sys.argv) != 3:
54+
print("Usage: python3 sarif_nobuild.py <sarif_file> <renamed_files_file>")
55+
sys.exit(1)
56+
57+
sarif_file = sys.argv[1]
58+
renamed_files_file = sys.argv[2]
59+
60+
# Check if files exist
61+
if not os.path.exists(sarif_file):
62+
print(f"SARIF file not found: {sarif_file}")
63+
sys.exit(1)
64+
65+
if not os.path.exists(renamed_files_file):
66+
print(f"Renamed files mapping not found: {renamed_files_file}")
67+
sys.exit(1)
68+
69+
try:
70+
process_sarif_file(sarif_file, renamed_files_file)
71+
print("SARIF file processed successfully")
72+
except Exception as e:
73+
print(f"Error processing SARIF file: {e}")
74+
sys.exit(1)
75+
76+
if __name__ == "__main__":
77+
main()

.github/scripts/sarif_nobuild.sh

Lines changed: 0 additions & 43 deletions
This file was deleted.

.github/workflows/codeql_nobuild.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ jobs:
7979
if: matrix.language == 'cpp'
8080
run: |
8181
sarif_file="sarif-results/${{ matrix.language }}.sarif"
82-
.github/scripts/sarif_nobuild.sh "$sarif_file" "renamed_files.json"
82+
python3 .github/scripts/sarif_nobuild.py "$sarif_file" "renamed_files.json"
8383
8484
- name: Upload SARIF file
8585
uses: github/codeql-action/upload-sarif@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2

0 commit comments

Comments
 (0)