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