Last active
December 15, 2022 19:02
-
-
Save iconifyit/d192e1647537e4019d8a3be22305f8a4 to your computer and use it in GitHub Desktop.
Interactive bash script to push a new tag and release version. Automatically increments major, minor, or patch version based on the latest tag (assumes you are using {major}.{minor}.{patch} format)
This file contains hidden or 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
#!/usr/bin/env bash | |
############################################################ | |
# Help # | |
############################################################ | |
Help() | |
{ | |
# Display Help | |
echo "Increment the latest tag and create a new tag & release." | |
echo | |
echo "Syntax: release [-major|-minor|-patch|-h]" | |
echo "options:" | |
echo "-M | -major Increment the major version. (Ex: 1.0.0 -> 2.0.0)" | |
echo "-m | -minor Increment the minor version. (Ex: 1.0.0 -> 1.1.0)" | |
echo "-p | -patch Increment the patch version. (Ex: 1.0.0 -> 1.0.1)" | |
echo "-h | -help Print this Help." | |
echo | |
} | |
############################################################ | |
while [ $# -gt 0 ] ; do | |
case $1 in | |
-M | --major) part="0"; name="major" ;; | |
-m | --minor) part="1"; name="minor";; | |
-p | --patch) part="2"; name="patch" ;; | |
-h | --help) Help ; exit 0 ;; | |
esac | |
shift | |
done | |
echo "Incrementing $name version... " | |
### Increments the part of the string | |
## $1: version itself | |
## $2: number of part: 0 – major, 1 – minor, 2 – patch | |
increment_version() { | |
local delimiter=. | |
local array=($(echo "$1" | tr $delimiter '\n')) | |
array[$2]=$((array[$2]+1)) | |
if [ $2 -lt 2 ]; then array[2]=0; fi | |
if [ $2 -lt 1 ]; then array[1]=0; fi | |
echo $(local IFS=$delimiter ; echo "${array[*]}") | |
} | |
# Create the github tag | |
TAG=$(git describe --tags `git rev-list --tags --max-count=1`) | |
VERSION=`increment_version $TAG $part 1` | |
echo "New version is: $VERSION" | |
rm -R -f dist | |
mkdir -p dist | |
cp .serverless/* dist/ | |
git tag -a $VERSION -m "Release of version $VERSION" | |
git push --tags | |
gh release create v$VERSION ./dist/* --generate-notes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment