forked from github/server
refactoring the pre-release script.
1. tests are now done in a subdiretory od the live server. 2. usage is easier, with commands. 3. using getopts for command-line parsing is cool.
This commit is contained in:
parent
3c2ae7ca93
commit
04be680bd5
158
s/preview
158
s/preview
|
@ -1,58 +1,158 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
usage() {
|
function usage() {
|
||||||
echo "usage: $0 game-id"
|
cat <<HEREDOC
|
||||||
|
usage: $0 [-t <turn>] [-g <game>] [-f <file>] command [args]
|
||||||
|
commands:
|
||||||
|
build -- pull and rebuild the code
|
||||||
|
version -- print the current build number
|
||||||
|
setup -- create base directory and config files
|
||||||
|
run -- run a turn
|
||||||
|
send [id ...] -- send reports to one or more factions, or to all ids in <file>
|
||||||
|
HEREDOC
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
abort() {
|
function abort() {
|
||||||
echo $1
|
echo $1
|
||||||
[ -z $2 ] && exit -1
|
[ -z $2 ] && exit -1
|
||||||
exit $2 # otherwise
|
exit $2 # otherwise
|
||||||
}
|
}
|
||||||
|
|
||||||
[ -d $ERESSEA ] || abort "Invalid env variable ERESSEA ($ERESSEA)"
|
function build() {
|
||||||
|
assert_dir $SOURCE
|
||||||
GAME=$1
|
|
||||||
LIVE=$ERESSEA/game-$GAME
|
|
||||||
SOURCE=$ERESSEA/git
|
|
||||||
TESTROOT=$LIVE/test
|
|
||||||
REBUILD=0
|
|
||||||
|
|
||||||
[ -d $LIVE ] || usage
|
|
||||||
[ -d $SOURCE ] || abort "missing source directory: $SOURCE"
|
|
||||||
|
|
||||||
[ -f $LIVE/turn ] || abort "missing turn file"
|
|
||||||
let TURN=$(cat $LIVE/turn)-1
|
|
||||||
|
|
||||||
if [ $REBUILD ] ; then
|
|
||||||
cd $SOURCE
|
cd $SOURCE
|
||||||
git pull || abort "failed to update source. do you have local changes?"
|
git pull || abort "failed to update source. do you have local changes?"
|
||||||
BUILD=$(grep BUILD src/build.h | awk '{ print $3 }')
|
|
||||||
s/build || abort "build failed."
|
s/build || abort "build failed."
|
||||||
fi
|
}
|
||||||
|
|
||||||
echo "testing turn $TURN of game $GAME with build $BUILD"
|
function assert_file() {
|
||||||
|
[ -e $1 ] || abort "missing file: $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
function assert_files() {
|
||||||
|
while [ ! -z $1 ] ; do
|
||||||
|
assert_file $1
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
function assert_dir() {
|
||||||
|
[ -d $1 ] || abort "missing directory: $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
function version() {
|
||||||
|
assert_dir $SOURCE
|
||||||
|
cd $SOURCE
|
||||||
|
build=$(grep BUILD src/build.h | awk '{ print $3 }')
|
||||||
|
echo "eressea build $build"
|
||||||
|
}
|
||||||
|
|
||||||
|
function setup() {
|
||||||
|
assert_dir $SOURCE
|
||||||
|
assert_dir $LIVE
|
||||||
mkdir -p $TESTROOT
|
mkdir -p $TESTROOT
|
||||||
|
assert_dir $TESTROOT
|
||||||
cd $TESTROOT
|
cd $TESTROOT
|
||||||
|
|
||||||
if [ ! -e eressea.ini ] ; then
|
|
||||||
cat >| eressea.ini <<HEREDOC
|
cat >| eressea.ini <<HEREDOC
|
||||||
[lua]
|
[lua]
|
||||||
dbname = preview.db
|
dbname = preview.db
|
||||||
install = $SOURCE
|
install = $SOURCE
|
||||||
paths = $SOURCE/lunit:$SOURCE/git/scripts
|
paths = $SOURCE/lunit:$SOURCE/git/scripts
|
||||||
rules = e$GAME
|
rules = e$game
|
||||||
HEREDOC
|
HEREDOC
|
||||||
fi
|
}
|
||||||
|
|
||||||
|
function run() {
|
||||||
|
echo "testing turn $turn of game $game"
|
||||||
|
assert_dir $TESTROOT
|
||||||
|
cd $TESTROOT
|
||||||
[ -d data ] || mkdir data
|
[ -d data ] || mkdir data
|
||||||
|
assert_dir data
|
||||||
|
assert_files $LIVE/orders.$turn $LIVE/data/$turn.dat
|
||||||
cp $LIVE/eressea.db preview.db
|
cp $LIVE/eressea.db preview.db
|
||||||
ln -f $LIVE/orders.$TURN
|
ln -f $LIVE/orders.$turn
|
||||||
ln -f $LIVE/data/$TURN.dat data/
|
ln -f $LIVE/data/$turn.dat data/
|
||||||
rm -rf reports
|
rm -rf reports
|
||||||
mkdir -p reports
|
mkdir -p reports
|
||||||
|
|
||||||
$SOURCE/build-x86_64-gcc-Debug/eressea/eressea -v1 -t$TURN -re$GAME $SOURCE/scripts/run-turn.lua
|
$SOURCE/build-x86_64-gcc-Debug/eressea/eressea -v$verbose -t$turn -re$game $SOURCE/scripts/run-turn.lua
|
||||||
let TURN=$TURN+1
|
let turn=$turn+1
|
||||||
[ -e data/$TURN.dat ] || abort "no data file created"
|
[ -e data/$turn.dat ] || abort "no data file created"
|
||||||
|
}
|
||||||
|
|
||||||
|
function send() {
|
||||||
|
echo "sending reports to $1"
|
||||||
|
zip="$turn-$1.zip"
|
||||||
|
zip -q -u $yip $turn-$1.?r
|
||||||
|
email=$(grep "faction=$1:" reports.txt | cut -d: -f2 | sed 's/email=//')
|
||||||
|
cat /dev/null | mutt -F $ERESSEA/etc/muttrc -s "Testauswertung Spiel $GAME Partei $1" -a $zip -- $email
|
||||||
|
}
|
||||||
|
|
||||||
|
game=0
|
||||||
|
turn=0
|
||||||
|
verbose=1
|
||||||
|
factions="testers.txt"
|
||||||
|
while getopts :g:t:f:v: o; do
|
||||||
|
case "${o}" in
|
||||||
|
f)
|
||||||
|
factions=${OPTARG}
|
||||||
|
;;
|
||||||
|
v)
|
||||||
|
verbose=${OPTARG}
|
||||||
|
;;
|
||||||
|
g)
|
||||||
|
game=${OPTARG}
|
||||||
|
;;
|
||||||
|
t)
|
||||||
|
turn=${OPTARG}
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
usage
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
shift $((OPTIND-1))
|
||||||
|
|
||||||
|
[ -d $ERESSEA ] || echo "invalid or missing env variable ERESSEA ($ERESSEA)"
|
||||||
|
[ -z $1 ] && usage
|
||||||
|
[ -z $SOURCE ] && SOURCE=$ERESSEA/git
|
||||||
|
[ -d $SOURCE ] || abort "missing source directory: $SOURCE"
|
||||||
|
[ -d LIVE ] || LIVE=$ERESSEA/game-$game
|
||||||
|
[ -d TESTROOT ] || TESTROOT=$LIVE/test
|
||||||
|
|
||||||
|
while [ ! -z $1 ]; do
|
||||||
|
case "$1" in
|
||||||
|
"version")
|
||||||
|
version
|
||||||
|
;;
|
||||||
|
"build")
|
||||||
|
build
|
||||||
|
;;
|
||||||
|
"setup")
|
||||||
|
setup
|
||||||
|
;;
|
||||||
|
"run")
|
||||||
|
if [ $turn -eq 0 ]; then
|
||||||
|
[ -f $LIVE/turn ] || abort "missing turn file, and no turn specified"
|
||||||
|
let turn=$(cat $LIVE/turn)-1
|
||||||
|
fi
|
||||||
|
run
|
||||||
|
;;
|
||||||
|
"send")
|
||||||
|
shift
|
||||||
|
for faction in $* ; do
|
||||||
|
send $faction
|
||||||
|
done
|
||||||
|
cd $TESTROOT
|
||||||
|
if [ -e $factions ]; then
|
||||||
|
for faction in $(cat $factions) ; do
|
||||||
|
send $faction
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
|
@ -228,7 +228,7 @@ void give_men(int n, unit * u, unit * u2, struct order *ord)
|
||||||
error = 312;
|
error = 312;
|
||||||
}
|
}
|
||||||
else if (u2 && u2->number != 0 && u_race(u2) != u_race(u)) {
|
else if (u2 && u2->number != 0 && u_race(u2) != u_race(u)) {
|
||||||
log_warning("faction %s attempts to give %s to %s.\n", itoa36(u->faction->no), u_race(u)->_name[0], u_race(u2)->_name[1]);
|
log_debug("faction %s attempts to give %s to %s.\n", itoa36(u->faction->no), u_race(u)->_name[0], u_race(u2)->_name[0]);
|
||||||
error = 139;
|
error = 139;
|
||||||
}
|
}
|
||||||
else if (u2 != NULL && (get_racename(u2->attribs)
|
else if (u2 != NULL && (get_racename(u2->attribs)
|
||||||
|
|
|
@ -965,8 +965,6 @@ void demographics(void)
|
||||||
free(free_migrants);
|
free(free_migrants);
|
||||||
free_migrants = m;
|
free_migrants = m;
|
||||||
};
|
};
|
||||||
if (verbosity >= 1)
|
|
||||||
putchar('\n');
|
|
||||||
|
|
||||||
remove_empty_units();
|
remove_empty_units();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue