This repository has been archived by the owner on Mar 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.sh
executable file
·230 lines (186 loc) · 4.41 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
#!/bin/bash -x
TAG_VERSION=NONE
VERSION=$2
PUSH_CHANGES=${1:-false}
SKIP_CHANGELOG=$3
BRANCH=master
if [ "${PUSH_CHANGES}" == "true" ]; then
TARGET=deploy
else
TARGET=install
fi
do_push() {
if [ "${PUSH_CHANGES}" == "true" ]; then
echo "INFO: PUSHING changes."
git push
else
echo "INFO: not pushing changes."
fi
}
do_push_tag() {
if [ "${PUSH_CHANGES}" == "true" ]; then
echo "INFO: PUSHING tag ${TAG_VERSION}."
git push origin ${TAG_VERSION}
else
echo "INFO: not pushing tag."
fi
}
create_tag() {
if [ "${PUSH_CHANGES}" == "true" ]; then
echo "INFO: CREATING tag ${TAG_VERSION}."
git tag ${TAG_VERSION}
else
echo "INFO: not creating tag."
fi
}
# update pom.xml files for tag and next development version
tag_release() {
# make the release tag
(git add . ; git commit -m "release ${TAG_VERSION}"; do_push; create_tag; do_push_tag)
}
# update pom.xml files for tag and next development version
update_to_snapshot() {
# update to next development version
(git add . ; git commit -m "next development version"; do_push)
}
do_tag() {
echo "TAGGING ${TAG_VERSION}"
tag_release
echo
}
do_update() {
echo "UPDATING TO SNAPSHOT ${NEXT_RELEASE}"
update_to_snapshot
echo
}
update_pom_versions() {
v=$1
if [ "${v}" == "" ]; then
echo "missing version for pom version update"
exit 1
fi
mvn -Djvmargs="-Xmx1024M" \
-f pom.xml \
-B \
-DskipTests \
versions:set -DnewVersion=${v} -DgenerateBackupPoms=false
}
update_project_versions() {
v=$1
if [ "${v}" == "" ]; then
echo "missing version for project.clj version update"
exit 1
fi
echo 'Updating project.clj versions to ' ${v}
find . -name project.clj -exec sed -i.bck "s/^(defproject sixsq.nuvla.server\/api-jar .*/(defproject sixsq.nuvla.server\/api-jar \"${v}\"/" {} \;
}
update_changelog() {
changelog_file="CHANGELOG.md"
text="$1"
sed -i.bck "2i\\
${text}
" ${changelog_file}
}
do_changelog() {
changelog_ready="n"
while [[ "${changelog_ready}" == "n" ]]
do
release_headline="## [${TAG_VERSION}] - $(date +%Y-%m-%d)"
added='### Added'
changed='### Changed'
newline="placeholder"
while true
do
read -p "added (empty line to stop writing): " newline
if [[ -z $newline ]]
then
break
else
added=${added}' \
- '${newline}
fi
done
newline="placeholder"
while true
do
read -p "changed (empty line to stop writing): " newline
if [[ -z $newline ]]
then
break
else
changed=${changed}'\
- '${newline}
fi
done
full_changelog=${release_headline}'\
'${added}'\
'${changed}
printf "Your new CHANGELOG entry is:\n\n${full_changelog}\n\n"
read -p "continue? (y/n): " changelog_ready
done
update_changelog "${full_changelog}"
}
cleanup() {
rm versions.sh
mvn clean
git status
}
#
# automatically prepare the release version, if provided
#
if [[ ! -z $VERSION ]]
then
echo "INFO: updating project version to ${VERSION} before releasing"
if [[ "${VERSION}" != *"-SNAPSHOT" ]]
then
echo "ERR: new versions must include the SNAPSHOT suffix"
exit 1
fi
update_pom_versions ${VERSION}
# update_project_versions ${VERSION}
echo "INFO: pushing the updated project version into GitHub"
(git add . ; git commit -m "updating project to version ${VERSION}"; do_push)
echo "WARN: please confirm that all builds are successfull before releasing..."
exit 0
fi
#
# calculate the versions
#
mvn -Djvmargs="-Xmx1024M" \
-f pom.xml \
-B \
-DskipTests \
validate
source versions.sh
export TAG_VERSION
export NEXT_VERSION
echo ${TAG_VERSION}
echo ${NEXT_VERSION}
#
# add entries to CHANGELOG.md
#
if [ -z $SKIP_CHANGELOG ]; then
do_changelog
fi
#
# update to release version
#
update_pom_versions ${TAG_VERSION}
#update_project_versions ${TAG_VERSION}
#
# tag release
#
do_tag
#
# update to next snapshot version
#
update_pom_versions ${NEXT_VERSION}
#update_project_versions ${NEXT_VERSION}
#
# update master to snapshot
#
do_update
#
# cleanup
#
cleanup