Skip to content

Commit adaa7a4

Browse files
WIP: test(CHANGELOG): add changelog: released entry changed label escape hatch
TODO: check for label in action, plumb option to still succeed? TODO: test it out TODO: docs
1 parent 5170ed9 commit adaa7a4

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

.github/workflows/changelog.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ on:
99
- opened
1010
- synchronize
1111
- reopened
12+
- labeled
13+
- unlabeled
1214

1315
env:
1416
#
@@ -41,6 +43,7 @@ jobs:
4143
with:
4244
fetch-depth: 0
4345

46+
# NOTE: Keep label name(s) in sync. with `xtask`'s implementation.
4447
- name: Run `cargo xtask changelog …`
4548
run: |
46-
cargo --quiet xtask changelog --emit-github-messages "origin/${{ github.event.pull_request.base.ref }}" 2> >(tee --append "$GITHUB_STEP_SUMMARY" >&2)
49+
cargo --quiet xtask changelog --emit-github-messages "origin/${{ github.event.pull_request.base.ref }}" ${{ contains(github.event.pull_request.labels.*.name, 'changelog: released entry changed') && '--warn-only' || '' }} 2> >(tee --append "$GITHUB_STEP_SUMMARY" >&2)

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+
"\n\n",
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
}

0 commit comments

Comments
 (0)