-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcreateTag.sh
executable file
·60 lines (49 loc) · 1.17 KB
/
createTag.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
#!/bin/bash
VERSION=""
#get parameters
while getopts v: flag
do
case "${flag}" in
v) VERSION=${OPTARG};;
esac
done
#get highest tag number, and add 0.0.1 if doesn't exist
CURRENT_VERSION=`git describe --abbrev=0 --tags 2>/dev/null`
if [[ $CURRENT_VERSION == '' ]]
then
CURRENT_VERSION='0.0.1'
fi
echo "Current Version: $CURRENT_VERSION"
# split
VERSION_ARRAY=(${CURRENT_VERSION//./ })
#get number parts
MAJOR=${VERSION_ARRAY[0]}
MINOR=${VERSION_ARRAY[1]}
PATCH=${VERSION_ARRAY[2]}
if [[ $VERSION == 'major' ]]
then
MAJOR=$((MAJOR+1))
elif [[ $VERSION == 'minor' ]]
then
MINOR=$((MINOR+1))
elif [[ $VERSION == 'patch' ]]
then
PATCH=$((PATCH+1))
else
echo "No version type or incorrect type specified, try: -v [major, minor, patch]"
exit 1
fi
#create new tag
NEW_TAG="$MAJOR.$MINOR.$PATCH"
echo "($VERSION) updating $CURRENT_VERSION to $NEW_TAG"
#get current hash and see if it already has a tag
GIT_COMMIT=$(git rev-parse HEAD)
NEEDS_TAG=$(git describe --contains "$GIT_COMMIT" 2>/dev/null)
if [ -z "$NEEDS_TAG" ]; then
echo "Tagged with $NEW_TAG"
git tag -a $NEW_TAG -m"Release $NEW_TAG"
git push --tags
else
echo "Already a tag on this commit"
fi
exit 0