-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·163 lines (141 loc) · 4.02 KB
/
release.sh
File metadata and controls
executable file
·163 lines (141 loc) · 4.02 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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash
# ---------------------------------------------------------------
# Script for release with Maven
# - Prepare the release (update POM version and commit)
# - Perform the release (tag the commit)
# - Prepare next development version (update POM and commit)
# ---------------------------------------------------------------
# Retrieving arguments
while [ -n "$1" ]
do
case "$1" in
--auto | -a)
auto=true
;;
--release | -r | --version | -v)
shift
DEFAULT_VERSION="$1"
;;
--tagPrefix | -p)
shift
DEFAULT_PREFIX="$1"
;;
--tag | -t)
shift
DEFAULT_TAG="$1"
;;
--snapshot | -s)
shift
DEFAULT_SNAPSHOT="$1"
;;
--help | -h)
echo "Options:"
echo " --auto | -a : enable auto mode (no user input, default values will be used)"
echo " --release | -r | --version | -v [version] : set the default release version to [version]"
echo " --tagPrefix | -p [prefix] : set the default tag prefix to [prefix]"
echo " --tag | -t [tag] : set the default release tag to [tag]"
echo " --snapshot | -s [version] : set the default snapshot version to [version]"
exit 0
;;
*)
echo "$1: Unknown option"
echo "Use --help or -h to show all available options"
exit 1
;;
esac
shift
done
# ------------------------------
# Release Version
# ------------------------------
if [ -z "$DEFAULT_VERSION" ]
then
# Extracting current version from POM and deducing release version
POM_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
DEFAULT_VERSION=${POM_VERSION//-SNAPSHOT/}
fi
# Skip input if auto is set
if [ -z "$auto" ]
then
# Ask for release version
echo -n "Release version ? [$DEFAULT_VERSION] : "; read version
fi
if [ -z "$version" ]
then
version=$DEFAULT_VERSION
fi
# ------------------------------
# Release Tag
# ------------------------------
if [ -z "$DEFAULT_PREFIX" ]
then
# Default tag prefix is 'v'
DEFAULT_PREFIX="v"
fi
if [ -z "$DEFAULT_TAG" ]
then
DEFAULT_TAG="$DEFAULT_PREFIX$version"
fi
# Skip input if auto is set
if [ -z "$auto" ]
then
# Ask for release tag
echo -n "Release tag ? [$DEFAULT_TAG] : "; read tag
fi
if [ -z "$tag" ]
then
tag=$DEFAULT_TAG
fi
# ------------------------------
# Snapshot Version
# ------------------------------
if [ -z "$DEFAULT_SNAPSHOT" ]
then
# Deduce next development version
SPLIT_VERSION=${version//./ }
OLD_IFS=$IFS
IFS=' '
read -ra SPLIT_VERSION <<< "$SPLIT_VERSION"
IFS=$OLD_IFS
NEW_MINOR=$( expr ${SPLIT_VERSION[1]} + 1 )
DEFAULT_SNAPSHOT="${SPLIT_VERSION[0]}.$NEW_MINOR-SNAPSHOT"
fi
# Skip input if auto is set
if [ -z "$auto" ]
then
echo -n "Next development version ? [$DEFAULT_SNAPSHOT] : "; read snapshot
fi
if [ -z "$snapshot" ]
then
snapshot=$DEFAULT_SNAPSHOT
fi
# ------------------------------
# Perform the release
# ------------------------------
echo "--------------------------------------------------"
echo "- Preparing release $version (tagged $tag)"
echo "--------------------------------------------------"
# Make sure we are on master and everything is up-to-date
git checkout master
git pull
# Set the release version in POM file
mvn versions:set -DnewVersion=$version
# Commit new POM
git add .
git commit -m "Prepare release $version"
git push
# Tag release
git tag $tag
git push --tags
echo "--------------------------------------------------"
echo "- Preparing next development version $snapshot"
echo "--------------------------------------------------"
# Set the next development version in POM file
mvn versions:set -DnewVersion=$snapshot
# Commit new POM
git add .
git commit -m "Prepare for next development version $snapshot"
git push
# ------------------------------
# Perform the release
# ------------------------------