#!/bin/bash ### 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 NEW_TAG=$(local IFS=$delimiter ; echo "${array[*]}") } LATEST_TAG=$(git describe --tags --abbrev=0) increment_version "$LATEST_TAG" $1 read -r -p "Apply tag $NEW_TAG to branch? [Y/n]" response response=${response,,} # tolower if [[ $response =~ ^(yes|y| ) ]] || [[ -z $response ]]; then git tag -a $NEW_TAG -m "$NEW_TAG" else exit 1 fi read -r -p "Push tag $NEW_TAG to origin? [Y/n]" response response=${response,,} # tolower if [[ $response =~ ^(yes|y| ) ]] || [[ -z $response ]]; then git push origin $NEW_TAG --follow-tags fi