feat(cli): add --fail-on CI/CD gate, --help/--version, robust arg parsing#5
Open
dmchaledev wants to merge 1 commit into
Open
feat(cli): add --fail-on CI/CD gate, --help/--version, robust arg parsing#5dmchaledev wants to merge 1 commit into
dmchaledev wants to merge 1 commit into
Conversation
The README markets sbom-diff as "perfect for CI/CD gates," but the CLI always exited 0, so it could not actually fail a build. This adds a --fail-on flag that exits non-zero when the diff matches one or more conditions (any/added/removed/upgraded/major/new-cves or a CVE severity threshold), implemented as a pure, tested evaluateGate() helper that is also exported from the public API. Also: - Add --help and --version flags. - Validate --format and --fail-on values with clear error messages. - Fix latent arg parsing so value flags before the file paths no longer get misread as positional file arguments. - Add 13 gate tests and document the feature in the README.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The README markets
sbom-diffas "perfect for CI/CD gates and audit trails," but the CLI always exited0regardless of what the diff found. That means it could not actually gate anything — a pipeline had no way to fail a build when a new critical CVE or a major-version bump was introduced. This PR delivers that keystone capability.What changed
--fail-on <conditions>— exit non-zero when the diff matches one or more comma-separated conditions:any,added,removed,upgraded,major,new-cveslow/medium/high/critical(fires on any new CVE at or above that level)Gate failed (--fail-on critical,major): 1 new CVE(s) at or above critical severity; 1 major version bump(s).evaluateGate(report, conditions)helper (plusparseGateConditions), now exported from the public API for programmatic use.--helpand--versionflags.--formatand--fail-onwith actionable error messages instead of a silent cast / generic throw.--format markdown old.json new.json) were previously misread as positional file arguments. Positional collection now skips value flags and their consumed tokens.Usage
# Fail the pipeline if a new critical CVE or a major version bump appears npx @hailbytes/sbom-diff old.json new.json --fail-on critical,majorTesting
src/__tests__/gate.test.ts(13 cases covering parsing, severity thresholds, major-bump detection, multi-condition reasons, and unknown-severity handling).lint,typecheck, andbuildall clean.0), triggered gates (1), invalid conditions/formats (1), and flags placed before file paths.No dependency or runtime-behavior changes for existing invocations —
--fail-onis opt-in and the default output path is unchanged.https://claude.ai/code/session_01YSnNaUitHirz9vbcjQQCjC
Generated by Claude Code