#!/bin/sh
set -eu

if [ "$#" -ne 1 ]; then
    echo "Usage:" >&2
    echo "\t$0 <version>" >&2
    exit 1
fi

PROJECT_ROOT="$(dirname $(dirname $(realpath $0)))"
CHANGELOG="$PROJECT_ROOT/CHANGELOG.md"

VERSION="$1"

# remove -suffix modifiers; they will not be in the changelog
VERSION_LOOKUP="${VERSION%-*}"

sed -n \
    -e "s/^## $VERSION_LOOKUP (.*/# Postmill $VERSION/" \
    -e "/^# Postmill $VERSION\$/,/^## /{/^## /!p;}" \
    "$CHANGELOG"
