forked from MagnusEnger/kohatesting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestkoha
executable file
·193 lines (161 loc) · 5.26 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
#!/bin/sh
#
# 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 Patch Status to Signed Off."
}
# Set defaults and read config file, if it exists.
KOHACLONE="~/kohaclone"
TMPDIR="/tmp/"
DBNAME="koha"
DBUSER="kohaadmin"
DBHOST="localhost"
DBPASS="katikoan"
[ $# -ge 1 ] && [ $# -le 3 ] || die $usage
TEMP=`getopt -o c: -l configfile: \
-n "$0" -- "$@"`
# Note the quotes around `$TEMP': they are essential!
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"
# Say what we are going to do
cat <<eoh
Going to test bug number $bugnumber with the following parameters:
Koha directory: $KOHACLONE
Temporary files: $TMPDIR
Database name: $DBNAME
Database user: $DBUSER
Database host: $DBHOST
Database password: ***
eoh
# 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
# Make sure we are on the master branch before we proceed
git checkout master
# Update the code and the database
git pull
perl installer/data/mysql/updatedatabase.pl
# Create a directory for the temporary files, if it does not exist
mytmpdir="${TMPDIR}testkohatmp"
if [ -e "$mytmpdir" ]
then
# TODO Check permissions
echo "$mytmpdir exists"
else
mkdir "$mytmpdir"
echo "Created $mytmpdir"
fi
# 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: tell the user to go to bugzilla and change status to "Does
# not apply", the clean up
# Update the database
# TODO Ask the user if she wants to edit updatedatabase.pl?
# This might be moot once the new system for database updates is in place
vim installer/data/mysql/updatedatabase.pl
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!"
# 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? (yes/no) " 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
# Restore database
while true; do
read -p "Do you wish to restore the database to what it was before this test (yes/no)" db_yn
case $db_yn in
[Yy]* ) echo "Restoring database..."; mysql --host="$DBHOST" --user="$DBUSER" --password="$DBPASS" "$DBNAME" < $dbtmpfile; break;;
[Nn]* ) echo "Database not restored"; break;;
* ) echo "Please answer yes or no.";;
esac
done
# Remove any files created during testing
rm $mytmpdir/*