-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrelease.sh
executable file
·128 lines (94 loc) · 2.67 KB
/
release.sh
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
realpath() {
OURPWD=$PWD
cd "$(dirname "$1")"
LINK=$(readlink "$(basename "$1")")
while [ "$LINK" ]; do
cd "$(dirname "$LINK")"
LINK=$(readlink "$(basename "$1")")
done
REALPATH="$PWD/$(basename "$1")"
cd "$OURPWD"
echo `dirname $REALPATH`
}
project_dir=`realpath $0`
local_maven=${HOME}/maven_rm
if [ ! -d ${local_maven} ]; then
mkdirs -p ${local_maven}
git clone [email protected]:rmalchow/maven.git ${local_maven}
fi
cd ${local_maven}
git pull
cd ${project_dir}
pwd
git diff --exit-code 2>&1 > /dev/null
if [ "$?" != "0" ]; then
echo "there are unstaged changes"
exit -1
fi
git diff --cached --exit-code 2>&1 > /dev/null
if [ "$?" != "0" ]; then
echo "there are uncommitted changes"
exit -2
fi
function current_version() {
mvn -B org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.version |grep "^[0-9]"
}
function current_project() {
mvn -B org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=project.name |grep -v "^\[" |grep -v "^Download"
}
function to_release() {
echo "$1" | sed s:"[^0-9.]":"":g
}
# Advances the last number of the given version string by one.
function next_snapshot() {
components=`echo "$1" | sed s:"[^0-9.]":"":g| sed s:"\.":" ":g`
i=0
for c in $components; do
a[i]=$c
let "i++"
done
d=${a[2]}
let "d++"
a[2]=$d
echo "${a[0]}.${a[1]}.${a[2]}-SNAPSHOT"
}
#
# this is an example script. it does a basic build, deployment and tagging of
# maven project. why not the maven deploy plugin, you ask? well ... i find it
# isn't flexible enough, and it also is quite difficult to debug.
#
cd `dirname $0`
set -e
set +x
num_args=${#@}
if [ $num_args -gt 0 ]; then
cd $1
fi
if [ ! -f pom.xml ]; then
echo "no POM found in folder `pwd`"
false
fi
echo "trying to determine versions ... "
project=$(current_project)
echo " project: ${project}"
curr=$(current_version)
echo " curr_v : ${curr}"
rel=$(to_release $curr)
dev=$(next_snapshot $rel)
echo -n "PROJECT: $project --- $curr - $rel - $dev - OK? [y/n]: "
read check
if [ "$check" = "y" ]; then
echo "Doing RELEASE ... "
else
echo "aborting ... "
false
fi
git add . && git commit -m "[ci-skip] release prepare $rel" && git push
mvn --batch-mode versions:set -DnewVersion=$rel
mvn deploy -DaltDeploymentRepository=local::default::file://${local_maven}
git tag -a $rel -m "[ci-skip] release $rel" && git push origin $rel
mvn --batch-mode versions:set -DnewVersion=$dev
git add . && git commit -m "[ci-skip] release ($rel) finished, prepare for development ... " && git push
cd ${local_maven}
git add . && git commit -m "[ci-skip] new release $rel of $project" && git push