From d888b88e1a8ed29baa394fd45509a64dd80ef422 Mon Sep 17 00:00:00 2001 From: Jan Date: Sun, 12 May 2024 13:46:11 +0200 Subject: [PATCH] fix: release notes script further tested and fixed --- documentation-guidelines.md | 1 + resources/scripts/release-notes.bash | 39 ++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/documentation-guidelines.md b/documentation-guidelines.md index 4bee5c4..1131fb1 100644 --- a/documentation-guidelines.md +++ b/documentation-guidelines.md @@ -12,6 +12,7 @@ The idea is to get rather automated release notes. To have this as easy as possi - `nonotes:` - for git commits we don't want to see in the release notes - tags for each version, we will output only the change log from the last and second last tag + - you can add tags with `git tag -a -m ""` [resources/scripts/release-notes.bash](resources/scripts/release-notes.bash) is an example bash script to generate the release notes. You can run it with the following command: diff --git a/resources/scripts/release-notes.bash b/resources/scripts/release-notes.bash index 5bd5720..3174fc0 100644 --- a/resources/scripts/release-notes.bash +++ b/resources/scripts/release-notes.bash @@ -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 ""