Skip to content

Commit d133dc1

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 117a62f commit d133dc1

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
@@ -7,6 +7,8 @@ on:
77
- opened
88
- synchronize
99
- reopened
10+
- labeled
11+
- unlabeled
1012

1113
env:
1214
#
@@ -39,6 +41,7 @@ jobs:
3941
with:
4042
fetch-depth: 0
4143

44+
# NOTE: Keep label name(s) in sync. with `xtask`'s implementation.
4245
- name: Run `cargo xtask changelog …`
4346
run: |
44-
cargo xtask changelog --emit-github-messages "origin/${{ github.event.pull_request.base.ref }}" >> "$GITHUB_STEP_SUMMARY"
47+
cargo xtask changelog --emit-github-messages ${{ contains(github.event.issue.labels.*.name, 'changelog: released entry changed') && '--warn-only' || '' }} "origin/${{ github.event.pull_request.base.ref }}" >> "$GITHUB_STEP_SUMMARY"

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)