Files
owlen/scripts/release-notes.sh

58 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
CHANGELOG="${REPO_ROOT}/CHANGELOG.md"
TAG="${1:-}"
OUTPUT="${2:-}"
if [[ -z "${TAG}" ]]; then
echo "usage: $0 <tag> [output-file]" >&2
exit 1
fi
TAG="${TAG#v}"
TAG="${TAG#V}"
if [[ ! -f "${CHANGELOG}" ]]; then
echo "error: CHANGELOG.md not found at ${CHANGELOG}" >&2
exit 1
fi
NOTES=$(TAG="${TAG}" CHANGELOG_PATH="${CHANGELOG}" python - <<'PY'
import os
import re
import sys
from pathlib import Path
changelog_path = Path(os.environ['CHANGELOG_PATH'])
tag = os.environ['TAG']
text = changelog_path.read_text(encoding='utf-8')
pattern = re.compile(rf'^## \[{re.escape(tag)}\]\s*(?:-.*)?$', re.MULTILINE)
match = pattern.search(text)
if not match:
sys.stderr.write(f"No changelog section found for tag {tag}.\n")
sys.exit(1)
start = match.end()
rest = text[start:]
next_heading = re.search(r'^## \[', rest, re.MULTILINE)
section = rest[:next_heading.start()] if next_heading else rest
lines = [line.rstrip() for line in section.strip().splitlines()]
print('\n'.join(lines))
PY
)
if [[ -z "${NOTES}" ]]; then
echo "error: no content generated for tag ${TAG}" >&2
exit 1
fi
if [[ -n "${OUTPUT}" ]]; then
printf '%s\n' "${NOTES}" > "${OUTPUT}"
else
printf '%s\n' "${NOTES}"
fi