Files
harpia/scripts/release-notes.sh
T

29 lines
816 B
Bash
Executable File

#!/usr/bin/env bash
# Prints release notes for a given tag: extracts the matching CHANGELOG.md
# section, or falls back to the commit log since the previous tag.
#
# scripts/release-notes.sh v1.2.3
set -euo pipefail
tag=${1:?usage: release-notes.sh <tag>}
version=${tag#v}
section=""
if [ -f CHANGELOG.md ]; then
section=$(awk -v head="## [$version]" '
index($0, head) == 1 { found = 1; next }
found && /^## \[/ { exit }
found && /^\[[^]]+\]: / { next }
found { print }
' CHANGELOG.md)
fi
if [ -n "$(printf '%s' "$section" | tr -d '[:space:]')" ]; then
printf '%s\n' "$section"
else
previous=$(git describe --tags --abbrev=0 "$tag^" 2>/dev/null || true)
echo "## Changes${previous:+ since $previous}"
echo
git log --no-merges --format='- %s (%h)' "${previous:+$previous..}$tag"
fi