util/scripts/generate-release-notes.sh

72 lines
2.2 KiB
Bash
Raw Normal View History

#!/bin/bash
# Generate release notes from commits since the last tag
set -e
CURRENT_TAG="${1:-${DRONE_TAG}}"
OUTPUT_FILE="${2:-.build/release-notes.md}"
if [ -z "$CURRENT_TAG" ]; then
echo "Error: Current tag not provided"
exit 1
fi
# Find the previous tag
PREVIOUS_TAG=$(git describe --tags --abbrev=0 "$CURRENT_TAG"^ 2>/dev/null || echo "")
mkdir -p "$(dirname "$OUTPUT_FILE")"
# Start release notes
{
echo "# Release $CURRENT_TAG"
echo ""
if [ -n "$PREVIOUS_TAG" ]; then
echo "**Changes since $PREVIOUS_TAG:**"
echo ""
# Extract commits and group by type (feat, fix, docs, ci, etc.)
git log "$PREVIOUS_TAG..$CURRENT_TAG" --pretty=format:"%s" | while read -r commit; do
# Parse conventional commits
if [[ $commit =~ ^([a-z]+)(\(.+\))?:\ (.+)$ ]]; then
TYPE="${BASH_REMATCH[1]}"
SCOPE="${BASH_REMATCH[2]}"
MESSAGE="${BASH_REMATCH[3]}"
case "$TYPE" in
feat)
echo "- ✨ **Feature**${SCOPE}: $MESSAGE" ;;
fix)
echo "- 🐛 **Fix**${SCOPE}: $MESSAGE" ;;
docs)
echo "- 📖 **Docs**${SCOPE}: $MESSAGE" ;;
ci)
echo "- 🔧 **CI**${SCOPE}: $MESSAGE" ;;
test)
echo "- ✅ **Test**${SCOPE}: $MESSAGE" ;;
refactor)
echo "- ♻️ **Refactor**${SCOPE}: $MESSAGE" ;;
perf)
echo "- ⚡ **Performance**${SCOPE}: $MESSAGE" ;;
*)
echo "- 📝 $commit" ;;
esac
else
echo "- 📝 $commit"
fi
done
else
echo "Initial release"
echo ""
git log "$CURRENT_TAG" --pretty=format:"- 📝 %s" | head -20
fi
echo ""
echo "---"
echo "See [all changes](https://scm.yoorie.de/git/go-lib/util/compare/$PREVIOUS_TAG...$CURRENT_TAG)"
} > "$OUTPUT_FILE"
echo "Release notes generated: $OUTPUT_FILE"
cat "$OUTPUT_FILE"