Files
ARTEX/scripts/extract-changelog-section.sh
BaaRai 1e3c858b4e release: build release body from CHANGELOG section
The release job now checks out the repo and extracts the CHANGELOG.md
section matching the pushed tag (leading v stripped) with
scripts/extract-changelog-section.sh, and passes it as body_path. If the
section is missing it logs a warning and falls back to a generic body
naming the tag and pointing at CHANGELOG.md.

scripts/test-extract-changelog-section.sh covers the found and missing
cases against a fake CHANGELOG in a temp dir; the CI shell job runs it
and shellchecks both scripts.
2026-11-12 12:43:10 +01:00

34 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Print the body of the CHANGELOG section "## [<version>]": the lines after that
# heading up to (not including) the next "## [" heading, with leading and
# trailing blank lines removed. The version is matched literally (no leading v).
# Exit 1 with nothing on stdout when the section is missing or empty.
#
# Usage: scripts/extract-changelog-section.sh <version> [changelog] (default CHANGELOG.md)
set -euo pipefail
if [ $# -lt 1 ] || [ $# -gt 2 ] || [ -z "$1" ]; then
echo "usage: $0 <version> [changelog]" >&2
exit 2
fi
version=$1
changelog=${2:-CHANGELOG.md}
body=$(awk -v head="## [$version]" '
{ sub(/\r$/, "") } # tolerate a CRLF checkout
index($0, "## [") == 1 {
if (found) exit
rest = substr($0, length(head) + 1)
if (substr($0, 1, length(head)) == head && (rest == "" || rest ~ /^[ \t]/)) { found = 1; next }
}
found { print }
' "$changelog")
# Trim leading blank lines ($(...) already drops the trailing ones).
body=$(printf '%s\n' "$body" | sed '/./,$!d')
if [ -z "$body" ]; then
exit 1
fi
printf '%s\n' "$body"