| | +#!/usr/bin/env bash |
| | +release_notes() { |
| | + if [ -z "$1" ]; then |
| | + echo "Error: Provide a starting tag." >&2 |
| | + return 1 |
| | + fi |
| | + readonly TAG_BEGAN=$1 |
| | + readonly TAG_ENDED=${2:-$(git describe --abbrev=0 --tags)} |
| | + readonly REPO_URL="https://repo.autonoma.ca/keenwrite.git" |
| | + readonly CURRENT_DATE=$(date +"%B %d, %Y") |
| | + |
| | + if [ -z "$TAG_ENDED" ]; then |
| | + echo "Error: Could not determine end tag." >&2 |
| | + return 1 |
| | + fi |
| | + |
| | + # Get all tags between the two specified tags (inclusive of end, exclusive of start) |
| | + local tags_between |
| | + tags_between=$(git tag --sort=-version:refname --merged="$TAG_ENDED" | \ |
| | + awk "/$TAG_ENDED/{found=1; print} found && /$TAG_BEGAN/{exit} found") |
| | + |
| | + cat << EOF |
| | +# Release Notes |
| | + |
| | +$CURRENT_DATE |
| | + |
| | +Changes between $TAG_BEGAN and $TAG_ENDED. |
| | + |
| | +EOF |
| | + |
| | + # If no intermediate tags, show all changes as one section |
| | + if [ -z "$tags_between" ]; then |
| | + local commits |
| | + commits=$(git log --pretty=format:'* [%h]('$REPO_URL'/commit/%H) -- %s' --reverse "$TAG_BEGAN".."$TAG_ENDED") |
| | + if [ -n "$commits" ]; then |
| | + echo "## $TAG_ENDED" |
| | + echo |
| | + echo "$commits" |
| | + echo |
| | + fi |
| | + return 0 |
| | + fi |
| | + |
| | + # Process each version section (newest first) |
| | + local next_tag="$TAG_ENDED" |
| | + |
| | + # Add the starting tag to the list to ensure we capture everything |
| | + tags_between=$(echo -e "$tags_between\n$TAG_BEGAN") |
| | + |
| | + while IFS= read -r current_tag; do |
| | + [ -z "$current_tag" ] && continue |
| | + |
| | + # Get commits between current_tag and next_tag |
| | + local commits |
| | + commits=$(git log --pretty=format:'* [%h]('$REPO_URL'/commit/%H) -- %s' --reverse "$current_tag".."$next_tag") |
| | + |
| | + if [ -n "$commits" ]; then |
| | + echo "## $next_tag" |
| | + echo |
| | + echo "$commits" |
| | + echo |
| | + fi |
| | + next_tag="$current_tag" |
| | + done <<< "$tags_between" |
| | +} |
| | + |
| | +release_notes "$@" |
| | + |
| | |