Skip to content

Commit d82e17a

Browse files
test(CHANGELOG): add --warn-only to cargo xtask changelog
1 parent 949a091 commit d82e17a

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

xtask/src/changelog.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ use xshell::Shell;
33

44
pub(crate) fn check_changelog(shell: Shell, mut args: Arguments) -> anyhow::Result<()> {
55
const CHANGELOG_PATH_RELATIVE: &str = "./CHANGELOG.md";
6+
const WARN_LABEL: &str = "changelog: released entry changed";
67

78
let emit_github_messages = args.contains("--emit-github-messages");
9+
let warn_only = args.contains("--warn-only");
810

911
let from_branch = args
1012
.free_from_str()
@@ -65,11 +67,24 @@ pub(crate) fn check_changelog(shell: Shell, mut args: Arguments) -> anyhow::Resu
6567
eprintln!("{}", hunk.contents);
6668

6769
if emit_github_messages {
70+
let severity = if warn_only { "warning" } else { "error" };
6871
let title = "Released changelog content changed";
69-
let message =
72+
let mut message =
7073
"This PR changes changelog content that is already released.".to_owned();
74+
if !warn_only {
75+
// NOTE: Keep this label name in sync. with CI's branching logic.
76+
message += &format!(
77+
concat!(
78+
" ",
79+
"If you know what you're doing, ",
80+
"you can add the `{}` label ",
81+
"and reduce this error's severity to a warning."
82+
),
83+
WARN_LABEL
84+
);
85+
}
7186
println!(
72-
"::error file=CHANGELOG.md,line={},endLine={},title={title}::{message}",
87+
"::{severity} file=CHANGELOG.md,line={},endLine={},title={title}::{message}",
7388
hunk.change_start_line_num, hunk.change_end_line_num,
7489
)
7590
}
@@ -82,7 +97,12 @@ pub(crate) fn check_changelog(shell: Shell, mut args: Arguments) -> anyhow::Resu
8297
"one or more checks against `{}` failed; see above for details",
8398
CHANGELOG_PATH_RELATIVE,
8499
);
85-
Err(anyhow::Error::msg(msg))
100+
if warn_only {
101+
log::warn!("{msg}");
102+
Ok(())
103+
} else {
104+
Err(anyhow::Error::msg(msg))
105+
}
86106
} else {
87107
Ok(())
88108
}

xtask/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Commands:
5353
`<to_commit>` is the tip of the `git diff` that will be used for checking (1).
5454
5555
--emit-github-messages Emit GitHub workflow commands for nice integrations like error reporting in PR views.
56+
--warn-only Only reports issues as warnings, rather than reporting errors and forcing a non-zero exit code.
5657
5758
miri
5859
Run all miri-compatible tests under miri. Requires a nightly toolchain

0 commit comments

Comments
 (0)