-
Notifications
You must be signed in to change notification settings - Fork 7
/
prepare-stable
executable file
·172 lines (140 loc) · 4.73 KB
/
prepare-stable
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
#!/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
# process parameters
bumpMajor=0
while [ $# -ge 1 ] ; do
case "$1" in
-h | --help | --usage )
cat <<EOF
Usage: $0 { -h | --help | --usage }
Options:
-h, --help, --usage Print this help and exit
-m Bump the major version number.
This script is supposed to be run from a directory that contains the
clone of a COIN-OR project and will create a new stable branch from the
head of the currently checked out branch.
This script will do the following:
- Set the new stable version number as the next minor version number in
the current major version number. Use the -m flag to bump the major
version number.
- Run run_autotools to rebuild configure and make files.
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 new stable branch or
to remove the new stable branch in the local clone.
EOF
exit 0
;;
-m* | --m*) bumpMajor=1 ;;
*)
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"
# get branches from remote
git fetch
# get last stable branch
lastStable=`git branch --list -r "origin/stable/*" | sort -V | tail -1`
echo "Last Stable : $lastStable"
# figure out new stable number
if [ -z "$lastStable" ] ; then
# no last stable, then choose 0.1
majVer=0
minVer=1
elif [[ "$lastStable" =~ stable/([0-9][0-9]*)\.([0-9][0-9]*)$ ]] ; then
majVer=${BASH_REMATCH[1]}
minVer=${BASH_REMATCH[2]}
if test "$bumpMajor" = 1 ; then
(( majVer += 1 ))
minVer=0
else
(( minVer += 1 ))
fi
else
echo "ERROR: Last stable name does not match stable/xx.yy format"
exit 1
fi
newVer=${majVer}.${minVer}
echo "New Stable : stable/$newVer"
# 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_PROJECTDIR_INIT, take the attitude that we only add a
# libtool version number as argument.
echo ''
echo "===> Updating version number in configure.ac files ..."
for i in $confac_files; do
sed -i -e "s|AC_INIT\([^,]*\),[^,]*,\(.*\)|AC_INIT\1,[$newVer],\2|" $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 9999/" \
$configFileLoc
git diff $configFileLoc
fi
if [ $topProjName != BuildTools ] ; then
echo ''
echo '===> Running $cmdDir/run_autotools ...'
echo ''
[ -e BuildTools ] && mv BuildTools BuildTools.bak
$cmdDir/run_autotools
[ -e BuildTools.bak ] && mv BuildTools.bak BuildTools
fi
echo ''
echo '===> Committing changes to new branch new branch stable/$newVer in local git clone ...'
echo ''
echo "Create branch stable/$newVer"
git checkout -b stable/$newVer
echo "Committing verion number update"
git commit -a -m "version number update for branch stable/$newVer"
echo ''
echo '===> Done ...'
echo ''
echo 'After reviewing the output above, you can push the new branch via'
echo ''
echo " git push -u origin stable/$newVer"
echo ''
echo 'Alternatively, you can forget the locally committed branch via'
echo ''
echo " git checkout master"
echo " git branch -D stable/$newVer"