Skip to content

Commit

Permalink
fix: add date to each release in the CHANGELOG.txt file
Browse files Browse the repository at this point in the history
-> Issue :  codazoda#49
  • Loading branch information
dkp-consult committed Aug 2, 2024
1 parent 710195f commit 9dd2273
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions release.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# Describe this script
echo This script releases a feature branch by merging the current branch into
echo master, tagging a new version, and pushing master up to origin.
#!/bin/bash

echo "This script releases a feature branch by merging the current branch into"
echo "master, tagging a new version, and pushing master up to origin."
echo

# Grab the current version number
CURRENT=`tail -1 version.txt`
NEXT=`tail -1 version.txt | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{$NF=sprintf("%0*d", length($NF), ($NF+1)); print}'`
CURRENT=`tail -1 version.txt | awk '{print $1}'`
NEXT=`tail -1 version.txt | awk '{print $1}' | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{$NF=sprintf("%0*d", length($NF), ($NF+1)); print}'`
FEAT=`git rev-parse --abbrev-ref HEAD`
DATE=`date +%Y-%m-%d`

# Show additional detail and wait for confirmation
echo Current version: $CURRENT
echo
echo To change the major or minor version number:
echo "Current version: $CURRENT"
echo
echo "To change the major or minor version number:"
echo " echo x.x.0 >> version.txt"
echo
echo Releasing $FEAT branch as v$NEXT
echo "Releasing $FEAT branch as v$NEXT"
echo
read -p "Press Enter to continue or Ctrl-C to stop"

Expand All @@ -23,15 +25,15 @@ if [ "$FEAT" != "master" ]; then

# Verify we don't have uncommitted changes
if [[ -n $(git status -s) ]]; then
echo Error: There are uncommitted changes.
echo "Error: There are uncommitted changes."
exit 1
fi

# Append an incremented version number to the version.txt file
echo $NEXT >> version.txt
# Append an incremented version number and date to the version.txt file
echo "$NEXT $DATE" >> version.txt

# Append commit messages to the CHANGELOG file
echo $NEXT >> CHANGELOG.txt
# Append commit messages to the CHANGELOG file with the date
echo "$NEXT ($DATE)" >> CHANGELOG.txt
git log v$CURRENT..HEAD --pretty=" - %s" --no-merges >> CHANGELOG.txt
echo >> CHANGELOG.txt

Expand All @@ -44,33 +46,33 @@ if [ "$FEAT" != "master" ]; then

# Commit the changes above
if ! git add .; then
echo ERROR: Unable to add version and css files.
echo "ERROR: Unable to add version and css files."
exit 1
fi
if ! git commit -m "docs: update version number and docs css"; then
echo ERROR: Unable to commit version and css files.
echo "ERROR: Unable to commit version and css files."
exit 1
fi

# Create a release tag and push it to GitHub
if ! git checkout master; then
echo ERROR: Failed to checkout master.
echo "ERROR: Failed to checkout master."
exit 1
fi
if ! git merge $FEAT; then
echo ERROR: Failed to merge the feature branch.
echo "ERROR: Failed to merge the feature branch."
exit 1
fi
if ! git tag -a v$NEXT -m "release: v$NEXT"; then
echo ERROR: Failed to tag the new version.
echo "ERROR: Failed to tag the new version."
exit 1
fi
if ! git push; then
echo ERROR: Failed to push all commited changes.
echo "ERROR: Failed to push all committed changes."
exit 1
fi
if ! git push --tags; then
echo ERROR: Failed to push the new tag.
echo "ERROR: Failed to push the new tag."
exit 1
fi

Expand All @@ -81,4 +83,4 @@ fi

# Exit with an error code
echo "You should be on a feature branch."
exit 1
exit 1

0 comments on commit 9dd2273

Please sign in to comment.