#!/usr/bin/env bash # Print the CHANGELOG.md section for one version on stdout. # # Usage: tools/release_notes.sh [changelog] # tools/release_notes.sh 0.7.1 # section between "## 0.7.1 ..." # # and the next "## " heading # # A missing or empty section is an error: the release workflow uses this to # publish release notes, and every release ships with real, written notes — # failing here fails the release, which is the point. set -eu [ $# -ge 1 ] || { echo "usage: $0 [changelog]" >&2; exit 2; } version=$1 changelog=${2:-CHANGELOG.md} [ -r "$changelog" ] || { echo "cannot read $changelog" >&2; exit 2; } notes=$(awk -v v="$version" ' $1 == "##" { grab = ($2 == v); next } grab { print } ' "$changelog") # Trim leading/trailing blank lines so the release body starts with content. notes=$(printf '%s' "$notes" | sed -e '/./,$!d' | sed -e :a -e '/^\n*$/{$d;N;ba' -e '}') [ -n "$notes" ] || { echo "no CHANGELOG.md section for version $version -- write one before tagging" >&2 exit 1 } printf '%s\n' "$notes"