3 GIT_ABS=`git rev-parse --show-toplevel`
4 RELEASE_DIR=$GIT_ABS/../release/
5 GIT_BRANCH=`git rev-parse --abbrev-ref HEAD | sed 's|.*/||'`
6 HEADURLBASE="http://git.evergreen-ils.org/?p=Evergreen.git;a=shortlog;h=refs/heads/tags/"
7 HEADURL="$HEADURLBASE$GIT_BRANCH"
9 # Drop to the root of the checkout
12 VERSION=AUTO # -v (version)
13 PREV_BRANCH=AUTO # -f (from)
14 PREV_VERSION=AUTO # -F (from version)
19 UPGRADE_PREVIEW=NO # -r
21 SKIP_BUILD_BROWSER_CLIENT=NO # -C
27 # path to OpenSRF libraries
28 [ "$(which osrf_config)" ] && OSRF_JS_PATH="$(osrf_config --libdir)/javascript";
31 while getopts ":hv:f:F:nptbrij:CH:D:U:P:O:" opt; do
62 OSRF_JS_PATH="$OPTARG"
65 SKIP_BUILD_BROWSER_CLIENT=YES
80 echo "Invalid Option: -$OPTARG"
84 echo "-$OPTARG requires an argument."
88 echo "$0 [-v VERSION] [-f PREV_BRANCH | -t | -b] [-F PREV_VERSION] [-n] [-p]"
89 echo " VERSION is auto-detected by default and is based on the currently checked out branch."
90 echo " PREV_BRANCH is auto-detected by default but that isn't reliable. Include remote name!"
91 echo " PREV_VERSION Is auto-detected by default and is based on the PREV_BRANCH's name."
92 echo " -n specifies that you don't want an upgrade script to be auto-generated."
93 echo " -p specifies that this is a preview build."
94 echo " -t turns on tag only mode."
95 echo " -b turns on build only mode."
96 echo " -r prompt to preview upgrade SQL in editor before committing."
97 echo " -i skip i18n; primarily useful for (quickly) testing this script."
98 echo " -j opensrf javascript library path. If osrf_config is found, the value derived from osrf_config --libdir."
99 echo " -C Skip building the browser client. Useful only if all you want to do is generate the DB update script."
100 echo " -H Postgres [H]ostname (optional)"
101 echo " -D Postgres [D]atabase name (optional)"
102 echo " -U Postgres [U]sername (optional)"
103 echo " -P Postgres [P]assword (optional)"
104 echo " -O Postgres p[O]rt"
106 echo " Postgres credentials are used to invoke the EXPERIMENTAL"
107 echo " feature to update the Enhanced Concerto dataset."
109 echo " The provided Pg credentials needs to have permissions to create"
110 echo " databases; using a Pg superuser will be most convenient."
112 echo " The commit created by the process to update the dataset"
113 echo " should be thoroughly reviewed before producing the release."
115 echo " Generally, the update of the Enhanced Concerto dataset should"
116 echo " be done and tested well before the release tarball is built; the main"
117 echo " dependency is when the database schema becomes stable for the"
118 echo " release, particularly changes that add or remove tables or"
121 echo " NOTE: -t and -b override PREV_BRANCH/PREV_VERSION, but -b overrides -t."
127 if [ -z "$OSRF_JS_PATH" ]; then
128 echo "Unable to find OpenSRF JavaScript library path. Specify with -j";
132 if [ "$TAG_ONLY" == "YES" ]; then
136 if [ "$BUILD_ONLY" == "YES" ]; then
137 PREV_BRANCH="PACKAGE"
140 if [ "$VERSION" == "AUTO" ]; then
141 # Auto-pick version based on branch name
143 VERSION=`echo $GIT_BRANCH | sed 's/^rel_\([0-9]\+\)_\([0-9]\+\)_\([0-9]\+\)_\(.\+\)$/\1.\2.\3-\4/'`
144 VERSION=`echo $VERSION | sed 's/^rel_\([0-9]\+\)_\([0-9]\+\)_\([0-9]\+\)$/\1.\2.\3/'`
145 VERSION=`echo $VERSION | sed 's/^rel_\([0-9]\+\)_\([0-9]\+\)_\(.\+\)$/\1.\2-\3/'`
146 VERSION=`echo $VERSION | sed 's/^rel_\([0-9]\+\)_\([0-9]\+\)$/\1.\2/'`
147 if [ "$VERSION" = "$GIT_BRANCH" ]; then
148 echo "AUTO VERSION FAILED."
152 SHORT_VERSION=`echo $VERSION | grep -o '^[0-9]\+\.[0-9]\+'`
153 echo "Version: $VERSION Short: $SHORT_VERSION"
155 # prep a couple alternate represenations
156 DASH_VERSION=`echo $VERSION | sed 's/\./-/g'`
157 SHORT_DASH_VERSION=`echo $SHORT_VERSION | sed 's/\./-/g'`
158 UNDER_VERSION=`echo $VERSION | sed -e 's/\./_/g;s/-/_/g'`
162 if [ "$IS_PREVIEW" == "YES" ]; then
163 PREVIEW_TEXT="previews/"
167 # For adding into README for release builds
168 # The head is used to check if we have it already (no need to add it twice)
169 RELEASE_PREAMBLE_HEAD="Preamble: Getting an Evergreen official release tarball"
170 RELEASE_PREAMBLE=$( cat <<PREAMBLE
171 $RELEASE_PREAMBLE_HEAD
172 -------------------------------------------------------
174 To download and extract the source for the current release of Evergreen, issue
175 the following commands as the *user* Linux account:
178 ------------------------------------------------------------------------------
179 wget -c http://evergreen-ils.org/downloads/${PREVIEW_TEXT}Evergreen-ILS-$VERSION.tar.gz
180 tar xzf Evergreen-ILS-$VERSION.tar.gz
181 ------------------------------------------------------------------------------
186 # This defines what the preamble comes before
187 RELEASE_PREAMBLE_BEFORE="Preamble: Developer instructions"
189 if [ "$PREV_BRANCH" != "TAG" -a "$PREV_BRANCH" != "PACKAGE" ]; then
190 if [ "$PREV_BRANCH" == "AUTO" ]; then
191 echo "AUTO PREVIOUS BRANCH"
192 PREV_BRANCH=`echo ${UNDER_VERSION%_*}`
193 PREV_BRANCH=`git branch -r | grep "rel_${PREV_BRANCH}_[^_]\+$" | sort -rV | head -n1`
194 PREV_BRANCH=`echo $PREV_BRANCH`
195 read -p "Does branch $PREV_BRANCH look like the previous version (y/n)?"
196 if [ "$REPLY" != "y" -a "$REPLY" != 'Y' ]; then
197 echo "Please specify the previous branch as second parameter. To continue auto-version, use AUTO as first parameter."
201 git show $PREV_BRANCH &>/dev/null
202 if [ $? -ne 0 -o -z "$PREV_BRANCH" ]; then
203 echo "PREVIOUS VERSION COMMIT NOT FOUND";
206 if [ "$PREV_VERSION" == "AUTO" ]; then
207 echo "AUTO PREVIOUS VERSION"
208 PREV_BRANCH_END=`echo $PREV_BRANCH | sed 's|.*/||'`
209 PREV_VERSION=`echo $PREV_BRANCH_END | sed 's/^rel_\([0-9]\+\)_\([0-9]\+\)_\([0-9]\+\)_\(.\+\)$/\1.\2.\3-\4/'`
210 PREV_VERSION=`echo $PREV_VERSION | sed 's/^rel_\([0-9]\+\)_\([0-9]\+\)_\([0-9]\+\)$/\1.\2.\3/'`
211 PREV_VERSION=`echo $PREV_VERSION | sed 's/^rel_\([0-9]\+\)_\([0-9]\+\)_\(.\+\)$/\1.\2-\3/'`
212 PREV_VERSION=`echo $PREV_VERSION | sed 's/^rel_\([0-9]\+\)_\([0-9]\+\)$/\1.\2/'`
213 if [ "$PREV_VERSION" == "$PREV_BRANCH_END" ]; then
214 echo "AUTO PREVIOUS VERSION FAILED."
218 echo "Previous Version: $PREV_VERSION"
220 echo "Tagging or packaging, no need for previous version"
223 if [ "$PREV_BRANCH" != "PACKAGE" ]; then
225 echo "Applying to Application.pm - HEAD -> $DASH_VERSION"
226 echo "Alt: $SHORT_DASH_VERSION -> $DASH_VERSION"
227 sed -i -e "s/\"$SHORT_DASH_VERSION[^\"]*\"/\"$DASH_VERSION\"/" -e "s/\"HEAD\"/\"$DASH_VERSION\"/" $GIT_ABS/Open-ILS/src/perlmods/lib/OpenILS/Application.pm
229 echo "Applying to README:"
231 if [ "$PREV_BRANCH" != "TAG" ]; then
232 if [ "$(grep "$RELEASE_PREAMBLE_HEAD" $GIT_ABS/README )" ]; then
233 echo "Updating old download links"
234 sed -i -e "s|\(previews/\)\?Evergreen-ILS-.*\.tar\.gz|${PREVIEW_TEXT}Evergreen-ILS-$VERSION.tar.gz|" $GIT_ABS/README
235 sed -i -e "s| Evergreen-ILS-.*\.tar\.gz| Evergreen-ILS-$VERSION.tar.gz|" $GIT_ABS/README
237 echo "Adding Download Preamble"
238 perl -pi -e "s|^|$RELEASE_PREAMBLE\n\n| if /$RELEASE_PREAMBLE_BEFORE/" $GIT_ABS/README
242 echo "Applying to configure.ac:"
243 echo "AC_INIT and AM_INIT_AUTOMAKE entries"
244 sed -i -e "s/^\(AC_INIT(Open-ILS, \)[^,]*,/\1$VERSION,/" -e "s/^\(AM_INIT_AUTOMAKE(\[[^]]*], \[\)[^]]*]/\1$VERSION]/" configure.ac
246 echo "Finding/updating old \$HeadURL\$ entries"
247 HEADURLBASE=`echo ${HEADURLBASE} | sed 's/\?/\\?/'`
248 for file in `grep -Rl --exclude=make_release "$HEADURLBASE" $GIT_ABS`
251 sed -i "s|${HEADURLBASE}[A-Za-z0-9_]*|$HEADURL|" $file
254 echo "Applying \$HeadURL\$ - $HEADURL"
255 for file in `grep -Rl --exclude=make_release '\\$HeadURL\\$' $GIT_ABS`
258 sed -i "s|\\\$HeadURL\\\$|$HEADURL|" $file
261 if [ "$PREV_BRANCH" = "TAG" ]; then
262 echo "Committing (but not pushing) the lot of it"
263 git commit -asm "Tagging version"
267 echo "Applying version to 002.schema.config.sql:"
268 echo "config.upgrade_log entry for $VERSION"
269 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;
271 if [ "$NO_UPGRADE" == "AUTO" ]; then
272 echo "Checking for DB upgrade potential...."
273 git ls-tree --name-only $PREV_BRANCH -- Open-ILS/src/sql/Pg/upgrade/ | cut -d/ -f6 | cut -d. -f1 | sort > old_upgrades.txt
274 git ls-tree --name-only HEAD -- Open-ILS/src/sql/Pg/upgrade/ | cut -d/ -f6 | cut -d. -f1 | sort > new_upgrades.txt
275 UPGRADE_CHECK=`diff old_upgrades.txt new_upgrades.txt | grep '^>' | cut -d' ' -f2`
276 UPGRADE_FILE=Open-ILS/src/sql/Pg/version-upgrade/$PREV_VERSION-$VERSION-upgrade-db.sql
277 if [ -f "$UPGRADE_FILE" ]; then
278 echo "Upgrade script for $PREV_VERSION-$VERSION already exists. Skipping."
281 echo "Building Upgrade Script."
282 echo "--Upgrade Script for $PREV_VERSION to $VERSION" > $UPGRADE_FILE
283 echo "\set eg_version '''$VERSION'''" >> $UPGRADE_FILE
284 echo "BEGIN;" >> $UPGRADE_FILE
285 grep "config.upgrade_log.*$VERSION" Open-ILS/src/sql/Pg/002.schema.config.sql >> $UPGRADE_FILE
286 for NUM in $UPGRADE_CHECK; do
287 cat Open-ILS/src/sql/Pg/upgrade/$NUM.* 2>/dev/null | grep -v '^\s*\(BEGIN\|COMMIT\);\s*$' >> $UPGRADE_FILE
289 echo "COMMIT;" >> $UPGRADE_FILE
290 #Add call to auditor.update_auditors() to keep auditor tables up to date
291 echo "" >> $UPGRADE_FILE
292 echo "-- Update auditor tables to catch changes to source tables." >> $UPGRADE_FILE
293 echo "-- Can be removed/skipped if there were no schema changes." >> $UPGRADE_FILE
294 echo "SELECT auditor.update_auditors();" >> $UPGRADE_FILE
295 MAYBE_DUPES=`grep -oP 'CREATE (OR REPLACE )?FUNCTION +\K[^ ]*(?= *\()' $UPGRADE_FILE | sort | grep -P '^(.*)\n\1$' | sort -u`
296 if [ -n "$MAYBE_DUPES" ]; then
298 echo "The following functions may be needlessly duplicated in the upgrade script:"
301 echo "For reference, I am writing the list to maybe_dupes.txt"
302 echo "$MAYBE_DUPES" > maybe_dupes.txt
305 if [ "$UPGRADE_PREVIEW" = "YES" ]; then
306 read -p "Please manually check the upgrade file."
307 ${EDITOR:-vi} $UPGRADE_FILE
309 git add $UPGRADE_FILE
313 grep -i -m 1 Signed-off-by ChangeLog &> /dev/null
314 if [ $? -ne 0 ]; then
315 echo "Building ChangeLog"
316 git log --cherry-pick --right-only --no-merges --pretty --summary --numstat $PREV_BRANCH...HEAD > $GIT_ABS/ChangeLog
318 echo "Not overwriting existing ChangeLog!"
321 echo "Committing (but not pushing) the lot of it"
322 COMMIT_MESSAGE="Bumping version numbers and adding Changelog"
323 if [ -n "$UPGRADE_FILE" ]; then
324 COMMIT_MESSAGE="Bumping version numbers, adding Upgrade Script and Changelog"
326 git commit -asm "$COMMIT_MESSAGE"
327 if [ "$PG_HOST" != "NONE" ]; then
328 echo "Attempting auto-upgrade for Enhanced Concerto Dataset"
329 $GIT_ABS/Open-ILS/src/support-scripts/make_concerto_from_evergreen_db.pl \
330 --db-host "$PG_HOST" --db-user "$PG_USER" --db-pass "$PG_PASS" --db-port "$PG_PORT" \
331 --output-folder "$GIT_ABS/Open-ILS/tests/datasets/sql/concerto_enhanced" \
332 --evergreen-repo "$GIT_ABS" \
336 if [ $? -ne 0 ]; then
337 echo "Failed to auto-upgrade the Enhanced Concerto Dataset"
338 echo "Proceeding without it"
339 read -p "Press [Enter] key to continue"
341 echo "Committing Enhanced Concerto Dataset to git"
342 COMMIT_MESSAGE="Upgrade Enhanced Concerto Dataset"
343 git commit -asm "$COMMIT_MESSAGE"
348 echo "Building release dump"
351 git archive --prefix=Evergreen-ILS-$VERSION/ HEAD | (cd ../release && tar xf -)
352 cd ../release/Evergreen-ILS-$VERSION
353 if [ -f ./autogen.sh ]; then
354 echo "Running autogen"
357 echo "Running autoreconf"
361 if [ "$SKIP_I18N" == "NO" ]; then
364 make install_all_locales
371 echo "Installing Dojo"
372 if [ ! -f "../dojo.tgz" ]; then
373 wget http://evergreen-ils.org/downloads/dojo.tgz -O ../dojo.tgz
375 tar xzf ../dojo.tgz -C Open-ILS/web/js/dojo/
377 echo "Prepping server download files"
379 if [ "$SKIP_BUILD_BROWSER_CLIENT" == "NO" ]; then
380 # AngularJS staff client
381 cd $RELEASE_DIR/Evergreen-ILS-$VERSION
382 echo "Building AngularJS browser staff client"
383 cd Open-ILS/web/js/ui/default/staff/
384 npm install # fetch build dependencies
385 npm run build-prod # copy to build dir and minify JS files
386 # npm cache is big and unnecessary in the final build. remove it.
388 cd ../../../../../ # Open-ILS dir
392 npm install # fetch dependencies
393 # and leave them in node_modules; there's no build step
394 cd ../../.. # Open-ILS dir
396 # Angular staff client
397 echo "Building Angular browser staff client"
399 npm install # fetch build dependencies
400 ng build --configuration production --localize true
401 # npm cache is big and unnecessary in the final build. remove it.
403 # similarly, the .angular directory, which includes the build
404 # cache, need not be shipped in the release tarball
407 echo "Skipping browser client build"
411 tar czf Evergreen-ILS-$VERSION.tar.gz Evergreen-ILS-$VERSION/
412 md5sum Evergreen-ILS-$VERSION.tar.gz > Evergreen-ILS-$VERSION.tar.gz.md5
413 if [ $PREV_BRANCH != "PACKAGE" ]; then # We need to have tagged to do this ;)
414 cp Evergreen-ILS-$VERSION/ChangeLog ChangeLog-$PREV_VERSION-$VERSION
417 echo "Removing build directory"
418 rm -rf Evergreen-ILS-$VERSION/
422 echo "* TEST the release"
423 if [ "$PREV_BRANCH" != "PACKAGE" ]; then
424 echo "* Push release branch"
426 echo "* Upload files"