-
Notifications
You must be signed in to change notification settings - Fork 21
/
.make-release-support
106 lines (92 loc) · 2.51 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
#
# Copyright 2015 Xebia Nederland B.V.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
function hasChanges() {
test -n "$(git status -s .)"
}
function getRelease() {
awk -F= '/^release=/{print $2}' .release
}
function getBaseTag() {
sed -n -e "s/^tag=\(.*\)$(getRelease)\$/\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.x -e "s/^tag=.*/tag=$(getTag $1)/" .release
sed -i.x -e "s/^release=.*/release=$1/g" .release
rm -f .release.x
runPreTagCommand "$1"
else
echo "ERROR: missing release version parameter " >&2
return 1
fi
}
function runPreTagCommand() {
if [ -n "$1" ] ; then
COMMAND=$(sed -n -e "s/@@RELEASE@@/$1/g" -e 's/^pre_tag_command=\(.*\)/\1/p' .release)
if [ -n "$COMMAND" ] ; then
if ! OUTPUT=$(bash -c "$COMMAND" 2>&1) ; then echo $OUTPUT >&2 && exit 1 ; fi
fi
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() {
result=$(getRelease)
if differsFromRelease; then
result="$result-$(git rev-parse --short HEAD)"
fi
if hasChanges ; then
result="$result-dirty"
fi
echo $result
}
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
}