-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget-next
executable file
·90 lines (77 loc) · 2.81 KB
/
get-next
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
#!/bin/bash
help () { printf "
***********
get-next.sh
***********
gets the next semver versioning of the current folder based on the version
in the git tag list. version should be in format 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-q --quiet : suppresses debug prints
\t-h --help : prints this text
usage:
\t./get-next.sh <version_type> [...options]
\t<version_type>:
\t\tmajor: {major|maj|m1}
\t\tminor: {minor|min|m2}
\t\tpatch: {patch|ptc|p} (DEFAULT)
examples:
\t./get-next.sh maj : bumps the major version (1.0.0 > 2.0.0)
\t./get-next.sh min : bumps the minor version (1.0.0 > 1.1.0)
\t./get-next.sh patch : bumps the patch version (1.0.0 > 1.0.1)
\t./get-next.sh -q : bumps the patch version (1.0.0 > 1.0.1) w/o output
";
}
get_current_version () {
if [[ $* == *-m* ]] || [[ $* == *--merged* ]]; then MERGE=' -m'; else MERGE=''; fi;
GET_LATEST_COMMAND="$(dirname $0)/get-latest -q${MERGE}";
CURRENT_VERSION=$($GET_LATEST_COMMAND);
if [[ $? != 0 ]]; then
printf "
ERROR: could not find a git tag that resembles a semver version (x.y.z).
\t> To add a 1.0.3 tag, run 'git tag 1.0.3'
\t> Exiting with status code 1.
";
exit 1;
fi;
LATEST_MAJOR_VERSION=$(printf "$CURRENT_VERSION" | cut -d. -f1);
LATEST_MINOR_VERSION=$(printf "$CURRENT_VERSION" | cut -d. -f2);
LATEST_PATCH_VERSION=$(printf "$CURRENT_VERSION" | cut -d. -f3);
}
get_next_version () {
VERSION_TYPE_TO_UPDATE=$1;
NEXT_MAJOR_VERSION=$LATEST_MAJOR_VERSION;
NEXT_MINOR_VERSION=$LATEST_MINOR_VERSION;
NEXT_PATCH_VERSION=$LATEST_PATCH_VERSION;
case "$VERSION_TYPE_TO_UPDATE" in
"major"|"maj"|"m1")
((NEXT_MAJOR_VERSION++));
NEXT_VERSION="${NEXT_MAJOR_VERSION}.0.0";
;;
"minor"|"min"|"m2")
((NEXT_MINOR_VERSION++));
NEXT_VERSION="${NEXT_MAJOR_VERSION}.${NEXT_MINOR_VERSION}.0";
;;
"patch"|"ptc"|"p"|*)
((NEXT_PATCH_VERSION++));
NEXT_VERSION="${NEXT_MAJOR_VERSION}.${NEXT_MINOR_VERSION}.${NEXT_PATCH_VERSION}";
;;
esac
}
if [[ $* == *-h* ]] || [[ $* == *--help* ]]; then help; exit 1; fi;
if [[ $* == *-q* ]] || [[ $* == *--quiet* ]]; then exec 6>&1; exec > /dev/null; fi;
get_current_version;
printf "CURRENT_VERSION: ${CURRENT_VERSION}\n";
printf "MAJOR: ${LATEST_MAJOR_VERSION}\n";
printf "MINOR: ${LATEST_MINOR_VERSION}\n";
printf "PATCH: ${LATEST_PATCH_VERSION}\n";
get_next_version $1;
printf "NEXT_VERSION: ${NEXT_VERSION}\n";
printf "MAJOR: ${NEXT_MAJOR_VERSION}\n";
printf "MINOR: ${NEXT_MINOR_VERSION}\n";
printf "PATCH: ${NEXT_PATCH_VERSION}\n";
printf "VERSION UPGRADE: ${CURRENT_VERSION} > ";
if [[ $* == *-q* ]] || [[ $* == *--quiet* ]]; then exec 1>&6 6>&-; fi;
printf "${NEXT_VERSION}\n";
exit 0;