|
| 1 | +# Summary JSON CI cookbook |
| 2 | + |
| 3 | +This page shows how to consume `--summary-json PATH` in CI without changing the `sbom-diff-risk` analysis model. |
| 4 | + |
| 5 | +`--summary-json` writes a compact machine-readable JSON object. It is the same object as `report.json["summary"]`, and is useful for CI dashboards, job summaries, and small local gates where a repository wants to set its own thresholds. |
| 6 | + |
| 7 | +## Minimal command |
| 8 | + |
| 9 | +```bash |
| 10 | +sbom-diff-risk compare \ |
| 11 | + --before examples/cdx_before.json \ |
| 12 | + --after examples/cdx_after.json \ |
| 13 | + --out-json outputs/report.json \ |
| 14 | + --summary-json outputs/summary.json |
| 15 | +``` |
| 16 | + |
| 17 | +The full report remains available at `outputs/report.json`. The compact summary-only object is written to `outputs/summary.json`. |
| 18 | + |
| 19 | +## Python consumer |
| 20 | + |
| 21 | +This example reads the summary and applies an explicit local threshold. The threshold is chosen by the caller; it is not a built-in package safety verdict. |
| 22 | + |
| 23 | +```python |
| 24 | +import json |
| 25 | +from pathlib import Path |
| 26 | + |
| 27 | +summary = json.loads(Path("outputs/summary.json").read_text(encoding="utf-8")) |
| 28 | + |
| 29 | +added = summary["added"] |
| 30 | +removed = summary["removed"] |
| 31 | +changed = summary["changed"] |
| 32 | +risk_counts = summary["risk_counts"] |
| 33 | + |
| 34 | +print(f"added={added} removed={removed} changed={changed}") |
| 35 | +print(f"risk_counts={risk_counts}") |
| 36 | + |
| 37 | +max_new_packages = 2 |
| 38 | +if risk_counts.get("new_package", 0) > max_new_packages: |
| 39 | + raise SystemExit(f"new_package count exceeds local threshold: {max_new_packages}") |
| 40 | +``` |
| 41 | + |
| 42 | +## PowerShell consumer |
| 43 | + |
| 44 | +This example uses `ConvertFrom-Json` and applies the same kind of explicit local threshold. |
| 45 | + |
| 46 | +```powershell |
| 47 | +$summary = Get-Content outputs/summary.json -Raw | ConvertFrom-Json |
| 48 | +
|
| 49 | +$added = $summary.added |
| 50 | +$removed = $summary.removed |
| 51 | +$changed = $summary.changed |
| 52 | +$newPackageCount = $summary.risk_counts.new_package |
| 53 | +
|
| 54 | +Write-Output "added=$added removed=$removed changed=$changed" |
| 55 | +Write-Output "new_package=$newPackageCount" |
| 56 | +
|
| 57 | +$maxNewPackages = 2 |
| 58 | +if ($newPackageCount -gt $maxNewPackages) { |
| 59 | + throw "new_package count exceeds local threshold: $maxNewPackages" |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +## Compatibility notes |
| 64 | + |
| 65 | +- `summary.policy` appears only when policy evaluation is applied. |
| 66 | +- `summary.enrichment` appears only when PyPI or Scorecard enrichment is used. |
| 67 | +- `unchanged` is absent because unchanged components are not modeled. |
| 68 | +- Absence of `summary.policy` or `summary.enrichment` means the feature was not used, not that it failed. |
| 69 | +- Consumers should treat new unrecognized fields as additive data. |
| 70 | + |
| 71 | +## Non-claims |
| 72 | + |
| 73 | +- `sbom-diff-risk` is not a CVE scanner. |
| 74 | +- The summary is not a dependency safety oracle. |
| 75 | +- Default runs do not perform hidden network access. |
| 76 | +- Production PyPI publishing remains intentionally deferred. |
0 commit comments