Last active
November 9, 2020 13:48
-
-
Save byronmansfield/ac426843cf677b6019ae to your computer and use it in GitHub Desktop.
Release script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# Release Manager | |
# Bumps version of project | |
# Tags the new version | |
# Produces Changelog | |
# Get Project Current Version | |
version=$(sed -n 's/.*"version": "\(.*\)",/\1/p' package.json) | |
# greeting banner | |
echo "" | |
echo "===========================" | |
echo " Welcome to Release Helper " | |
echo "===========================" | |
echo "" | |
# Bump Version Function | |
do_bump () { | |
# abstract each part to the version and set to variable | |
base_version=(`echo $version | tr '.' ' '`) | |
major_v=${base_version[0]} | |
minor_v=${base_version[1]} | |
patch_v=${base_version[2]} | |
echo "Current version: $version" | |
# bump each part based on user input | |
if [ "$1" != 0 ]; then | |
major_v=$((major_v + $1)) | |
fi | |
if [ "$2" != 0 ]; then | |
minor_v=$((minor_v + $2)) | |
fi | |
if [ "$3" != 0 ]; then | |
patch_v=$((patch_v + $3)) | |
fi | |
suggested_v="$major_v.$minor_v.$patch_v" | |
read -p "Suggested version to bump to [$suggested_v]. Will this be ok? (y/n): " version_confirm | |
case $version_confirm in | |
[Yy]* ) start_release $suggested_v;; | |
[Nn]* ) read -p "Ok, what version would you like to bump to?: " set_v; start_release set_v;; | |
* ) echo "Bumping version to $suggested_v"; start_release $suggested_v;; | |
esac | |
} | |
# Gather user input on how to bump the project | |
ask_bump () { | |
echo "Until I get smart enough to calculate this for you, help me figure out how to bump this project." | |
read -p "How many major changes have been made?: " major_chgs | |
read -p "How many minor changes have been made?: " minor_chgs | |
read -p "How many patches have been made?: " patch_chgs | |
do_bump major_chgs minor_chgs patch_chgs | |
} | |
# Actually starting the release process | |
start_release () { | |
echo "Doing release under version $1" | |
lastdate=$(git show -s --format=%ad `git rev-list --tags --max-count=1`) | |
today=$(date +"%m-%d-%Y") | |
echo "Last Release was on $lastdate" | |
echo "Producing Changelog starting from $lastdate" | |
# start producing Changelog file starting with the heading | |
echo "# Performance Manager Changelog for release v$1" > CHANGELOG.md | |
echo "" >> CHANGELOG.md | |
echo "## [$1](https://github.com/Demandbase/perfman/releases/tag/v$1) ($today)" >> CHANGELOG.md | |
echo "" >> CHANGELOG.md | |
# now we add in the commit history | |
git log --no-merges --pretty=format:"%h %an, %ad, message: %s%n" --date=local --since="$lastdate" >> CHANGELOG.md | |
git add -A | |
git commit -m "Produced Changelog file for release" | |
git push origin staging | |
echo "Done making CHANGELOG.md. Starting release" | |
git flow release start v$1 | |
echo "Bumping project version to v$1" | |
grunt bump --setversion=$1 | |
echo "Adding and commiting all changes done during release process" | |
git add -A | |
git commit -m "Bumps project version to v$1" | |
git flow release finish v$1 | |
git push --tags --force | |
git push origin master | |
} | |
# Let user input which version to work from | |
set_version () { | |
read -p "Ok, please input a semantic version you would like to work from. (e.g. 0.6.2): " version | |
read -p "Your new version to work from is v$version. Is this correct? (y/n): " yn | |
case $yn in | |
[Yy]* ) ask_bump $version;; | |
[Nn]* ) echo "Sorry something went wrong. Please try again.";; | |
* ) echo "Sorry something went wrong. Please try again.";; | |
esac | |
} | |
# Confirm project version | |
confirm_version () { | |
read -p "Looks like Performance Manager is currently at version $1. Is this correct? (y/n): " yn | |
case $yn in | |
[Yy]* ) ask_bump $1;; | |
[Nn]* ) set_version;; | |
* ) echo "Something went wrong. Please try again.";; | |
esac | |
} | |
# Confirm user ready | |
confirm_ready () { | |
read -p "Are you ready to get started? (y/n): " yn | |
case $yn in | |
[Yy]* ) confirm_version $version;; | |
[Nn]* ) echo "Ok, Cya next time!";; | |
* ) read -p "Sorry, I didnt catch that. Please tell me if you are ready to | |
* begin your release? (y/n): ";; | |
esac | |
} | |
confirm_ready |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Release script I wrote to help developers of a project I'm contributing to all release the same way. It helps to produce a consistent changelog and make sure they tag their work. It needs work but it is successfully being used today.