Skip to content

Instantly share code, notes, and snippets.

@titom73
Last active March 22, 2022 12:37
Show Gist options
  • Save titom73/84f954bcb0a61221a1dd0257cd6ac4f9 to your computer and use it in GitHub Desktop.
Save titom73/84f954bcb0a61221a1dd0257cd6ac4f9 to your computer and use it in GitHub Desktop.
Bump SemVer
#! /bin/bash
# Author:
# Date: 2022-03-22
# Version: 0.1.0
# Info: Script to bump version based on SemVer syntax. DEV id is based on week number
# Example:
# # Assuming current version is v3.32.1.dev2
# # Bump MAJOR version
# $ bash .github/bump-dev-version.sh major
# 4.0.0
# # Bump MINOR version
# $ bash .github/bump-dev-version.sh minor
# 3.33.0
# # Bump PATCH version
# $ bash .github/bump-dev-version.sh patch
# 3.32.2
# # Bump DEV version
# $ bash .github/bump-dev-version.sh dev
# 3.32.1.dev3
# # Bump SemVer & DEV version
# $ bash .github/bump-dev-version.sh patch dev
# 3.32.2.dev3
SEMVER_REGEX='\([a-zA-Z]*\)\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)[.dev]*\([0-9]*\)'
step="$1"
if [ -z "$1" ]
then
step=patch
fi
option="$2"
if [ -z "$2" ]
then
option='nodev'
fi
base="$3"
if [ -z "$3" ]
then
base=$(git describe --abbrev=0 --tags)
if [ -z "$base" ]
then
if [ $option = 'dev']
then
base=0.0.0.dev0
else
base=0.0.0
fi
fi
fi
HEADER=`echo $base | sed -e "s#$SEMVER_REGEX#\1#"`
MAJOR=`echo $base | sed -e "s#$SEMVER_REGEX#\2#"`
MINOR=`echo $base | sed -e "s#$SEMVER_REGEX#\3#"`
PATCH=`echo $base | sed -e "s#$SEMVER_REGEX#\4#"`
DEV=`echo $base | sed -e "s#$SEMVER_REGEX#\5#"`
case "$step" in
major)
let MAJOR+=1
let MINOR=0
let PATCH=0
let DEV=0
;;
minor)
let MINOR+=1
let PATCH=0
let DEV=0
;;
patch)
let PATCH+=1
let DEV=0
;;
dev)
if [[ $DEV -gt 0 ]]; then
let DEV+=1
else
let DEV=0
fi
;;
esac
case "$option" in
dev)
if [[ $DEV -gt 0 ]]; then
let DEV+=1
else
let DEV=0
fi
;;
esac
if [[ ${step} == "dev" ]] || [[ ${option} == 'dev' ]]; then
echo "${HEADER}${MAJOR}.${MINOR}.${PATCH}.dev${DEV}"
# Specific AVD logic
elif [[ ${step} == "minor" ]]; then
echo "${HEADER}${MAJOR}.${MINOR}.${PATCH}.dev0"
else
echo "${HEADER}${MAJOR}.${MINOR}.${PATCH}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment