From b2c729dc7d5af72ea80e88f8936dc3ea82632832 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Wed, 4 Mar 2026 15:36:49 +0100 Subject: [PATCH] utils: fix kernel-upgrade.sh clobbering existing ChangeLog entries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- utils/kernel-upgrade.sh | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/utils/kernel-upgrade.sh b/utils/kernel-upgrade.sh index d5487ebe..b39d434a 100755 --- a/utils/kernel-upgrade.sh +++ b/utils/kernel-upgrade.sh @@ -249,9 +249,8 @@ update_changelog() { # Check if the latest release is UNRELEASED (first release header in file) FIRST_RELEASE=$(grep -m1 "^\[v" doc/ChangeLog.md) if ! echo "$FIRST_RELEASE" | grep -q "\[UNRELEASED\]"; then - log_error "First release section in ChangeLog.md is not UNRELEASED" - log_error "Please create an UNRELEASED section first before running this script" - exit 1 + log_warn "No UNRELEASED section found in ChangeLog.md, skipping changelog update" + return 0 fi # Extract just the UNRELEASED section (from start until next version header) @@ -264,13 +263,22 @@ update_changelog() { sed -i '0,/^- Upgrade \(\*\*\)\?Linux kernel to .*/s//- Upgrade Linux kernel to '"$NEW_VERSION"' (LTS)/' doc/ChangeLog.md log_info "Updated existing kernel version entry to $NEW_VERSION" else - # Add new kernel upgrade entry after first "### Changes" + # Add new kernel upgrade entry after the first "### Changes" in the UNRELEASED section. + # Use getline to peek at the line following "### Changes" so we can preserve it: + # - blank line: print it, then insert kernel entry (normal case) + # - non-blank line: insert kernel entry first, then print the consumed line + # (guards against silently dropping existing entries, e.g. a Buildroot upgrade) awk -v new_line="- Upgrade Linux kernel to $NEW_VERSION (LTS)" ' /^### Changes/ && !done { print getline - if (NF == 0) print - print new_line + if (NF == 0) { + print + print new_line + } else { + print new_line + print + } done=1 next }