-
Notifications
You must be signed in to change notification settings - Fork 6
/
.make-release-support
76 lines (64 loc) · 1.54 KB
/
.make-release-support
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
function hasChanges() {
test -n "$(git status -s .)"
}
function getRelease() {
awk -F= '/release/{print $2}' .release
}
function getBaseTag() {
sed -n -e "s/tag=\([^0-9]*\).*/\1/p" .release
}
function getTag() {
if [ -z "$1" ] ; then
awk -F= '/tag/{print $2}' .release
else
echo "$(getBaseTag)$1"
fi
}
function setRelease() {
if [ -n "$1" ] ; then
sed -i -e "s/release=.*/release=$1/g" .release
sed -i -e "s/tag=.*/tag=$(getTag $1)/" .release
rm -f .release-e
else
echo "ERROR: missing release version parameter " >&2
return 1
fi
}
function tagExists() {
tag=${1:-$(getTag)}
test -n "$tag" && test -n "$(git tag | grep "$tag\$")"
}
function differsFromRelease() {
tag=$(getTag)
! tagExists $tag || test -n "$(git diff --shortstat -r $tag .)"
}
function getVersion() {
version=$(getRelease)
if differsFromRelease ; then
version="$version-$(git describe --always)"
if hasChanges ; then
version="$version-dirty"
fi
fi
echo $version
}
function nextPatchLevel() {
version=${1:-$(getRelease)}
major_and_minor=$(echo $version | cut -d. -f1,2)
patch=$(echo $version | cut -d. -f3)
version=$(printf "%s.%d" $major_and_minor $(($patch + 1)))
echo $version
}
function nextMinorLevel() {
version=${1:-$(getRelease)}
major=$(echo $version | cut -d. -f1);
minor=$(echo $version | cut -d. -f2);
version=$(printf "%d.%d.0" $major $(($minor + 1))) ;
echo $version
}
function nextMajorLevel() {
version=${1:-$(getRelease)}
major=$(echo $version | cut -d. -f1);
version=$(printf "%d.0.0" $(($major + 1)))
echo $version
}