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