Last active 1751197245

Increments a GIT tag tot he next version and pushes the tag upstream

git
tag.increment.sh Raw
1#!/bin/bash
2
3### Increments the part of the string
4## $1: version itself
5## $2: number of part: 0 – major, 1 – minor, 2 – patch
6
7increment_version() {
8 local delimiter=.
9 local array=($(echo "$1" | tr $delimiter '\n'))
10 array[$2]=$((array[$2]+1))
11 if [ $2 -lt 2 ]; then array[2]=0; fi
12 if [ $2 -lt 1 ]; then array[1]=0; fi
13 NEW_TAG=$(local IFS=$delimiter ; echo "${array[*]}")
14}
15
16
17LATEST_TAG=$(git describe --tags --abbrev=0)
18
19increment_version "$LATEST_TAG" $1
20
21
22read -r -p "Apply tag $NEW_TAG to branch? [Y/n]" response
23response=${response,,} # tolower
24if [[ $response =~ ^(yes|y| ) ]] || [[ -z $response ]]; then
25 git tag -a $NEW_TAG -m "$NEW_TAG"
26else
27 exit 1
28fi
29
30read -r -p "Push tag $NEW_TAG to origin? [Y/n]" response
31response=${response,,} # tolower
32if [[ $response =~ ^(yes|y| ) ]] || [[ -z $response ]]; then
33 git push origin $NEW_TAG --follow-tags
34fi
35