-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathversion_tag.sh
executable file
·121 lines (106 loc) · 3.02 KB
/
version_tag.sh
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
SORTCMD=${SORT:-gsort}
which -s $SORTCMD
if [ $? -eq 1 ]
then
echo "ERROR: Can't find sort command '$SORTCMD'. Please install it or set SORT to a sort command that exists."
exit 1
fi
PREFIX="release/"
TAGS=$(git ls-remote -t 2>/dev/null | grep -o 'release/[0-9]\+\.[0-9]\+\.[0-9]\+$' | cut -d'/' -f 2 | $SORTCMD -V)
LAST_TAG=$(echo "$TAGS" | tail -1)
set_tag() {
MAJOR=$(echo $LAST_TAG | cut -d. -f 1)
MINOR=$(echo $LAST_TAG | cut -d. -f 2)
BUILD=$(echo $LAST_TAG | cut -d. -f 3)
case $1 in
(major)
NEWTAG="$[$MAJOR+1].0.0"
echo "incrementing major on $LAST_TAG to make $NEWTAG"
;;
(minor)
NEWTAG="$MAJOR.$[$MINOR+1].0"
echo "incrementing minor on $LAST_TAG to make $NEWTAG"
;;
(build)
NEWTAG="$MAJOR.$MINOR.$[$BUILD+1]"
echo "incrementing build on $LAST_TAG to make $NEWTAG"
;;
(*)
tmp=$(echo $1| grep -o '^[0-9]\+\.[0-9]\+\.[0-9]\+$')
if [ "$?" != 0 ]; then
echo "TAG must match d.d.d SEMVAR format"
exit 2
fi
NEWTAG=$1
echo "creating new tag $NEWTAG"
esac
for OLDTAG in ${TAGS}
do
if [ $OLDTAG == $NEWTAG ]; then
echo "TAG $NEWTAG already exists"
exit 2
fi
done
git tag -a -m"Create TAG" ${PREFIX}${NEWTAG} && git push --tags
}
remove_tag() {
TAG=$1
if [ "$TAG" == "" ]; then
echo "TAG not specified"
exit 2
fi
echo "Removing local tag ${PREFIX}${TAG}"
git tag -d ${PREFIX}${TAG}
if [[ $TAGS =~ $TAG ]]; then
echo "Removing remote TAG $TAG"
else
echo "TAG $TAG does not exist"
exit 2
fi
git push origin :refs/tags/${PREFIX}${TAG}
}
show_tag() {
TAG=$2
[ "$TAG" == "" ] && TAG=$LAST_TAG
git show ${PREFIX}${TAG}
}
verbose_list() {
OUTPUT=$(git for-each-ref refs/tags/release --format "%(objectname):%(refname):%(taggername):%(taggerdate:relative)")
SaveIFS=$IFS
IFS=":"
echo "$OUTPUT" | while read commit ref author date
do
version=$(echo $ref | grep -o 'release/[0-9]\+\.[0-9]\+\.[0-9]\+$' | cut -d'/' -f 2)
printf "%s %12s %-30s %s\n" "$commit" "$version" "$author" "$date"
done
}
if [ "$#" -eq 0 ]; then
echo "$TAGS" | tail -1
elif [ "$1" == "last" ]; then
echo "$TAGS" | tail -1
elif [ "$1" == "ll" ]; then
verbose_list
elif [ "$1" == "list" ]; then
echo "$TAGS"
elif [ "$1" == "set" ]; then
set_tag $2
elif [ "$1" == "show" ]; then
show_tag $2
elif [ "$1" == "remove" ]; then
remove_tag $2
else
cat <<EOT
Usage: $0 [command]
Commands:
last - list the highest semver tag (default if no command specified)
list - list all semver tags
ll - long list: contains committer/datestamp (required updated local repo)
set major - create a tag with new major version
set minor - create a tag with new minor version
set build - create a tag with new build version
set <version> - create a tag with a specific semver version
show <version> - perform a git show on the specific version
remove <version> - remove a semver tag
EOT
fi