-
Notifications
You must be signed in to change notification settings - Fork 3
/
release.sh
executable file
·91 lines (80 loc) · 2.37 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
#!/bin/bash
set -e
function printHelp()
{
cat << EOF
DESCRIPTION
Releases a Maven project using the official Maven Release plugin.
OPTIONS
-v <version> Specify the version to be released, e.g. 1.4.2. Default - the current dev version without SNAPSHOT.
-n <version> Specify the next dev version. Default - maintenance increment of the released one with SNAPSHOT
-u <username> User to be used for SCM.
-i <email> Impersonate with the provided email. Sets the git user.email temporary.
-r <url> Repository URL. Assumes the POM property to be set to ${scmDeveloperConnection}
-h Prints this help.
EOF
}
while getopts ":v:n:u:i:r:h" opt; do
case $opt in
v)
version=$OPTARG
;;
n)
next=$OPTARG
;;
u)
username=$OPTARG
;;
i)
impersonate=$OPTARG
;;
r)
repo=$OPTARG
;;
h)
printHelp
exit 0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
maven_version=$(mvn -q \
-Dexec.executable="echo" \
-Dexec.args='${project.version}' \
--non-recursive \
org.codehaus.mojo:exec-maven-plugin:1.6.0:exec)
ver=${version:-$maven_version}
ver=$(echo $ver | sed -e "s/-SNAPSHOT$//g")
# impersonate
if [[ $impersonate ]]; then
original_user_email=$(git config --get user.email)
echo Impersonating $impersonate, Original: $original_user_email
git config user.email $impersonate
fi
if [[ $username ]]; then
usernameArg=-Dusername=$username
fi
if [[ $next ]]; then
nextVersionArg=-DdevelopmentVersion=$next-SNAPSHOT
fi
if [[ $repo ]]; then
developerConnectionArg=-DscmDeveloperConnection=scm:git:$repo
fi
echo Executing Maven Release:
echo mvn release:prepare --batch-mode -DreleaseVersion=$ver $nextVersionArg $usernameArg $developerConnectionArg -Dresume=false -DscmCommentPrefix="(release) " -DpushChanges=false
mvn release:prepare --batch-mode -DreleaseVersion=$ver $nextVersionArg $usernameArg $developerConnectionArg -Dresume=false -DscmCommentPrefix="(release) " -DpushChanges=false
git push origin $(git rev-list -n 1 v$ver):$(git rev-parse --abbrev-ref HEAD) --follow-tags
sleep 5
git push
# reset impersonation
if [[ $impersonate ]]; then
echo Setting user.email back to $original_user_email
git config user.email $original_user_email
fi