#!/usr/bin/env bash # SPDX-FileCopyrightText: 2026 Lukas Schaefer # SPDX-License-Identifier: AGPL-3.0-or-later # # Print the newest Keep a Changelog version section (skips Unreleased). # Usage: extract-latest-changelog.sh [CHANGELOG.md] set -euo pipefail changelog="${1:-CHANGELOG.md}" if [[ ! -f "${changelog}" ]]; then echo "changelog not found: ${changelog}" >&2 exit 1 fi notes="$(awk ' BEGIN { printing = 0 } # Version headings are "## …"; subsection headings are "### …". /^##[ \t]/ { if ($0 ~ /^##[ \t]+\[?[Uu]nreleased\]?/) { printing = 0 next } if (printing) { exit } printing = 1 } printing { print } ' "${changelog}")" if [[ -z "${notes}" ]]; then echo "no version section found in ${changelog}" >&2 exit 1 fi # Trim trailing blank lines. printf '%s\n' "${notes}" | awk ' NF { seen = 1 } seen { lines[++n] = $0 } END { while (n > 0 && lines[n] ~ /^[ \t]*$/) { n-- } for (i = 1; i <= n; i++) { print lines[i] } } '