forked from Rocketmakers/gitflow-semver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-release-bash
More file actions
executable file
·69 lines (61 loc) · 1.83 KB
/
Copy pathgit-release-bash
File metadata and controls
executable file
·69 lines (61 loc) · 1.83 KB
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
#!/bin/bash
if [ "$1" != 'major' -a "$1" != 'minor' -a "$1" != 'patch' -a "$1" != 'init' -a "$1" != 'version' ]; then
>&2 echo "Usage: git release major|minor|patch|init|version"
exit 1
fi
if [ "$1" == 'version' ]; then
echo "0.2.0"
exit 0
fi
if [ `git rev-parse master` != `git rev-parse origin/master 2> /dev/null` ]; then
>&2 echo "Error: master is out of date with origin, please update/push first!"
exit 1
fi
lastVersion=`git describe --abbrev=0 master 2> /dev/null`
if [ $? != 0 ]; then
if [ "$1" == 'init' ]; then
read -p "No tags found in repo, shall we initialize this repo for gitflow? [Y/n] " -n 1 -r
echo
if echo $REPLY | grep -E '^[Nn]$' > /dev/null; then
exit 1
else
git flow init
lastVersion="0.0.0"
fi
else
>&2 echo "Error: no tags found in repo, run again with 'init' to initialize for gitflow"
exit 1
fi
elif [ `git rev-parse develop` != `git rev-parse origin/develop 2> /dev/null` ]; then
>&2 echo "Error: develop is out of date with origin, please update/push first!"
exit 1
fi
versionArray=(${lastVersion//./ })
major=${versionArray[0]}
minor=${versionArray[1]}
patch=${versionArray[2]}
if [ "$1" == 'major' ]; then
newVersion="$((major+1)).0.0"
elif [ "$1" == 'minor' ]; then
newVersion="$major.$((minor+1)).0"
elif [ "$1" == 'patch' ]; then
newVersion="$major.$minor.$((patch+1))"
elif [ "$1" == 'init' ]; then
newVersion="0.1.0"
fi
echo "Last release was version ${lastVersion}."
echo "We're about to create a new $1 release, with version ${newVersion}."
read -p "Continue? [Y/n] " -n 1 -r
echo
if echo $REPLY | grep -E '^[Nn]$' > /dev/null; then
exit 1
else
if [ "$1" == 'patch' ]; then
git flow hotfix start $newVersion
else
git flow release start $newVersion
if [ "$1" == 'init' ]; then
git flow release finish $newVersion
fi
fi
fi