forked from dadoonet/fscrawler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.sh
executable file
·259 lines (219 loc) · 7.52 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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#!/bin/sh
# save current dir
CUR_DIR=`pwd`
SCRIPT="$0"
# SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path.
while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
# Drop everything prior to ->
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT=`dirname "$SCRIPT"`/"$link"
fi
done
# Read a value and fallback to a default value
readvalue () {
read -p "$1 [$2]:" value
if [ -z "$value" ]; then
value=$2
fi
echo ${value}
}
increment_version ()
{
declare -a part=( ${1//\./ } )
declare new
declare -i carry=1
for (( CNTR=${#part[@]}-1; CNTR>=0; CNTR-=1 )); do
len=${#part[CNTR]}
new=$((part[CNTR]+carry))
[ ${#new} -gt ${len} ] && carry=1 || carry=0
[ ${CNTR} -gt 0 ] && part[CNTR]=${new: -len} || part[CNTR]=${new}
done
new="${part[*]}"
echo "${new// /.}"
}
promptyn () {
while true; do
read -p "$1 [Y]/N? " yn
if [ -z "$yn" ]; then
yn="y"
fi
case ${yn:-$2} in
[Yy]* ) return 0;;
[Nn]* ) return 1;;
* ) echo "Please answer yes or no.";;
esac
done
}
test_against_version () {
echo "Building and testing the release..."
mvn clean install -Prelease ${MAVEN_OPTION} >> /tmp/fscrawler-${RELEASE_VERSION}.log
if [ $? -ne 0 ]
then
tail -20 /tmp/fscrawler-${RELEASE_VERSION}.log
echo "Something went wrong. Full log available at /tmp/fscrawler-$RELEASE_VERSION.log"
exit 1
fi
}
# determine fscrawler home
FS_HOME=`dirname "$SCRIPT"`
# make FS_HOME absolute
FS_HOME=`cd "$FS_HOME"; pwd`
DRY_RUN=0
# Enter project dir
cd "$FS_HOME"
CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD`
CURRENT_VERSION=`mvn help:evaluate -Dexpression=project.version|grep -Ev '(^\[|Download\w+:)'`
echo "Setting project version for branch $CURRENT_BRANCH. Current is $CURRENT_VERSION."
RELEASE_VERSION=$(readvalue "Enter the release version" ${CURRENT_VERSION%-SNAPSHOT})
NEXT_VERSION_P=`increment_version ${RELEASE_VERSION}`
NEXT_VERSION=$(readvalue "Enter the next snapshot version" ${NEXT_VERSION_P}-SNAPSHOT)
MAVEN_OPTION=$(readvalue "Enter any maven option you want to add" "")
RELEASE_BRANCH=release-${RELEASE_VERSION}
if [ "${CURRENT_BRANCH}" = "${RELEASE_BRANCH}" ]
then
echo "WARN: you are running the script from the release branch. You might want to switch to another branch first."
fi
echo "STARTING LOGS FOR $RELEASE_VERSION..." > /tmp/fscrawler-${RELEASE_VERSION}.log
# Check if the release already exists
git show-ref --tags | grep -q fscrawler-${RELEASE_VERSION}
if [ $? -eq 0 ]
then
if promptyn "Tag fscrawler-$RELEASE_VERSION already exists. Do you want to remove it?"
then
git tag -d "fscrawler-$RELEASE_VERSION"
else
echo "To remove it manually, run:"
echo "tag -d fscrawler-$RELEASE_VERSION"
exit 1
fi
fi
# Create a git branch
echo "Creating release branch $RELEASE_BRANCH..."
git branch | grep -q ${RELEASE_BRANCH}
if [ $? -eq 0 ]
then
git branch -D ${RELEASE_BRANCH}
fi
git checkout -q -b ${RELEASE_BRANCH}
echo "Changing maven version to $RELEASE_VERSION..."
mvn versions:set -DnewVersion=${RELEASE_VERSION} >> /tmp/fscrawler-${RELEASE_VERSION}.log
# We need to also commit files that changed for documentation
mvn clean process-resources >> /tmp/fscrawler-${RELEASE_VERSION}.log
# Git commit release
git commit -q -a -m "prepare release fscrawler-$RELEASE_VERSION"
# The actual build is made against latest version
test_against_version
# Just display the end of the build
tail -7 /tmp/fscrawler-${RELEASE_VERSION}.log
# Tagging
echo "Tag version with fscrawler-$RELEASE_VERSION"
git tag -a fscrawler-${RELEASE_VERSION} -m "Release FsCrawler version $RELEASE_VERSION"
if [ $? -ne 0 ]
then
tail -20 /tmp/fscrawler-${RELEASE_VERSION}.log
echo "Something went wrong. Full log available at /tmp/fscrawler-$RELEASE_VERSION.log"
exit 1
fi
# Preparing announcement
echo "Preparing announcement"
mvn changes:announcement-generate >> /tmp/fscrawler-${RELEASE_VERSION}.log
echo "Check the announcement message"
cat target/announcement/announcement.vm
if promptyn "Is message ok?"
then
echo "Message will be sent after the release"
else
exit 1
fi
# Do we really want to publish artifacts?
RELEASE=0
if promptyn "Everything is ready and checked. Do you want to release now?"
then
RELEASE=1
# Deploying the version to final repository
echo "Deploying artifacts to remote repository"
if [ ${DRY_RUN} -eq 0 ]
then
mvn deploy -DskipTests -Prelease >> /tmp/fscrawler-${RELEASE_VERSION}.log
if [ $? -ne 0 ]
then
tail -20 /tmp/fscrawler-${RELEASE_VERSION}.log
echo "Something went wrong. Full log available at /tmp/fscrawler-$RELEASE_VERSION.log"
exit 1
fi
fi
fi
echo "Changing maven version to $NEXT_VERSION..."
mvn versions:set -DnewVersion=${NEXT_VERSION} >> /tmp/fscrawler-${RELEASE_VERSION}.log
# We need to also commit files that changed for documentation
mvn clean process-resources >> /tmp/fscrawler-${RELEASE_VERSION}.log
git commit -q -a -m "prepare for next development iteration"
# git checkout branch we started from
git checkout -q ${CURRENT_BRANCH}
if [ ${DRY_RUN} -eq 0 ]
then
echo "Inspect Sonatype staging repositories"
open https://s01.oss.sonatype.org/#stagingRepositories
if promptyn "Is the staging repository ok?"
then
echo "releasing the nexus repository"
mvn nexus-staging:release >> /tmp/fscrawler-${RELEASE_VERSION}.log
else
echo "dropping the nexus repository"
RELEASE=0
mvn nexus-staging:drop >> /tmp/fscrawler-${RELEASE_VERSION}.log
fi
fi
if [ ${DRY_RUN} -eq 0 ]
then
echo "Inspect DockerHub"
open https://hub.docker.com/r/dadoonet/fscrawler/tags
if promptyn "Is the DockerHub repository ok?"
then
echo "We can continue the release process."
else
echo "We cancel the release process."
RELEASE=0
fi
fi
# We are releasing, so let's merge into the original branch
if [ ${RELEASE} -eq 1 ]
then
echo "Merging changes into ${CURRENT_BRANCH}"
git merge -q ${RELEASE_BRANCH}
git branch -q -d ${RELEASE_BRANCH}
echo "Push changes to origin"
if [ ${DRY_RUN} -eq 0 ]
then
git push origin ${CURRENT_BRANCH} fscrawler-${RELEASE_VERSION}
if promptyn "Do you want to announce the release?"
then
# We need to checkout the tag, announce and checkout the branch we started from
git checkout -q fscrawler-${RELEASE_VERSION}
SMTP_USERNAME=$(readvalue "Enter your SMTP username" "david@pilato.fr")
SMTP_PASSWORD=$(readvalue "Enter your SMTP password" "")
mvn changes:announcement-mail -Dchanges.username=${SMTP_USERNAME} -Dchanges.password=${SMTP_PASSWORD} >> /tmp/fscrawler-${RELEASE_VERSION}.log
if [ $? -ne 0 ]
then
tail -20 /tmp/fscrawler-${RELEASE_VERSION}.log
echo "We have not been able to send the email. Full log available at /tmp/fscrawler-$RELEASE_VERSION.log"
fi
git checkout -q ${CURRENT_BRANCH}
else
echo "Message not sent. You can send it manually using:"
echo "mvn changes:announcement-mail"
fi
fi
else
if promptyn "Do you want to remove $RELEASE_BRANCH branch and fscrawler-${RELEASE_VERSION} tag?"
then
git branch -q -D ${RELEASE_BRANCH}
git tag -d fscrawler-${RELEASE_VERSION}
fi
fi
# Go back in current dir
cd "$CUR_DIR"