diff --git a/resources/scripts/release-notes.bash b/resources/scripts/release-notes.bash index abf8a37..6337687 100644 --- a/resources/scripts/release-notes.bash +++ b/resources/scripts/release-notes.bash @@ -1,43 +1,63 @@ #!/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]} +# 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 - echo "Not enough tags found. Need at least two." - exit 1 + 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." + echo "* No new features." else echo "$newfeatures" fi @@ -45,7 +65,7 @@ echo "" echo "Updated Features:" if [ -z "$updatedfeatures" ]; then - echo "* No updated features." + echo "* No updated features." else echo "$updatedfeatures" fi @@ -53,7 +73,7 @@ echo "" echo "Fixed Features:" if [ -z "$fixedfeatures" ]; then - echo "* No fixed features." + echo "* No fixed features." else echo "$fixedfeatures" fi @@ -61,7 +81,7 @@ echo "" echo "Deleted Features:" if [ -z "$deletedfeatures" ]; then - echo "* No deleted features." + echo "* No deleted features." else echo "$deletedfeatures" fi