-
Notifications
You must be signed in to change notification settings - Fork 1
/
iterate
executable file
·65 lines (55 loc) · 1.99 KB
/
iterate
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
#!/bin/bash
help() { printf "
*******
iterate
*******
this script gets the latest merged version available in the current branch, ups
the version number depending on the argument passed in. exits with 0 on successful
updating, exist with 1 if tag could not be applied for any reason.
versioning has to be in semver for this to work. eg. x.y.z where x is the major
version, y is the minor version and z is the patch version.
options:
\t-m --merged : retrieve only from tags that have been merged
\t-i --init : initializes tagging if no version tags could be found
\t-q --quiet : suppresses debug prints
\t-h --help : prints this text
usage:
\t./iterate [<version_target>]
\t\t<version_target>:
\t\t\t{ major|maj|1 } : ups the major version
\t\t\t{ minor|min|2 } : ups the minor version
\t\t\t{ patch|p|3 } : ups the patch version
";
}
if [[ $* == *-h* ]] || [[ $* == *--help* ]]; then help; exit 1; fi;
if [[ $* == *-q* ]] || [[ $* == *--quiet* ]]; then exec 6>&1; exec > /dev/null; fi;
if [[ $* == *-i* ]] || [[ $* == *--init* ]]; then INIT=1; else INIT=0; fi;
if [[ $* == *-m* ]] || [[ $* == *--merged* ]]; then MERGE=' -m'; else MERGE=''; fi;
TO_INITIALIZE=0;
GET_LATEST_COMMAND="$(dirname $0)/get-latest -q${MERGE}";
CURRENT_VERSION="$($GET_LATEST_COMMAND)";
if [[ "$?" != "0" ]] && [[ "${CURRENT_VERSION}" = "" ]]; then
TO_INITIALIZE=1;
fi;
if [ ${TO_INITIALIZE} -eq 1 ]; then
NEXT_VERSION='0.0.0';
else
case $1 in
"major"|"maj"|"1")
GET_NEXT_COMMAND="$(dirname $0)/get-next major -q";
;;
"minor"|"min"|"2")
GET_NEXT_COMMAND="$(dirname $0)/get-next minor -q";
;;
"patch"|"p"|"3"|*)
GET_NEXT_COMMAND="$(dirname $0)/get-next patch -q";
;;
esac;
NEXT_VERSION="$($GET_NEXT_COMMAND)";
fi;
CURRENT_BRANCH_COMMAND="$(dirname $0)/get-branch -q";
CURRENT_BRANCH="$($CURRENT_BRANCH_COMMAND)";
printf -- "NEXT_VERSION: ${NEXT_VERSION}\n";
printf -- "CURRENT_BRANCH: ${CURRENT_BRANCH}\n";
git tag "${NEXT_VERSION}" "${CURRENT_BRANCH}";
exit 0;