]> git.evergreen-ils.org Git - working/Evergreen.git/blob - build/tools/make_release
Teach make_release to set the eg_version var
[working/Evergreen.git] / build / tools / make_release
1 #!/bin/bash
2
3 GIT_ABS=`git rev-parse --show-toplevel`
4 GIT_BRANCH=`git rev-parse --abbrev-ref HEAD | sed 's|.*/||'`
5 HEADURLBASE="http://git.evergreen-ils.org/Evergreen.git?h=refs/heads/"
6 HEADURL="$HEADURLBASE$GIT_BRANCH"
7
8 # Drop to the root of the checkout
9 cd $GIT_ABS
10
11 VERSION=AUTO # -v (version)
12 PREV_BRANCH=AUTO # -f (from)
13 PREV_VERSION=AUTO # -F (from version)
14 NO_UPGRADE=AUTO # -n
15 IS_PREVIEW=AUTO # -p
16 TAG_ONLY=NO # -t
17 BUILD_ONLY=NO # -b
18
19 while getopts ":hv:f:F:nptb" opt; do
20     case $opt in
21         v)
22             VERSION=$OPTARG
23         ;;
24         f)
25             PREV_BRANCH=$OPTARG
26         ;;
27         F)
28             PREV_VERSION=$OPTARG
29         ;;
30         n)
31             NO_UPGRADE=YES
32         ;;
33         p)
34             IS_PREVIEW=YES
35         ;;
36         t)
37             TAG_ONLY=YES
38         ;;
39         b)
40             BUILD_ONLY=YES
41         ;;
42         \?)
43             echo "Invalid Option: -$OPTARG"
44             exit 1
45         ;;
46         :)
47             echo "-$OPTARG requires an argument."
48             exit 1
49         ;;
50         h)
51             echo "$0 [-v VERSION] [-f PREV_BRANCH | -t | -b] [-F PREV_VERSION] [-n] [-p]"
52             echo "   VERSION is auto-detected by default and is based on the currently checked out branch."
53             echo "   PREV_BRANCH is auto-detected by default but that isn't reliable. Include remote name!"
54             echo "   PREV_VERSION Is auto-detected by default and is based on the PREV_BRANCH's name."
55             echo "   -n specifies that you don't want an upgrade script to be auto-generated."
56             echo "   -p specifies that this is a preview build."
57             echo "   -t turns on tag only mode."
58             echo "   -b turns on build only mode."
59             echo "   NOTE: -t and -b override PREV_BRANCH/PREV_VERSION, but -b overrides -t."
60             exit -1
61         ;;
62     esac
63 done
64
65 if [ $TAG_ONLY = "YES" ]; then
66     PREV_BRANCH="TAG"
67 fi
68
69 if [ $BUILD_ONLY = "YES" ]; then
70     PREV_BRANCH="PACKAGE"
71 fi
72
73 if [ $VERSION = "AUTO" ]; then
74     # Auto-pick version based on branch name
75     echo AUTO VERSION
76     VERSION=`echo $GIT_BRANCH | sed 's/^rel_\([0-9]\+\)_\([0-9]\+\)_\([0-9]\+\)_\(.\+\)$/\1.\2.\3-\4/'`
77     VERSION=`echo $VERSION | sed 's/^rel_\([0-9]\+\)_\([0-9]\+\)_\([0-9]\+\)$/\1.\2.\3/'`
78     VERSION=`echo $VERSION | sed 's/^rel_\([0-9]\+\)_\([0-9]\+\)_\(.\+\)$/\1.\2-\3/'`
79     VERSION=`echo $VERSION | sed 's/^rel_\([0-9]\+\)_\([0-9]\+\)$/\1.\2/'`
80     if [ "$VERSION" = "$GIT_BRANCH" ]; then
81         echo "AUTO VERSION FAILED."
82         exit 1
83     fi
84 fi
85 SHORT_VERSION=`echo $VERSION | grep -o '^[0-9]\+\.[0-9]\+'`
86 echo "Version: $VERSION Short: $SHORT_VERSION"
87
88 # prep a couple alternate represenations
89 DASH_VERSION=`echo $VERSION | sed 's/\./-/g'`
90 SHORT_DASH_VERSION=`echo $SHORT_VERSION | sed 's/\./-/g'`
91 UNDER_VERSION=`echo $VERSION | sed -e 's/\./_/g;s/-/_/g'`
92
93 PREVIEW_TEXT=""
94
95 if [ "$IS_PREVIEW" == "YES" ]; then
96     PREVIEW_TEXT="previews/"
97 fi
98
99 # Release Preamble
100 # For adding into README for release builds
101 # The head is used to check if we have it already (no need to add it twice)
102 RELEASE_PREAMBLE_HEAD="Preamble: Getting an Evergreen official release tarball"
103 RELEASE_PREAMBLE=$( cat <<PREAMBLE
104 $RELEASE_PREAMBLE_HEAD
105 -------------------------------------------------------
106
107 To download and extract the source for the current release of Evergreen, issue
108 the following commands as the *user* Linux account:
109
110 [source, bash]
111 ------------------------------------------------------------------------------
112 wget -c http://evergreen-ils.org/downloads/${PREVIEW_TEXT}Evergreen-ILS-$VERSION.tar.gz
113 tar xzf Evergreen-ILS-$VERSION.tar.gz
114 ------------------------------------------------------------------------------
115
116 PREAMBLE
117 )
118
119 # This defines what the preamble comes before
120 RELEASE_PREAMBLE_BEFORE="Preamble: Developer instructions"
121
122 if [ $PREV_BRANCH != "TAG" -a $PREV_BRANCH != "PACKAGE" ]; then
123     if [ $PREV_BRANCH = "AUTO" ]; then
124         echo "AUTO PREVIOUS BRANCH"
125         PREV_BRANCH=`echo ${UNDER_VERSION%_*}`
126         PREV_BRANCH=`git branch -r | grep "rel_${PREV_BRANCH}_[^_]\+$" | sort -rV | head -n1`
127         PREV_BRANCH=`echo $PREV_BRANCH`
128         read -p "Does branch $PREV_BRANCH look like the previous version (y/n)?"
129         if [ "$REPLY" != "y" -a "$REPLY" != 'Y' ]; then
130             echo "Please specify the previous branch as second parameter. To continue auto-version, use AUTO as first parameter."
131             exit 1
132         fi
133     fi
134     git show $PREV_BRANCH &>/dev/null
135     if [ $? -ne 0 -o -z "$PREV_BRANCH" ]; then
136         echo "PREVIOUS VERSION COMMIT NOT FOUND";
137         exit 1
138     fi
139     if [ $PREV_VERSION = "AUTO" ]; then
140         echo "AUTO PREVIOUS VERSION"
141         PREV_BRANCH_END=`echo $PREV_BRANCH | sed 's|.*/||'`
142         PREV_VERSION=`echo $PREV_BRANCH_END | sed 's/^rel_\([0-9]\+\)_\([0-9]\+\)_\([0-9]\+\)_\(.\+\)$/\1.\2.\3-\4/'`
143         PREV_VERSION=`echo $PREV_VERSION | sed 's/^rel_\([0-9]\+\)_\([0-9]\+\)_\([0-9]\+\)$/\1.\2.\3/'`
144         PREV_VERSION=`echo $PREV_VERSION | sed 's/^rel_\([0-9]\+\)_\([0-9]\+\)_\(.\+\)$/\1.\2-\3/'`
145         PREV_VERSION=`echo $PREV_VERSION | sed 's/^rel_\([0-9]\+\)_\([0-9]\+\)$/\1.\2/'`
146         if [ "$PREV_VERSION" = "$PREV_BRANCH_END" ]; then
147             echo "AUTO PREVIOUS VERSION FAILED."
148             exit 1
149         fi
150     fi
151     echo "Previous Version: $PREV_VERSION"
152 else
153     echo "Tagging or packaging, no need for previous version"
154 fi
155
156 if [ $PREV_BRANCH != "PACKAGE" ]; then
157
158     echo "Applying to Application.pm - HEAD -> $DASH_VERSION"
159     echo "Alt: $SHORT_DASH_VERSION -> $DASH_VERSION"
160     sed -i -e "s/\"$SHORT_DASH_VERSION[^\"]*\"/\"$DASH_VERSION\"/" -e "s/\"HEAD\"/\"$DASH_VERSION\"/" $GIT_ABS/Open-ILS/src/perlmods/lib/OpenILS/Application.pm
161
162     if [ -f "$GIT_ABS/Open-ILS/xul/staff_client/windowssetup.nsi" ]; then
163         echo "Applying to windowssetup.nsi - Master -> $SHORT_VERSION"
164         sed -i "s/Master/$SHORT_VERSION/" $GIT_ABS/Open-ILS/xul/staff_client/windowssetup.nsi
165     fi
166
167     echo "Applying to README:"
168     echo "STAMP_ID with $UNDER_VERSION"
169     sed -i -e "s/STAMP_ID=rel_[^ ]*/STAMP_ID=rel_$UNDER_VERSION/" $GIT_ABS/README
170
171     if [ $PREV_BRANCH != "TAG" ]; then
172         if [ "$(grep "$RELEASE_PREAMBLE_HEAD" $GIT_ABS/README )" ]; then
173             echo "Updating old download links"
174             sed -i -e "s|\(previews/\)\?Evergreen-ILS-.*\.tar\.gz|${PREVIEW_TEXT}Evergreen-ILS-$VERSION.tar.gz|" $GIT_ABS/README
175             sed -i -e "s| Evergreen-ILS-.*\.tar\.gz| Evergreen-ILS-$VERSION.tar.gz|" $GIT_ABS/README
176         else
177             echo "Adding Download Preamble"
178             perl -pi -e "s|^|$RELEASE_PREAMBLE\n\n| if /$RELEASE_PREAMBLE_BEFORE/" $GIT_ABS/README
179         fi
180     fi
181
182     echo "Applying to configure.ac:"
183     echo "AC_INIT and AM_INIT_AUTOMAKE entries"
184     sed -i -e "s/^\(AC_INIT(Open-ILS, \)[^,]*,/\1$VERSION,/" -e "s/^\(AM_INIT_AUTOMAKE(\[[^]]*], \[\)[^]]*]/\1$VERSION]/" configure.ac
185
186     echo "Finding/updating old \$HeadURL\$ entries"
187     HEADURLBASE=`echo ${HEADURLBASE} | sed 's/\?/\\?/'`
188     for file in `grep -Rl --exclude=make_release "$HEADURLBASE" $GIT_ABS`
189     do
190         echo $file
191         sed -i "s|${HEADURLBASE}[A-Za-z0-9_]*|$HEADURL|" $file
192     done
193
194     echo "Applying \$HeadURL\$ - $HEADURL"
195     for file in `grep -Rl --exclude=make_release '\\$HeadURL\\$' $GIT_ABS`
196     do
197         echo $file
198         sed -i "s|\\\$HeadURL\\\$|$HEADURL|" $file
199     done
200
201     if [ "$PREV_BRANCH" = "TAG" ]; then
202         echo "Committing (but not pushing) the lot of it"
203         git commit -asm "Tagging version"
204         exit 0;
205     fi
206
207     echo "Applying version to 002.schema.config.sql:"
208     echo "config.upgrade_log entry for $VERSION"
209     sed -i -e "s/\(INSERT INTO config.upgrade_log (version[^)]*) VALUES ('\)[0-9]*\('.*;\).*/&\n\1$VERSION\2/" $GIT_ABS/Open-ILS/src/sql/Pg/002.schema.config.sql;
210
211     if [ "$NO_UPGRADE" = "AUTO" ]; then
212         echo "Checking for DB upgrade potential...."
213         git ls-tree --name-only $PREV_BRANCH -- Open-ILS/src/sql/Pg/upgrade/ | cut -d/ -f6 | cut -d. -f1 | sort > old_upgrades.txt
214         git ls-tree --name-only HEAD -- Open-ILS/src/sql/Pg/upgrade/ | cut -d/ -f6 | cut -d. -f1 | sort > new_upgrades.txt
215         UPGRADE_CHECK=`diff old_upgrades.txt new_upgrades.txt | grep '^>' | cut -d' ' -f2`
216         UPGRADE_FILE=Open-ILS/src/sql/Pg/version-upgrade/$PREV_VERSION-$VERSION-upgrade-db.sql
217         if [ -f "$UPGRADE_FILE" ]; then
218             echo "Upgrade script for $PREV_VERSION-$VERSION already exists. Skipping."
219             UPGRADE_FILE=""
220         elif [ -n "$UPGRADE_CHECK" ]; then
221             echo "Found Upgrade Files! Building Upgrade Script."
222             echo "--Upgrade Script for $PREV_VERSION to $VERSION" > $UPGRADE_FILE
223             echo "\set eg_version '''$VERSION'''"
224             echo "BEGIN;" >> $UPGRADE_FILE
225             grep "config.upgrade_log.*$VERSION" Open-ILS/src/sql/Pg/002.schema.config.sql >> $UPGRADE_FILE
226             for NUM in $UPGRADE_CHECK; do
227                 cat Open-ILS/src/sql/Pg/upgrade/$NUM.* 2>/dev/null | grep -v '^\s*\(BEGIN\|COMMIT\);\s*$' >> $UPGRADE_FILE
228             done;
229             echo "COMMIT;" >> $UPGRADE_FILE
230             MAYBE_DUPES=`grep -oP 'CREATE (OR REPLACE )?FUNCTION +\K[^ ]*(?= *\()' $UPGRADE_FILE | sort | grep -P '^(.*)\n\1$' | sort -u`
231             if [ -n "$MAYBE_DUPES" ]; then
232                 echo ""
233                 echo "The following functions may be needlessly duplicated in the upgrade script:"
234                 echo "$MAYBE_DUPES"
235                 echo ""
236                 echo "For reference, I am writing the list to maybe_dupes.txt"
237                 echo "$MAYBE_DUPES" > maybe_dupes.txt
238             fi
239             echo ""
240             read -p "Please manually check the upgrade file."
241             ${EDITOR:-vi} $UPGRADE_FILE
242             git add $UPGRADE_FILE
243         fi
244     fi
245
246     grep -i -m 1 Signed-off-by ChangeLog &> /dev/null
247     if [ $? -ne 0 ]; then
248         echo "Building ChangeLog"
249         git log --cherry-pick --right-only --no-merges --pretty --summary --numstat $PREV_BRANCH..HEAD > $GIT_ABS/ChangeLog
250     else
251         echo "Not overwriting existing ChangeLog!"
252     fi
253
254     echo "Committing (but not pushing) the lot of it"
255     COMMIT_MESSAGE="Bumping version numbers and adding Changelog"
256     if [ -n "$UPGRADE_FILE" ]; then
257         COMMIT_MESSAGE="Bumping version numbers, adding Upgrade Script and Changelog"
258     fi
259     git commit -asm "$COMMIT_MESSAGE"
260 fi
261
262 echo "Building release dump"
263 cd $GIT_ABS
264 mkdir -p ../release
265 git archive --prefix=Evergreen-ILS-$VERSION/ HEAD | (cd ../release && tar xf -)
266 cd ../release/Evergreen-ILS-$VERSION
267 if [ -f ./autogen.sh ]; then
268     echo "Running autogen"
269     ./autogen.sh
270 else
271     echo "Running autoreconf"
272     autoreconf -i
273 fi
274 cd build/i18n
275 echo "Building i18n"
276 make install_all_locales
277 echo "i18n Cleanup"
278 cd ..
279 rm -rf i18n
280 echo "Installing Dojo"
281 cd ..
282 if [ ! -f "../dojo.tgz" ]; then
283     wget http://evergreen-ils.org/downloads/dojo.tgz -O ../dojo.tgz
284 fi
285 tar xzf ../dojo.tgz -C Open-ILS/web/js/dojo/
286 echo "Grabbing XULRunner (to avoid issues with version changes)"
287 cd Open-ILS/xul/staff_client
288 XULRUNNER_VERSION=`grep '^XULRUNNER_VERSION' Makefile.am`
289 XULRUNNER_VERSION=${XULRUNNER_VERSION##XULRUNNER_VERSION=}
290 wget http://ftp.mozilla.org/pub/mozilla.org/xulrunner/releases/$XULRUNNER_VERSION/runtimes/xulrunner-$XULRUNNER_VERSION.en-US.win32.zip
291 wget http://ftp.mozilla.org/pub/mozilla.org/xulrunner/releases/$XULRUNNER_VERSION/runtimes/xulrunner-$XULRUNNER_VERSION.en-US.linux-i686.tar.bz2
292 wget http://ftp.mozilla.org/pub/mozilla.org/xulrunner/releases/$XULRUNNER_VERSION/runtimes/xulrunner-$XULRUNNER_VERSION.en-US.linux-x86_64.tar.bz2
293
294 echo "Prepping server download files"
295 cd ../../../../
296 tar czf Evergreen-ILS-$VERSION.tar.gz Evergreen-ILS-$VERSION/
297 md5sum Evergreen-ILS-$VERSION.tar.gz > Evergreen-ILS-$VERSION.tar.gz.md5
298 if [ $PREV_BRANCH != "PACKAGE" ]; then # We need to have tagged to do this ;)
299     cp Evergreen-ILS-$VERSION/ChangeLog ChangeLog-$PREV_VERSION-$VERSION
300 fi
301
302 echo "Running enough of configure to build staff client"
303 cd Evergreen-ILS-$VERSION/
304 ./configure --disable-core --disable-web --disable-updates --disable-apache-modules --disable-reporter
305
306 echo "Building Release Staff Clients"
307 cd Open-ILS/xul/staff_client
308 make rigrelease
309 make STAFF_CLIENT_STAMP_ID=rel_$UNDER_VERSION build
310 make win-client
311 mv evergreen_staff_client_setup.exe ../../../../evergreen-setup-$VERSION.exe
312 make linux32-client
313 mv evergreen_staff_client_i686.tar.bz2 ../../../../evergreen-client-${VERSION}_i686.tar.bz2
314 make linux64-client
315 mv evergreen_staff_client_x86_64.tar.bz2 ../../../../evergreen-client-${VERSION}_x86_64.tar.bz2
316 cd ../../../../
317 md5sum evergreen-setup-$VERSION.exe > evergreen-setup-$VERSION.exe.md5
318 md5sum evergreen-client-${VERSION}_i686.tar.bz2 > evergreen-client-${VERSION}_i686.tar.bz2.md5
319 md5sum evergreen-client-${VERSION}_x86_64.tar.bz2 > evergreen-client-${VERSION}_x86_64.tar.bz2.md5
320
321
322 echo "Removing build directory"
323 rm -rf Evergreen-ILS-$VERSION/
324
325 echo ""
326 echo "FOR YOU TODO:"
327 echo "* TEST the release"
328 if [ $PREV_BRANCH != "PACKAGE" ]; then
329     echo "* Push release branch"
330 fi
331 echo "* Upload files"
332 echo "* Send emails"