forked from mercadolibre/java-restclient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·90 lines (73 loc) · 1.72 KB
/
build.sh
File metadata and controls
executable file
·90 lines (73 loc) · 1.72 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
function isCommitted() {
git diff-index --quiet HEAD --
}
function getBranch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
function isPushed() {
branch=$(getBranch)
changes=$(git log --quiet origin/${branch}..${branch})
if [ "$changes" == "" ]; then
return 0
else
return 1
fi
}
function updateVersion() {
mvn -e -X -B versions:set -DnewVersion=$1
}
function deploy() {
mvn -e -X deploy
}
function updateReadmeVersion() {
line_nbr=$(getReadmeVersionLineNbr restclient-default)
modifyVersion $line_nbr $1
line_nbr=$(getReadmeVersionLineNbr restclient-core)
modifyVersion $line_nbr $1
}
function getReadmeVersionLineNbr() {
awk "/<artifactId>$1<\/artifactId>/{getline; print NR}" README.md
}
function modifyVersion() {
line_nbr=$1
version=$2
if [ "$line_nbr" != "" ]; then
sed -i "" "${line_nbr}s/<version>.*<\/version>/<version>$version<\/version>/" README.md
fi
}
function updateGit() {
git commit -am "RestClient new version: $1"
git push origin $(getBranch)
}
function print_help() {
echo "Usage: build.sh [-v version] [-d] [-h]"
}
version=""
do_deploy=0
while getopts ":v:dh" flag; do
case $flag in
v) version=$OPTARG;;
d) do_deploy=1;;
h) print_help; exit 0;;
\? | *) print_help; exit 2;;
esac
done
shift $(( OPTIND - 1 ));
if [ "$version" == "" ]; then
echo "Version is mandatory"
print_help
exit 1;
elif ! isCommitted; then
echo "Repo has uncommitted changes"
exit 1
elif ! isPushed; then
echo "Branch has non pushed changes"
exit 1
fi
updateVersion $version
updateReadmeVersion $version
if [ $do_deploy -eq 1 ]; then
deploy
updateGit $version
fi