Skip to content

Commit 48d2f1e

Browse files
chandrur44claude
andcommitted
Merge image SARIF runs into a single run to satisfy Code Scanning
GitHub Code Scanning (since 2025-07-21) rejects SARIF files that contain multiple runs under the same category. Previously we appended the bait run to the real run; now we merge results + rules into one run. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent e652eef commit 48d2f1e

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

.github/workflows/security.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,27 @@ jobs:
149149
run: |
150150
python - <<'PY'
151151
import json, pathlib
152+
152153
real = json.loads(pathlib.Path("trivy-image.sarif").read_text())
153154
bait = json.loads(pathlib.Path("trivy-image-bait.sarif").read_text())
154-
real["runs"].extend(bait.get("runs", []))
155-
for run in real.get("runs", []):
156-
run.setdefault("tool", {}).setdefault("driver", {})["name"] = "Trivy Image Scanner"
155+
156+
# Merge both scans into a SINGLE run (not multiple runs).
157+
# GitHub Code Scanning rejects multiple runs in one SARIF under
158+
# the same category as of 2025-07-21.
159+
target_run = real["runs"][0]
160+
target_rules = target_run.setdefault("tool", {}).setdefault("driver", {}).setdefault("rules", [])
161+
existing_rule_ids = {r.get("id") for r in target_rules}
162+
163+
for run in bait.get("runs", []):
164+
for rule in run.get("tool", {}).get("driver", {}).get("rules", []):
165+
if rule.get("id") not in existing_rule_ids:
166+
target_rules.append(rule)
167+
existing_rule_ids.add(rule.get("id"))
168+
target_run.setdefault("results", []).extend(run.get("results", []))
169+
170+
target_run["tool"]["driver"]["name"] = "Trivy Image Scanner"
171+
real["runs"] = [target_run]
172+
157173
pathlib.Path("trivy-image.sarif").write_text(json.dumps(real))
158174
PY
159175

0 commit comments

Comments
 (0)