-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestkoha
executable file
·219 lines (186 loc) · 6.17 KB
/
testkoha
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
#!/bin/bash
#
# testkoha -- Automate some of the tedious tasks of testing patches
# Copyright 2011 Magnus Enger Libriotech
#
# This program 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 3 of the License, or
# (at your option) any later version.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
set -e
usage="Usage: $0 [--configfile /path/to/config] bugnumber"
everything_is_commited() {
if git status --short | grep -q '^'
then
return 1
else
return 0
fi
}
die() {
echo "$@" 1>&2
exit 1
}
signoff() {
git commit --amend -s
git bz attach -e $1 HEAD
# We don't send signedoff patches to the mail list any longer
# FIXME The name of the remote for the official repo should be configurable
# git send-email origin/master
echo "Please go to http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=$1 and change the Status to Signed Off."
}
# Check we have the correct number of arguments
[ $# -ge 1 ] && [ $# -le 3 ] || die $usage
# Set defaults and some other variables
KOHACLONE="/home/koha/kohaclone/"
DBDUMPDIR="/home/koha/kohatestdb/"
DBDUMP="testing.sql"
DBNAME="koha"
DBUSER="kohaadmin"
DBHOST="localhost"
DBPASS="katikoan"
DATE=$(date +%F)
# Get command line options
TEMP=`getopt -o c: -l configfile: -n "$0" -- "$@"`
eval set -- "$TEMP"
while true ; do
case "$1" in
-c|--configfile) configfile="$2" ; shift 2 ;;
--) shift ; break ;;
*) die "Internal error processing command line arguments" ;;
esac
done
# Load the configfile given on the command line
if [ "$configfile" != "" ]
then
if [ -e "$configfile" ]
then
. "$configfile"
else
die "$configfile does not exist.";
fi
fi
# Get the bug number
bugnumber="$1"
# Assemble the name of the DB dump
dbfile="$DBDUMPDIR/$DBDUMP"
# Check that the DB dump actually exists
if [ -e "$dbfile" ]
then
echo "OK, $dbfile exists"
else
die "$dbfile does not exist.";
fi
# Move to the directory that has the git repo
cd $KOHACLONE
# TODO Check that the current directory is a git repo
# Make sure there are no uncomitted changes
if ! everything_is_commited
then
die "Cannot proceed: uncommitted changes!"
else
echo "No uncommitted changes"
fi
# Say what we are going to do
cat <<eoh
Going to test bug number $bugnumber with the following parameters:
Koha directory: $KOHACLONE
Database dump: $dbfile
Dir of DB-files: $DBDUMPDIR
Database name: $DBNAME
Database user: $DBUSER
Database host: $DBHOST
Database password: ***
eoh
# Load the testing database
echo "Loading $dbfile"
mysql --host="$DBHOST" --user="$DBUSER" --password="$DBPASS" "$DBNAME" < $dbfile
# Make sure we are on the master branch before we proceed
git checkout master
# Update the code and the database
git pull
# TODO Delete this code:
# Create a directory for the temporary files, if it does not exist
# mytmpdir="${DBDUMPDIR}testkohatmp"
# if [ -e "$mytmpdir" ]
# then
# # TODO Check permissions
# echo "$mytmpdir exists"
# else
# mkdir "$mytmpdir"
# echo "Created $mytmpdir"
# fi
# TODO Remove this code
# Backup database
# echo "Dumping database..."
# dbtmpfile="$mytmpdir/backup.sql"
# mysqldump --host="$DBHOST" --user="$DBUSER" --password="$DBPASS" "$DBNAME" > $dbtmpfile
# Create a branch to test in
# FIXME What to do if the branch already exists?
git checkout -b bug$bugnumber origin/master
# Use git bz to get patches? Or ask for the URLs of patches as input?
git bz apply $bugnumber
# FIXME Ask the user if the patches applied cleanly
# If yes: proceed
# If no: - give the user a shell (screen?) to sort the situation out
# - tell the user to go to bugzilla and change status to "Does
# not apply", then clean up
# Update the database, after giving the user a chance to change
# updatedatabase.pl ($DBversion = '3.06.00.XXX';)
read -p "Do you want to edit updatedatabase.pl? [y/n] " -n1 editupdatedb
if [ $editupdatedb == 'y' ]; then
# This might be unnecessary once the new system for database
# updates is in place?
vim installer/data/mysql/updatedatabase.pl
fi
# Update the database
perl installer/data/mysql/updatedatabase.pl
# Let the user choose to run Koha's tests
# TODO Make this configurable through the config file: always/never/ask
# FIXME Looks like the whole script exits if the tests fail?
# while true; do
# read -p "Do you wish to run Koha's test suite? (yes/no) " yn
# case $yn in
# [Yy]* ) prove; break;;
# [Nn]* ) break;;
# * ) echo "Please answer yes or no.";;
# esac
# done
echo "Now test the changes!"
# TODO Let the user choose to enter a "screen" session, to be able to
# do stuff on the commandline while testing, without opening another
# terminal
# Ask if the user is ready to sign off
# FIXME Only works with one patch!
while true; do
read -p "Do you wish to sign off on that? [y/n] " so_yn
case $so_yn in
[Yy]* ) signoff $bugnumber; break;;
[Nn]* ) echo "Please go to http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=$bugnumber and report on why you do not want to sign off."; break;;
* ) echo "Please answer yes or no.";;
esac
done
# Clean up
# Check out master again
# TODO Let the user choose to keep or delete the branch
# FIXME This will fail if there are changes to e.g. updatedatabase
git checkout master
# Let the user choose to keep a dump of the database after testing
# Construct the filename
keepdbfile="$DBDUMPDIR/kohatest-bug$bugnumber-$DATE.sql"
while true; do
read -p "Do you wish to save a dump of the database [y/n] " keepdb_yn
case $keepdb_yn in
[Yy]* ) echo "Dumping database as $keepdbfile..."; mysql --host="$DBHOST" --user="$DBUSER" --password="$DBPASS" "$DBNAME" > "$keepdbfile"; break;;
[Nn]* ) echo "Database not dumped"; break;;
* ) echo "Please answer yes or no.";;
esac
done