tag.increment.sh
· 883 B · Bash
Raw
#!/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
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 | |
7 | increment_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 | |
17 | LATEST_TAG=$(git describe --tags --abbrev=0) |
18 | |
19 | increment_version "$LATEST_TAG" $1 |
20 | |
21 | |
22 | read -r -p "Apply tag $NEW_TAG to branch? [Y/n]" response |
23 | response=${response,,} # tolower |
24 | if [[ $response =~ ^(yes|y| ) ]] || [[ -z $response ]]; then |
25 | git tag -a $NEW_TAG -m "$NEW_TAG" |
26 | else |
27 | exit 1 |
28 | fi |
29 | |
30 | read -r -p "Push tag $NEW_TAG to origin? [Y/n]" response |
31 | response=${response,,} # tolower |
32 | if [[ $response =~ ^(yes|y| ) ]] || [[ -z $response ]]; then |
33 | git push origin $NEW_TAG --follow-tags |
34 | fi |
35 |