Skip to content

Commit 91af895

Browse files
committed
utils: fix kernel-upgrade.sh clobbering existing ChangeLog entries
The awk insertion path used getline to peek at the line right after the "### Changes", but only printed it when NF == 0 (blank line). If the section already had a non-blank entry (e.g. a Buildroot upgrade line), getline consumed it silently and the kernel line was written in its place. Fix by adding the missing else branch so the consumed line is always re-emitted — blank lines before the new entry, non-blank lines after it. Also demote the missing-UNRELEASED guard from exit 1 to a warning with return 0, so the workflow doesn't abort when a new release cycle hasn't had its ChangeLog section opened yet. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
1 parent fc28acb commit 91af895

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

utils/kernel-upgrade.sh

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,8 @@ update_changelog() {
249249
# Check if the latest release is UNRELEASED (first release header in file)
250250
FIRST_RELEASE=$(grep -m1 "^\[v" doc/ChangeLog.md)
251251
if ! echo "$FIRST_RELEASE" | grep -q "\[UNRELEASED\]"; then
252-
log_error "First release section in ChangeLog.md is not UNRELEASED"
253-
log_error "Please create an UNRELEASED section first before running this script"
254-
exit 1
252+
log_warn "No UNRELEASED section found in ChangeLog.md, skipping changelog update"
253+
return 0
255254
fi
256255

257256
# Extract just the UNRELEASED section (from start until next version header)
@@ -264,13 +263,22 @@ update_changelog() {
264263
sed -i '0,/^- Upgrade \(\*\*\)\?Linux kernel to .*/s//- Upgrade Linux kernel to '"$NEW_VERSION"' (LTS)/' doc/ChangeLog.md
265264
log_info "Updated existing kernel version entry to $NEW_VERSION"
266265
else
267-
# Add new kernel upgrade entry after first "### Changes"
266+
# Add new kernel upgrade entry after the first "### Changes" in the UNRELEASED section.
267+
# Use getline to peek at the line following "### Changes" so we can preserve it:
268+
# - blank line: print it, then insert kernel entry (normal case)
269+
# - non-blank line: insert kernel entry first, then print the consumed line
270+
# (guards against silently dropping existing entries, e.g. a Buildroot upgrade)
268271
awk -v new_line="- Upgrade Linux kernel to $NEW_VERSION (LTS)" '
269272
/^### Changes/ && !done {
270273
print
271274
getline
272-
if (NF == 0) print
273-
print new_line
275+
if (NF == 0) {
276+
print
277+
print new_line
278+
} else {
279+
print new_line
280+
print
281+
}
274282
done=1
275283
next
276284
}

0 commit comments

Comments
 (0)