diff --git a/CHANGELOG.md b/CHANGELOG.md index c71df7e..51e3e5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,14 @@ All notable changes to this project are documented here, following ## [Unreleased] +### Fixed + +- `sdlc ci` and `sdlc tiers` now name the push verdicts a repo took out of + ci with `[tool.sdlc.push] skip`, as one line: + `sdlc ci: not run, skipped in [tool.sdlc.push]: lint, codeql` (#50). + Before, a skipped verdict was simply absent, so a green ci could not be + told from one that opted out. + ## [0.7.1] - 2026-11-17 ### Changed diff --git a/sdlc b/sdlc index e4f5488..660beac 100755 --- a/sdlc +++ b/sdlc @@ -296,6 +296,23 @@ def resolve(cfg: dict, command: str) -> list[str]: return out +def push_skips(cfg: dict) -> list[str]: + """The push verdicts ci does not run because [tool.sdlc.push] skips them. + + That skip is the only way a repo takes a verdict out of ci, and a verdict + that is not run is otherwise just absent: a green `sdlc ci` read the same + whether the repo ran lint or opted out of it (python-sdlc#50). + """ + drop = set(names(block(cfg, "push").get("skip"), "[tool.sdlc.push] skip")) + ci = resolve(cfg, "ci") + return [c for c in DEFAULTS["push"] if c in drop and c not in CI_EXCLUDES and c not in ci] + + +def push_skip_line(cfg: dict) -> str | None: + gone = push_skips(cfg) + return f"sdlc ci: not run, skipped in [tool.sdlc.push]: {', '.join(gone)}" if gone else None + + def check_settings(cfg: dict, name: str) -> dict: """A check's own table, wherever it is written. Names are unique.""" found = [ @@ -469,6 +486,10 @@ def t_plan(target: str) -> int: for check in checks: if check not in BUILTINS and kind_of(cfg, check) is None: cannot(f"unknown check: {check}") + # stderr, because stdout is the plan the launcher parses. + line = push_skip_line(cfg) if target == "ci" else None + if line: + print(line, file=sys.stderr) lanes = lane_of(cfg, checks) for check in checks: lane = plain(lanes[check], "a lane name") @@ -495,6 +516,9 @@ def t_tiers() -> int: print(f" {check}{note}") if parallel: print(f" {len(set(lanes.values()))} lanes, run at the same time") + line = push_skip_line(cfg) if command == "ci" else None + if line: + print(f" {line}") if skipped(): print(f"\nSDLC_SKIP is skipping: {', '.join(sorted(skipped()))}") return CLEAN diff --git a/tests/test_plan.py b/tests/test_plan.py index 8796335..c0c6ad7 100644 --- a/tests/test_plan.py +++ b/tests/test_plan.py @@ -413,6 +413,46 @@ def plan_of(target: str, pyproject: str, **env) -> list[list[str]]: return [line.split("\t") for line in buf.getvalue().splitlines()] +# python-sdlc#50: a push skip is the only way a verdict leaves ci, so ci and +# tiers say so; otherwise a green ci reads the same whether lint ran or not. +check("no push skip, nothing to report", S.push_skips(empty) == []) +check( + "a push skip is named, in push order", + S.push_skips({"push": {"skip": ["codeql", "lint"]}}) == ["lint", "codeql"], +) +check( + "the reviewers ci never runs are not named", + S.push_skips({"push": {"skip": ["gatehouse", "mypy"]}}) == ["mypy"], +) +check( + "a verdict ci adds back is not named", + S.push_skips({"push": {"skip": ["lint"]}, "ci": {"checks": ["lint"]}}) == [], +) + + +def stderr_and_stdout(fn, target: str | None, pyproject: str) -> tuple[str, str]: + with tempfile.TemporaryDirectory() as root: + Path(root, "pyproject.toml").write_text(pyproject) + S.REPO = Path(root) + out, err = io.StringIO(), io.StringIO() + with contextlib.redirect_stdout(out), contextlib.redirect_stderr(err): + fn(*([target] if target else [])) + return err.getvalue(), out.getvalue() + + +SKIPS = '[tool.sdlc.push]\nskip = ["lint", "codeql"]\n' +NAMED = "sdlc ci: not run, skipped in [tool.sdlc.push]: lint, codeql" +err, out = stderr_and_stdout(S.t_plan, "ci", SKIPS) +check("sdlc ci names its push skips once", err.splitlines() == [NAMED], err) +check("the plan itself stays clean", NAMED not in out, out) +err, _ = stderr_and_stdout(S.t_plan, "push", SKIPS) +check("only ci names them", err == "", err) +err, _ = stderr_and_stdout(S.t_plan, "ci", "[tool.ruff]\n") +check("a repo that skips nothing hears nothing", err == "", err) +_, out = stderr_and_stdout(S.t_tiers, None, SKIPS) +check("sdlc tiers prints the same line", f" {NAMED}" in out.splitlines(), out) + + TRENTINA = """ [project] name = "fx"