@@ -27,10 +27,11 @@ jobs:
2727 run : |
2828 /home/runner/.opengrep/cli/latest/opengrep --config=r/all --sarif-output=opengrep-results.sarif --verbose .
2929
30- - name : Fix SARIF severity values
30+ - name : Fix SARIF for GitHub compatibility
3131 run : |
3232 python3 << 'EOF'
3333 import json
34+ import hashlib
3435
3536 # Load SARIF file
3637 with open('opengrep-results.sarif', 'r') as f:
@@ -48,19 +49,39 @@ jobs:
4849 'NOTE': '1.0'
4950 }
5051
51- # Fix security-severity values
52+ # Process each run
5253 for run in sarif.get('runs', []):
54+ # Fix rule IDs and security-severity
5355 for rule in run.get('tool', {}).get('driver', {}).get('rules', []):
56+ # Truncate or hash long rule IDs
57+ if 'id' in rule and len(rule['id']) > 255:
58+ original_id = rule['id']
59+ # Keep first 200 chars and add hash of full ID
60+ hash_suffix = hashlib.sha256(original_id.encode()).hexdigest()[:8]
61+ rule['id'] = original_id[:200] + '...' + hash_suffix
62+ # Store original in properties for reference
63+ if 'properties' not in rule:
64+ rule['properties'] = {}
65+ rule['properties']['original-rule-id'] = original_id
66+
67+ # Fix security-severity values
5468 if 'properties' in rule and 'security-severity' in rule['properties']:
5569 severity = rule['properties']['security-severity']
5670 if isinstance(severity, str) and severity.upper() in severity_map:
5771 rule['properties']['security-severity'] = severity_map[severity.upper()]
72+
73+ # Fix result ruleIds to match truncated rule IDs
74+ for result in run.get('results', []):
75+ if 'ruleId' in result and len(result['ruleId']) > 255:
76+ original_id = result['ruleId']
77+ hash_suffix = hashlib.sha256(original_id.encode()).hexdigest()[:8]
78+ result['ruleId'] = original_id[:200] + '...' + hash_suffix
5879
5980 # Save fixed SARIF
6081 with open('opengrep-results.sarif', 'w') as f:
6182 json.dump(sarif, f, indent=2)
6283
63- print("✓ Fixed SARIF severity values ")
84+ print("✓ Fixed SARIF for GitHub compatibility ")
6485 EOF
6586
6687 - name : Upload OpenGrep scan results to GitHub Security tab
0 commit comments