-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-tag
executable file
·55 lines (47 loc) · 1.2 KB
/
git-tag
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env bash
# *************************************
#
# Git Tag
# -> Automatically set a git tag based on Semantic Versioning keyword
#
# -------------------------------------
# Usage
# -------------------------------------
#
# $1 - 'major', 'minor', 'patch'
#
# Usage: `git-tag major`
#
# *************************************
tag=$(git describe --abbrev=0 --tags 2>/dev/null)
prefix=$(echo $tag | grep -o --color=never "[A-z]\+")
major=$(echo $tag | cut -d '.' -f1 | grep -o --color=never "[0-9]")
minor=$(echo $tag | cut -d '.' -f2)
patch=$(echo $tag | cut -d '.' -f3)
case "$1" in
'major')
nmajor=$(($major+1))
version="$nmajor.0.0"
;;
'minor')
nminor=$(($minor+1))
version="$major.$nminor.0"
;;
'patch')
npatch=$(($patch+1))
version="$major.$minor.$npatch"
;;
*)
echo "Automatically set a git tag based on Semantic Versioning keyword"
echo
echo "Usage: git-tag <major|minor|patch>"
echo
echo "Example:"
echo " git-tag major"
echo
echo "If this is your first tag, use 'git tag' to set up your first one."
esac
if [[ "$version" ]]; then
git tag -a "$prefix$version" -m "Version $version"
echo "$prefix$version created!"
fi