update: Example script for release notes updated to better output changes for release notes

This commit is contained in:
Jan 2024-05-13 10:13:47 +02:00
parent 6d09a3f60f
commit 439f90cbff

View file

@ -1,40 +1,60 @@
#!/bin/bash
# Check for the "final" flag in command line arguments
finalFlag=false
for arg in "$@"; do
if [[ "$arg" == "final" ]]; then
finalFlag=true
break
fi
done
# Get tags sorted by creation date
tags=$(git tag --sort=creatordate)
# Convert tags into an array using a mapfile or read -a
# Convert tags into an array
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
# Determine the number of tags
len=${#tagArray[@]}
# 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."
# Find the last tag or the last "final" tag based on the flag
if $finalFlag; then
for (( i=len-1; i>=0; i-- )); do
if [[ "${tagArray[i]}" == *"final"* ]]; then
latestTag="${tagArray[i]}"
break
fi
done
if [ -z "$latestTag" ]; then
echo "No 'final' tag found."
exit 1
fi
else
if [ "$len" -gt 0 ]; then
latestTag="${tagArray[$len-1]}"
else
echo "No tags found."
exit 1
fi
fi
# Generate release notes from commits between the two latest tags
# Print release notes
echo ""
echo "Release Notes from $secondLastTag to $latestTag:"
echo "Release Notes from $latestTag to HEAD:"
echo ""
# Separate types of commits
newfeatures=$(git log "$secondLastTag".."$latestTag" --pretty=format:"%s" | grep 'new:' | sed 's/new:/* /g' | sort | uniq)
updatedfeatures=$(git log "$secondLastTag".."$latestTag" --pretty=format:"%s" | grep 'update:' | sed 's/update:/* /g' | sort | uniq)
fixedfeatures=$(git log "$secondLastTag".."$latestTag" --pretty=format:"%s" | grep 'fix:' | sed 's/fix:/* /g' | sort | uniq)
deletedfeatures=$(git log "$secondLastTag".."$latestTag" --pretty=format:"%s" | grep 'delete:' | sed 's/delete:/* /g' | sort | uniq)
# Fetch commit logs from the latest tag to HEAD and categorize them
newfeatures=$(git log "$latestTag"..HEAD --pretty=format:"%s" | grep 'new:' | sed 's/new:/* /g' | sort | uniq)
updatedfeatures=$(git log "$latestTag"..HEAD --pretty=format:"%s" | grep 'update:' | sed 's/update:/* /g' | sort | uniq)
fixedfeatures=$(git log "$latestTag"..HEAD --pretty=format:"%s" | grep 'fix:' | sed 's/fix:/* /g' | sort | uniq)
deletedfeatures=$(git log "$latestTag"..HEAD --pretty=format:"%s" | grep 'delete:' | sed 's/delete:/* /g' | sort | uniq)
# Output formatted commit lists
echo "New Features:"
if [ -z "$newfeatures" ]; then
echo "* No new features."