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