fix: release notes script further tested and fixed

This commit is contained in:
Jan 2024-05-12 13:46:11 +02:00
parent 783bfb47dc
commit d888b88e1a
2 changed files with 29 additions and 11 deletions

View file

@ -3,22 +3,39 @@
# Get tags sorted by creation date
tags=$(git tag --sort=creatordate)
# Convert tags into an array using IFS
IFS=$'\n' tagArray=("$tags")
# Convert tags into an array using a mapfile or read -a
if [[ $(echo "$BASH_VERSION" | cut -d. -f1) -ge 4 ]]; then
# For Bash 4 and newer
readarray -t tagArray <<< "$tags"
else
# For older Bash versions like the default on macOS
IFS=$'\n' read -d '' -ra tagArray <<< "$tags"
fi
# Get the number of tags
# Determine the number of tags
len=${#tagArray[@]}
# Extract the last and second last tags based on length
latestTag=${tagArray[$len-1]}
secondLastTag=${tagArray[$len-2]}
# Check if the tags are assigned correctly
if [ -z "$latestTag" ] || [ -z "$secondLastTag" ]; then
echo "Not enough tags found."
# Get the last two tags if there are at least two tags
if [ "$len" -gt 1 ]; then
latestTag=${tagArray[$len-1]}
secondLastTag=${tagArray[$len-2]}
else
echo "Not enough tags found. Need at least two."
exit 1
fi
# Generate release notes from commits between the two latest tags
echo ""
echo "Release Notes from $secondLastTag to $latestTag:"
git log "$secondLastTag".."$latestTag" --pretty=format:"%s" | grep -E 'feature:|fix:' | sort | uniq | sed -e 's/feature:/\nNew Feature:/g' -e 's/fix:/\nFix:/g'
echo ""
# Separate features and fixes
features=$(git log "$secondLastTag".."$latestTag" --pretty=format:"%s" | grep 'feature:' | sed 's/feature:/* /g' | sort | uniq)
fixes=$(git log "$secondLastTag".."$latestTag" --pretty=format:"%s" | grep 'fix:' | sed 's/fix:/* /g' | sort | uniq)
echo "New Features:"
echo "$features"
echo ""
echo "Fixes:"
echo "$fixes"
echo ""