-
Notifications
You must be signed in to change notification settings - Fork 1
/
test-release.sh
executable file
·225 lines (205 loc) · 9.67 KB
/
test-release.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/bin/bash
# Copyright 2012 C & P Bibliography Services
#
# This is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA
#
# Usage: test-release.sh [output directory]
#
# This script runs the tests necessary to ensure that a Koha release can be
# produced from the current git repository. It should be run from the root
# of the git repository. The results of the package and tarball builds will
# be placed in ~/releases or the directory specified by the command-line
# argument.
#
# This script honors the following environment variables:
# SKIP_TESTS: skip the unit test step
# SKIP_DEB: skip all steps related to package building and installation
# SKIP_TGZ: skip all steps related to tarball building and installation
# SKIP_INSTALL: skip testing the package and tarball installation
export PERL5LIB=`pwd`
RELTOOLS=$(cd $(dirname "$0"); pwd)
START=$(date +%s)
START_FMT=`date`
if [ -n "$1" ]; then
RELDIR=$1
else
RELDIR=$HOME/releases
fi
MARCFLAVOURS='MARC21 UNIMARC NORMARC'
BRANCH=`git branch | grep '*' | sed -e 's/^* //' -e 's#/#-#'`
VERSION=`grep 'VERSION = ' kohaversion.pl | sed -e "s/^[^']*'//" -e "s/';//"`
TEST_QA=1
TMPFILE=`tempfile`
PKGFILE=/dev/null
ARCHIVEFILE=$RELDIR/koha-$BRANCH-$VERSION.tar.gz
rm -f $ARCHIVEFILE
rm -f $RELDIR/errors.log
echo "[0;34;48mStarting release test at $START_FMT[0;30;48m"
echo -e "\tBranch: $BRANCH"
echo -e "\tVersion: $VERSION"
echo ""
if [ -z "$FAILURE" ] && [ -z "$SKIP_TESTS" ]; then
echo "Running unit tests..."
prove t/ t/db_dependent/ t/db_dependent/Labels xt/author/icondirectories.t xt/author/podcorrectness.t xt/author/translatable-templates.t xt/author/valid-templates.t xt/permissions.t xt/tt_valid.t > $TMPFILE 2>&1 || FAILURE='Unit tests'
fi
if [ -z "$FAILURE" ] && [ -z "$SKIP_DEB" ]; then
echo "Updating pbuilder..."
sudo pbuilder update > $TMPFILE 2>&1 || echo "[1;31;48mError updating pbuilder. Continuing anyway.[0;30;48m";
fi
if [ -z "$FAILURE" ] && [ -z "$SKIP_DEB" ]; then
echo "Building packages..."
[email protected] debian/build-git-snapshot -D $BRANCH -r $RELDIR > $TMPFILE 2>&1 || FAILURE='Building package';
PKGFILE=$RELDIR/`grep "dpkg-deb: building package .koha-common." $TMPFILE | sed -e 's#^[^/]*/##' | sed -e "s/'\.$//"`
if [ "$PKGFILE" = "$RELDIR/" ]; then FAILURE='Building package'; fi
fi
if [ -z "$FAILURE" ] && [ -z "$SKIP_TGZ" ]; then
echo "Preparing release tarball..."
git archive --format=tar --prefix=koha-$VERSION/ $BRANCH | gzip > $ARCHIVEFILE 2> $TMPFILE || FAILURE='Creating archive';
gpg -sb $ARCHIVEFILE || FAILURE='Signing archive';
md5sum $ARCHIVEFILE > $ARCHIVEFILE.MD5 || FAILURE='Md5summing archive';
gpg --clearsign $ARCHIVEFILE.MD5 || FAILURE='Signing md5sum';
fi
if [ -z "$FAILURE" ] && [ -z "$SKIP_DEB" ] && [ -z "$SKIP_INSTALL" ]; then
echo "Installing package..."
sudo dpkg -i $PKGFILE > $TMPFILE 2>&1 || FAILURE='Installing package';
cat > /tmp/koha-sites.conf <<EOF
OPACPORT=9003
INTRAPORT=9004
EOF
sudo mv /tmp/koha-sites.conf /etc/koha/koha-sites.conf
fi
for FLAVOUR in $MARCFLAVOURS; do
VAR=SKIP_$FLAVOUR
if [ -z "$FAILURE" ] && [ -z "$SKIP_DEB" ] && [ -z "$SKIP_INSTALL" ] && [ -z "${!VAR}" ]; then
echo "Installing from package for $FLAVOUR..."
if [ -z "$FAILURE" ]; then
echo " Running koha-create for $FLAVOUR..."
sudo koha-create --marcflavor=`echo $FLAVOUR | tr '[:upper:]' '[:lower:]'` --create-db pkgrel > $TMPFILE 2>&1 || FAILURE="Koha-create for $FLAVOUR";
fi
if [ -z "$FAILURE" ] && [ -z "$SKIP_WEBINSTALL" ]; then
echo " Running webinstaller for $FLAVOUR..."
prove $RELTOOLS/install-fresh.pl :: http://localhost:9004 http://localhost:9003 $FLAVOUR `sudo xmlstarlet sel -t -v 'yazgfs/config/user' '/etc/koha/sites/pkgrel/koha-conf.xml'` `sudo xmlstarlet sel -t -v 'yazgfs/config/pass' '/etc/koha/sites/pkgrel/koha-conf.xml'` > $TMPFILE 2>&1 || FAILURE="Running webinstaller for $FLAVOUR";
fi
echo " Cleaning up package install for $FLAVOUR..."
sudo koha-remove pkgrel > $TMPFILE 2>&1 || FAILURE="Koha-remove for $FLAVOUR"
fi
done
for FLAVOUR in $MARCFLAVOURS; do
VAR=SKIP_$FLAVOUR
if [ -z "$FAILURE" ] && [ -z "$SKIP_TGZ" ] && [ -z "$SKIP_INSTALL" ] && [ -z "${!VAR}" ]; then
echo "Installing from tarball for $FLAVOUR..."
export INSTALL_BASE=$RELDIR/fresh/koha
export DESTDIR=$RELDIR/fresh
export KOHA_CONF_DIR=$RELDIR/fresh/etc
export ZEBRA_CONF_DIR=$RELDIR/fresh/etc/zebradb
export PAZPAR2_CONF_DIR=$RELDIR/fresh/etc/pazpar2
export ZEBRA_LOCK_DIR=$RELDIR/fresh/var/lock/zebradb
export ZEBRA_DATA_DIR=$RELDIR/fresh/var/lib/zebradb
export ZEBRA_RUN_DIR=$RELDIR/fresh/var/run/zebradb
export LOG_DIR=$RELDIR/fresh/var/log
export INSTALL_MODE=standard
export DB_TYPE=mysql
export DB_HOST=localhost
export DB_NAME=koharel
export DB_USER=koharel
export DB_PASS=koharel
export INSTALL_ZEBRA=yes
export INSTALL_SRU=no
export INSTALL_PAZPAR2=no
export ZEBRA_MARC_FORMAT=`echo $FLAVOUR | tr '[:upper:]' '[:lower:]'`
export ZEBRA_LANGUAGE=en
export ZEBRA_USER=kohauser
export ZEBRA_PASS=zebrastripes
export KOHA_USER=`id -u -n`
export KOHA_GROUP=`id -g -n`
mkdir -p $RELDIR/fresh
tar zxvf $ARCHIVEFILE -C /tmp > $TMPFILE 2>&1 || FAILURE="Untarring tarball for $FLAVOUR"
cd /tmp/koha-$VERSION
if [ -z "$FAILURE" ]; then
echo -e " Running perl Makefile.PL for $FLAVOUR..."
yes '' | perl Makefile.PL > $TMPFILE 2>&1 || FAILURE="Running Makefile.PL for $FLAVOUR";
fi
if [ -z "$FAILURE" ]; then
echo -e " Running make for $FLAVOUR..."
make > $TMPFILE 2>&1 || FAILURE="Running make for $FLAVOUR";
fi
if [ -z "$FAILURE" ]; then
echo -e " Running make test for $FLAVOUR..."
make test > $TMPFILE 2>&1 || FAILURE="Running make test for $FLAVOUR";
fi
if [ -z "$FAILURE" ]; then
echo -e " Running make install for $FLAVOUR..."
make install > $TMPFILE 2>&1 || FAILURE="Running make install for $FLAVOUR";
sed -i -e 's/<VirtualHost 127.0.1.1:80>/<VirtualHost *:9001>/' -e 's/<VirtualHost 127.0.1.1:8080>/<VirtualHost *:9002>/' $RELDIR/fresh/etc/koha-httpd.conf
fi
if [ -z "$SKIP_WEBINSTALL" ]; then
if [ -z "$FAILURE" ]; then
mysql -u koharel -pkoharel -e "CREATE DATABASE koharel;" > $TMPFILE 2>&1 || FAILURE="Creating database for $FLAVOUR";
fi
if [ -z "$FAILURE" ]; then
echo " Adding to sites-available for $FLAVOUR..."
sudo ln -s $RELDIR/fresh/etc/koha-httpd.conf /etc/apache2/sites-available/release-fresh > $TMPFILE 2>&1 || FAILURE="Adding to sites-available for $FLAVOUR";
fi
if [ -z "$FAILURE" ]; then
echo " Enabling site for $FLAVOUR..."
sudo a2ensite release-fresh > $TMPFILE 2>&1 || FAILURE="Enabling site for $FLAVOUR";
fi
if [ -z "$FAILURE" ]; then
echo " Restarting Apache for $FLAVOUR..."
sudo apache2ctl restart > $TMPFILE 2>&1 || FAILURE="Restarting Apache for $FLAVOUR";
fi
if [ -z "$FAILURE" ]; then
echo " Running webinstaller for $FLAVOUR..."
prove $RELTOOLS/install-fresh.pl :: http://localhost:9002 http://localhost:9001 $FLAVOUR koharel koharel > $TMPFILE 2>&1 || FAILURE="Running webinstaller for $FLAVOUR";
fi
echo " Cleaning up for $FLAVOUR..."
mysql -u koharel -pkoharel -e "DROP DATABASE koharel;" > /dev/null 2>&1
sudo a2dissite release-fresh > /dev/null 2>&1
sudo apache2ctl restart > /dev/null 2>&1
sudo rm /etc/apache2/sites-available/release-fresh > /dev/null 2>&1
fi
rm -Rf /tmp/koha-$VERSION > /dev/null 2>&1
rm -Rf $RELDIR/fresh > /dev/null 2>&1
fi
done
if [ -n "$FAILURE" ]; then cp $TMPFILE $RELDIR/errors.log; fi
END=$(date +%s)
END_FMT=`date`
DIFF=$(( $END - $START ))
rm -f $TMPFILE
if [ -f $PKGFILE ]; then
echo "[0;32;48mPackage at [1;32;48m`ls $PKGFILE`[0;30;48m";
else
echo "[1;31;48mNo package built.[0;30;48m";
fi
if [ -f $ARCHIVEFILE ]; then
echo "[0;32;48mTarball at [1;32;48m`ls $ARCHIVEFILE`[0;30;48m";
else
echo "[1;31;48mNo tarball built.[0;30;48m";
fi
if [ -z "$FAILURE" ]; then
echo "[0;32;48mSuccessfully finished release test at $END_FMT in $DIFF seconds[0;30;48m";
echo -e "\tBranch: $BRANCH";
echo -e "\tVersion: $VERSION";
else
echo "[4;31;48m[1;31;48m$FAILURE[0;31;48m[1;31;48m failed in release test at $END_FMT in $DIFF seconds[0;30;48m";
echo "[0;31;48mError report at [1;31;48m$RELDIR/errors.log[0;30;48m";
echo -e "\tBranch: $BRANCH";
echo -e "\tVersion: $VERSION";
echo ""
read -p "Would you like to view the error log? (Y/n) " VIEWERROR;
if [ ! "x$VIEWERROR" = "xn" ]; then
less $RELDIR/errors.log
fi
fi