forked from coin-or-tools/BuildTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare-release
executable file
·260 lines (219 loc) · 7.73 KB
/
prepare-release
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
260
#!/bin/bash
#
# This file is distributed under the Eclipse Public License 2.0.
# See LICENSE for details.
#set -x -v
set -e
if expr "$0" : '.*/.*' >/dev/null 2>&1 ; then
cmdDir=`dirname $0`
else
cmdDir='.'
fi
if test -r $cmdDir/coin-functions ; then
. $cmdDir/coin-functions
else
echo "Cannot find utility functions file coin-functions; exiting."
exit 1
fi
# process parameters
releaseStyle="reset"
while [ $# -ge 1 ] ; do
case "$1" in
-h | --help | --usage )
cat <<EOF
Usage: $0 { -h | --help | --usage | -t }
Options:
-h, --help, --usage Print this help and exit
-t Make sure release tag is visible on current branch
More details about -t:
If -t is specified, the script will commit the release version number
change (xx.yy -> xx.yy.zz) to the current branch, tag this commit, and
then adds another commit that reverts the tagged commit.
If -t is not specified, the script will also commit the release version
number change to the current branch, tag this commit, but then removes
the tagged commit from the current branch by resetting it.
Using -t has the advantage that the tag will be visible in the log of the
stable branch. Not using -t has the advantage that the temporary change in
the version number will not be part of the stable branch.
COIN-OR standard practice is to generate releases by taking a snapshot
of the stable branch of the project. This script can be used to prepare
a new release based on the currently checked out stable branch.
Thus, this script is supposed to be run from a directory that contains the
clone of a COIN-OR project and that has a branch named stable/X.Y checkout out.
This script will do the following:
- Automatically determine the next release number (X.Y.0 if this is the
first release for stable/X.Y, otherwise one greater than any existing
release)
- Update configure.ac to specify the release version number in the AC_INIT
macro and the corresponding libtool version number in the AC_COIN_INITIALIZE
macro.
- Execute run_autotools to update configure, Makefile.in, etc., to reflect
the most recent release of BuildTools and change in version number.
If there is any error during these tasks the script will stop and you should
examine the output.
If the script completes without error, examine the output, too.
This script does not make any changes to the remote repository, but prints
out the commands that should be issued to push the release tag or
to remove the release tag in the local clone.
EOF
exit 0
;;
-t | --ted )
releaseStyle="revert"
;;
*)
echo "Unknown argument. Run with -h to see usage."
exit 1
;;
esac
shift
done
if ! git diff --exit-code --quiet HEAD ; then
echo "EXIT: There are uncommitted changes. I'm too afraid to proceed."
exit 1
fi
# figure out name of project from repo URL, remove possible .git suffix
topProjName=`git remote get-url origin`
topProjName=${topProjName##*/}
topProjName=${topProjName/.git/}
echo "Project : $topProjName"
branchName=`git rev-parse --abbrev-ref HEAD`
echo "Branch : $branchName"
if [[ "$branchName" != stable/* ]] ; then
echo "ERROR: Expected branchname to start with 'stable/"
exit 1
fi
# get tags from remote
git fetch -t
# get last release from current stable branch
lastRelease=`git tag --list "${branchName/stable/releases}*" | sort -V | tail -1`
echo "Last Release : $lastRelease"
# figure out new release number
if [ -z "$lastRelease" ] ; then
# no last release, then take stable version and add .0
if [[ "$branchName" =~ ^stable/([0-9][0-9]*)\.([0-9][0-9]*) ]] ; then
majVer=${BASH_REMATCH[1]}
minVer=${BASH_REMATCH[2]}
relVer=0
else
echo "ERROR: Branchname does not match stable/xx.yy"
exit 1
fi
elif [[ "$lastRelease" =~ ^releases/([0-9][0-9]*)\.([0-9][0-9]*)\.([0-9][0-9]*)$ ]] ; then
majVer=${BASH_REMATCH[1]}
minVer=${BASH_REMATCH[2]}
relVer=${BASH_REMATCH[3]}
(( relVer += 1 ))
else
echo "ERROR: Last release name does not match releases/xx.yy.zz format"
exit 1
fi
newVer=${majVer}.${minVer}.${relVer}
echo "New release : releases/$newVer"
isNormal=yes
if test $isNormal = yes ; then
newLTCurrent=`calcLibtoolCurrent $majVer $minVer`
newLTRevision=$relVer
newLTAge=`calcLibtoolAge $majVer $minVer`
(( newLTAge -= 1 )) || :
newLTVer=${newLTCurrent}:${newLTRevision}:${newLTAge}
echo "Libtool version: $newLTVer"
fi
# Find configure.ac files and update the version.
echo ''
echo "===> Checking for configure.ac files ..."
confac_files=`find . -name 'configure.ac' -print`
if test -n "$confac_files" ; then
# Take the attitude that [] around parameters in AC_INIT is optional,
# it's the commas that count. This does make for a surpassing ugly regular
# expression. A comma in the version string will cause a spectacular failure.
# In AC_COIN_INITIALIZE, take the attitude that we only add a
# libtool version number as argument.
echo ''
echo "===> Updating version numbers in configure.ac files ..."
for i in $confac_files; do
sed -i -e "s|AC_INIT\([^,]*\),[^,]*,\(.*\)|AC_INIT\1,[$newVer],\2|" $i
sed -i -e "s|AC_COIN_INITIALIZE|AC_COIN_INITIALIZE\($newLTCurrent:$newLTRevision:$newLTAge\)|" $i
git diff $i
done
else
echo " ... none to process."
fi
# Find config_proj_default.h. If there's a definition for PROJ_VERSION, adjust it and
# add config_proj_default.h.bak to the list of files to be restored.
configFileLoc=`find . -name 'config_*_default.h' -print`
if test -n "$configFileLoc" ; then
versionSym=${topProjName^^}_VERSION
echo ''
echo "===> Updating $versionSym in $configFileLoc (if present)"
echo ''
sed -i -e "s/# *define $versionSym .*\$/#define $versionSym \"$newVer\"/" \
-e "s/# *define ${versionSym}_MAJOR .*\$/#define ${versionSym}_MAJOR $majVer/" \
-e "s/# *define ${versionSym}_MINOR .*\$/#define ${versionSym}_MINOR $minVer/" \
-e "s/# *define ${versionSym}_RELEASE .*\$/#define ${versionSym}_RELEASE $relVer/" \
$configFileLoc
git diff $configFileLoc
fi
if [ $topProjName != BuildTools ] ; then
buildtoolsDir=$cmdDir
echo ''
echo '===> Running $buildtoolsDir/run_autotools ...'
echo ''
[ -e BuildTools ] && mv BuildTools BuildTools.bak
$buildtoolsDir/run_autotools
[ -e BuildTools.bak ] && mv BuildTools.bak BuildTools
fi
if [ -e .coin-or/generate_readme ]; then
if [ x"${COINBREW_HOME-}" == x ]; then
if ! command -v coinbrew; then
export COINBREW_HOME=$(command -V coinbrew | head -n1 | cut -d ' ' -f 3)
else
echo "EXIT: To generate README, you must either have coinbrew in your"
echo " path or manually set COINBREW_HOME to the location of the"
echo " coinbrew repo."
exit 1
fi
fi
echo ''
echo '===> Generating README ...'
echo ''
COIN_VERSION_OVERRIDE=releases/$newVer bash .coin-or/generate_readme > README.md
git diff README.md
fi
echo ''
echo '===> Showing status, just to be sure ...'
echo ''
git status
echo ''
echo '===> Applying changes to local git clone ...'
echo ''
echo "Committing verion number update"
git commit -a -m "version number updates for release $newVer"
echo
echo "Tagging release: releases/$newVer"
git tag releases/$newVer
echo
if [ "$releaseStyle" = "reset" ] ;
then
echo "Resetting to original commit"
git reset --hard HEAD~1
else
echo "Reverting version number update"
git revert --no-edit HEAD
fi
echo ''
echo '===> Done ...'
echo ''
echo 'After reviewing the output above, you can push the new release via'
echo ''
echo " git push -u origin releases/$newVer"
echo ''
echo 'Alternatively, you can forget the locally committed release via'
echo ''
echo " git tag -d releases/$newVer"
if [ "$releaseStyle" = "revert" ] ;
then
echo " git reset --hard HEAD~2"
fi
echo
echo "Don't forget to also run update-doxygen, as appropriate!"