Skip to content

Commit 7158f3a

Browse files
shenxianpengclaude
andcommitted
fix: report dry-run failures as warnings with a verdict line
dry-run zeroed the exit code but still emitted ::error annotations for each failure, so a green step counted errors in the run summary, and log_error_and_exit() prints nothing for a zero exit, so the log ended with no verdict at all. Downgrade the per-failure annotations to ::warning (keeping the rule ID title) and print "commit-check (dry-run): N of M checks failed; not failing the job". Reword the dry-run input description in README and action.yml, which read "exit code is 0; otherwise is 1", to say what it does: failures are reported (summary, PR comment, annotations as warnings) but the job never fails. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018xYa7m3qup5wyN5MaXFgf6
1 parent 8d638ca commit 7158f3a

4 files changed

Lines changed: 43 additions & 3 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ jobs:
116116

117117
### `dry-run`
118118

119-
- **Description**: run checks without failing. exit code is 0; otherwise is 1.
119+
- **Description**: report failures (job summary, PR comment, and annotations
120+
downgraded to warnings) but always exit 0, so the job never fails.
120121
- Default: `false`
121122

122123
### `job-summary`

‎action.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ inputs:
2222
required: false
2323
default: false
2424
dry-run:
25-
description: run checks without failing
25+
description: report failures (summary, PR comment, annotations as warnings) but always exit 0
2626
required: false
2727
default: false
2828
job-summary:

‎main.py‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,11 @@ def render_step_log(results: list[ScopeResult]) -> None:
589589
A failure becomes an ``::error``, a warning a ``::warning`` \u2014 GitHub
590590
renders the two differently, and only the errors count toward the
591591
friendly one-line verdict claiming nothing failed.
592+
593+
Under ``dry-run`` a failure is still reported, but as a ``::warning``:
594+
an ``::error`` annotation on a step that then exits 0 reads as a
595+
contradiction, and the run's error count would claim a failure the job
596+
did not have. The verdict line says the same thing in words.
592597
"""
593598
# The tree is grouped, so it is printed group by group rather than in one
594599
# block: ::group:: and ::endgroup:: have to bracket each section's lines.
@@ -617,9 +622,10 @@ def render_step_log(results: list[ScopeResult]) -> None:
617622
first_line = error.splitlines()[0] if error else "check warning"
618623
warnings.append((_rule_label(check), f"{scope.label}: {first_line}"))
619624

625+
level = "warning" if DRY_RUN_ENABLED else "error"
620626
for title, message in errors:
621627
print(
622-
f"::error title={_annotation_escape(title)}"
628+
f"::{level} title={_annotation_escape(title)}"
623629
f"::{_annotation_escape(message)}"
624630
)
625631
for title, message in warnings:
@@ -628,6 +634,12 @@ def render_step_log(results: list[ScopeResult]) -> None:
628634
f"::{_annotation_escape(message)}"
629635
)
630636

637+
if errors and DRY_RUN_ENABLED:
638+
failed, total = _check_counts(results)
639+
print(
640+
f"commit-check (dry-run): {failed} of {total} checks failed; "
641+
"not failing the job"
642+
)
631643
if not errors:
632644
skipped, warned, total = (
633645
_skip_count(results),

‎main_test.py‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,33 @@ def test_raw_text_fallback_is_printed(self):
873873
self.assertIn("unexpected output", output)
874874
self.assertIn("::error title=commit-check: Branch::", output)
875875

876+
def test_dry_run_downgrades_annotations_and_prints_verdict(self):
877+
"""Dry-run still reports every failure, but nothing may say "error".
878+
879+
The exit code is forced to 0, so an ::error annotation would count
880+
toward the run's error total on a green job, and log_error_and_exit
881+
prints nothing for a zero exit — leaving the log with no verdict.
882+
"""
883+
with patch("main.DRY_RUN_ENABLED", True):
884+
output = self._run([fail_scope("Commit 1/1"), pass_scope("Branch")])
885+
self.assertNotIn("::error", output)
886+
self.assertIn(
887+
"::warning title=CC001 message::Commit 1/1: The commit message should "
888+
"follow Conventional Commits.",
889+
output,
890+
)
891+
self.assertIn(
892+
"commit-check (dry-run): 1 of 2 checks failed; not failing the job",
893+
output,
894+
)
895+
self.assertNotIn("all checks passed", output)
896+
897+
def test_dry_run_without_failures_prints_the_usual_verdict(self):
898+
with patch("main.DRY_RUN_ENABLED", True):
899+
output = self._run([pass_scope("Branch")])
900+
self.assertIn("✔ commit-check: all checks passed", output)
901+
self.assertNotIn("dry-run", output)
902+
876903

877904
class TestRenderJobSummary(unittest.TestCase):
878905
@pin_version

0 commit comments

Comments
 (0)