543 lines
14 KiB
Bash
543 lines
14 KiB
Bash
#!/bin/bash
|
|
|
|
# this script is for automatic testing secondo
|
|
|
|
# define some constants
|
|
|
|
# directory for testing
|
|
basedir=$HOME
|
|
# file for setting secondo environment
|
|
envfile=$HOME/.secondorc
|
|
# set force to yes for testing even if no changes were made since last test
|
|
force="no"
|
|
#time out for Testrunner
|
|
timeout=1800
|
|
|
|
server=bassi.fernuni-hagen.de
|
|
users=/cvs/CVSROOT/users
|
|
to=fabio.valdes@fernuni-hagen.de
|
|
from=fabio.valdes@fernuni-hagen.de
|
|
additional=""
|
|
cvs=""
|
|
rev=""
|
|
|
|
function help {
|
|
echo "testsecondo [OPTIONS]"
|
|
echo "OPTIONS: "
|
|
echo "-f: forces to run the test even if there are no changes since last run"
|
|
echo "-d <directory>: changes the base directory, default is \$HOME"
|
|
echo "-e <envfile>: changes the file for setting the environment, default is \$HOME/.secondorc"
|
|
echo "-t <timeout>: sets the timeout for each test in seconds, default is 1800"
|
|
echo "-m <server>: specifies the mailserver for outgoing mails"
|
|
echo "-u <users>: specifies the file where cvs users emails are provided"
|
|
echo "-s <from>: email address of the sender of an email"
|
|
echo "-r <recipient>: email address of the main recipient"
|
|
echo "-a <recipient>: additional recipient (repeat this option if more than one)"
|
|
echo "-c <CVSROOT>: sets CVSROOT variable"
|
|
echo "-p: publish public version to dna server"
|
|
echo "-h: shows this help text"
|
|
echo "-v <REV>: test a specific revision (standard is HEAD)"
|
|
}
|
|
|
|
|
|
# overwrite standard parameters if options are available
|
|
|
|
while getopts hfpd:e:t:m:u:s:r:a:c:v: opt
|
|
do
|
|
case $opt in
|
|
f) force="yes";;
|
|
p) PUBLISH="yes";;
|
|
d) basedir=$OPTARG ;;
|
|
e) envfile=$OPTARG ;;
|
|
t) timeout=$OPTARG ;;
|
|
m) server=$OPTARG ;;
|
|
u) users=$OPTARG ;;
|
|
s) to=$OPTARG ;;
|
|
r) recipient=$OPTARG ;;
|
|
a) additional+=$OPTARG" "; echo "add additional $OPTARG" ;;
|
|
c) cvs=$OPTARG ;;
|
|
h) help; exit 0 ;;
|
|
v) rev=$OPTARG ;;
|
|
esac
|
|
done
|
|
|
|
echo "force = $force"
|
|
echo "PUBLISH = $PUBLISH"
|
|
echo "basedir = $basedir"
|
|
echo "envfile = $envfile"
|
|
echo "timeout = $timeout"
|
|
echo "server = $server"
|
|
echo "users = $users"
|
|
echo "to = $to"
|
|
echo "recipient = $recipient"
|
|
echo "additional = $additional"
|
|
echo "cvs = $cvs"
|
|
echo "rev = $rev"
|
|
|
|
|
|
export CVSROOT=$cvs
|
|
|
|
|
|
# create additional list with commata
|
|
additionalcs=$(echo $additional | sed "s/ */,/g")
|
|
|
|
if [ ! -f $users ]; then
|
|
echo "users file: $users not present"
|
|
echo exit
|
|
exit 1
|
|
fi
|
|
|
|
|
|
|
|
# derived file and directory names
|
|
secondoname=sectest
|
|
secondodir=$basedir/$secondoname
|
|
databasedir=$basedir/secondo-databases
|
|
logdir=$basedir/secondotestlogs
|
|
failed_log_dir=$logdir/failed
|
|
|
|
last_run=$logdir/last_run
|
|
last_successful_run=$logdir/last_successful_run
|
|
make_log_first=$logdir/make_first.log
|
|
make_log_current=$logdir/make.log
|
|
checkout_log=$logdir/checkout.log
|
|
|
|
last_stable_dir=$basedir/laststable
|
|
|
|
|
|
|
|
|
|
function sendMail {
|
|
local subject=$1
|
|
local testStarted=$2
|
|
# compress log directory
|
|
local appendix=$logdir/failed.tgz
|
|
rm -f $appendix
|
|
cd $logdir
|
|
tar -czf $appendix $(basename $failed_log_dir)
|
|
## add additional recipients
|
|
for a in $additional; do
|
|
echo $a >>$logdir/ChangerMails.txt
|
|
done
|
|
local bcc=$(cat $logdir/ChangerMails.txt | sort | uniq | sed "s/$/,/")
|
|
bcc=$(echo $bcc | sed "s/ //g" | sed "s/,$//")
|
|
local content=$logdir/mailcontent.txt
|
|
echo "Dear Secondo developer, " >$content
|
|
echo "" >>$content
|
|
echo "During the last tests of Secondo, some errors occurred." >>$content
|
|
echo "You receive this email because you have checked in some code since the last successful test." >>$content
|
|
echo "" >>$content
|
|
echo "The changes after the previous test are the following:" >>$content
|
|
echo "" >>$content
|
|
cat $logdir/Changes.txt >>$content
|
|
echo "" >>$content
|
|
echo "Please check whether your changes are responsible for the failed test." >>$content
|
|
if [ "$testStarted" == "true" ]; then
|
|
echo "Failed tests:" >>$content
|
|
cat $logdir/_failed_* >>$content
|
|
fi
|
|
echo "Detailed information can be found in the attachment." >>$content
|
|
echo "" >>$content
|
|
echo "Kind Regards" >>$content
|
|
echo "The automatic Test" >>$content
|
|
mailx -s "$subject" -a $appendix -b "$bcc" -r $from -S smtp=smtp://$server $to <$content
|
|
|
|
}
|
|
|
|
|
|
function fileDate {
|
|
local res=$(date)
|
|
if [ -e $1 ]; then
|
|
res=$(stat -c %z $1 | awk '{print $1" " $2}')
|
|
fi
|
|
echo "$res"
|
|
}
|
|
|
|
|
|
function createaccessfiles {
|
|
local lastrun=$1
|
|
local logdir=$2
|
|
local users=$3
|
|
local lastsuccrun=$4
|
|
|
|
firstrun="true"
|
|
lastrundate="3 days ago"
|
|
if [ -f "$lastrun" ]; then
|
|
lastrundate=$(fileDate $lastrun)
|
|
firstrun="false"
|
|
fi
|
|
|
|
echo "lastrundate = $lastrundate" >$logdir/lastrundate.txt
|
|
|
|
lastsuccrundate=$lastrundate
|
|
if [ -f "$lastsuccrun" ]; then
|
|
lastsuccrundate=$(fileDate $lastsuccrun)
|
|
fi
|
|
echo "lastsuccrundate = $lastsuccrundate" >$logdir/lastsuccrundate.txt
|
|
|
|
# check for changes since last run
|
|
|
|
cvs history -xMAR -a -D "$lastsuccrundate" -p secondo | grep -v 'No records selected' >$logdir/Changes.txt
|
|
|
|
if [ "$firstrun" == "true" ]; then
|
|
echo "yes"
|
|
else
|
|
noChanges=$(cat $logdir/Changes.txt | wc -l | awk '{print $1}')
|
|
if [ "$noChanges" == "0" ]; then
|
|
echo "no"
|
|
else
|
|
# collect all changes since last successful run and get the names of the changers
|
|
cvs history -xMAR -a -D "$lastsuccrundate" -p secondo | grep -v 'No records selected' >$logdir/Changes.txt
|
|
cat $logdir/Changes.txt | awk '{print $5}' | sort | uniq | sort >$logdir/changerNames.txt
|
|
cat $users | sort -t: | join -t: - $logdir/changerNames.txt | sed "s/.*://" >$logdir/ChangerMails.txt
|
|
echo "yes"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function showValue
|
|
{
|
|
local var=$1
|
|
eval echo $var' = $'$var''
|
|
}
|
|
|
|
|
|
|
|
# start processing
|
|
|
|
echo "start testing secondo"
|
|
|
|
testStart="false"
|
|
|
|
rm -rf $secondodir
|
|
rm -rf $databasedir
|
|
rm -rf $failed_log_dir
|
|
|
|
rm -f $logdir/_failed_*
|
|
rm -rf $failed_log_dir
|
|
rm -f $logdir/Changes.txt $logdir/changerNames.txt $logdir/ChangerMails.txt $logdir/mailcontent.txt $logdir/failed.tgz
|
|
mkdir -p $failed_log_dir; echo "logdir created"
|
|
|
|
# create files containing the changes, the names of the people who made the changes
|
|
# and the corresponding email-adresses
|
|
# the result of the function changes may be yes or no depending whether there were
|
|
# changes since the last test
|
|
|
|
|
|
changes=$(createaccessfiles $last_run $logdir $users $last_successful_run)
|
|
|
|
showValue changes
|
|
|
|
if [ "$changes" == "no" ]; then
|
|
echo "no changes since last run of the test"
|
|
if [ "$force" != "yes" ]; then
|
|
echo "exit test"
|
|
exit 0
|
|
fi
|
|
echo "force test even without changes"
|
|
fi
|
|
|
|
# mark the file holding the last run
|
|
touch $last_run
|
|
|
|
# step 1: checkout the newest secondo version
|
|
|
|
cd $basedir
|
|
echo "Checkout secondo"
|
|
|
|
firstCheckOutFailure=$(fileDate $checkout_log)
|
|
revopt=""
|
|
if [ -n "$rev" ]; then
|
|
revopt="-r $rev"
|
|
fi
|
|
|
|
|
|
cvs -q co $revopt -d $secondoname secondo >/dev/null 2>&1
|
|
|
|
|
|
n=$?
|
|
|
|
if [ "$n" != "0" ]; then
|
|
if [ ! -f $checkout_log ]; then
|
|
touch $checkout_log
|
|
fi
|
|
sendMail "Problem in checking out secondo" $testStart
|
|
exit 1
|
|
fi
|
|
|
|
#chekout successful
|
|
|
|
rm -f $checkout_log
|
|
|
|
|
|
#step 2: compile secondo
|
|
|
|
echo "set environment"
|
|
echo "source $envfile $secondodir"
|
|
|
|
source $envfile $secondodir
|
|
cd $secondodir
|
|
|
|
echo "make secondo"
|
|
|
|
firstFailedMake=$(fileDate $make_log_first)
|
|
make >$make_log_current 2>&1
|
|
|
|
n=$?
|
|
|
|
if [ "$n" != "0" ]; then
|
|
if [ ! -f "$make_log_first" ]; then
|
|
touch $make_log_first
|
|
fi
|
|
mv -f $make_log_current $failed_log_dir
|
|
sendMail "Building secondo failed" $testStart
|
|
exit 1
|
|
fi
|
|
|
|
rm -f $make_log_first
|
|
rm -f $make_log_current
|
|
|
|
# start tests
|
|
|
|
|
|
echo "run tests"
|
|
testStart="true"
|
|
|
|
cd $secondodir/CM-Scripts
|
|
run-tests.sh -tty $logdir $timeout
|
|
|
|
n=$?
|
|
|
|
if [ "$n" != "0" ]; then
|
|
#automatic test failed, collect log files into $failed_log_dir
|
|
failed_tests=$(find $logdir -maxdepth 1 -name "_failed_*" -printf "%f " | sed "s/_failed_//g")
|
|
for f in $failed_tests; do
|
|
find $secondodir -name $f.log -exec cp {} $failed_log_dir \;
|
|
done
|
|
sendMail "Automatic tests failed" $testStart
|
|
exit 1
|
|
fi
|
|
|
|
# mark test as successful
|
|
touch $last_successful_run
|
|
|
|
# tests were successful, set LAST_STABLE tag in Secondo
|
|
|
|
cd $secondodir
|
|
|
|
|
|
if [ -z "$rev" ]; then
|
|
# remove the LAST_STABLE tag from removed files, only if not a certain revision is tested
|
|
cvs -q rtag -a LAST_STABLE secondo
|
|
|
|
# tag all files present in the currect project
|
|
# to be part of the last stable version
|
|
|
|
cvs -q tag -F LAST_STABLE
|
|
|
|
fi
|
|
|
|
|
|
if [ -z "$additionalcs" ]; then
|
|
echo "Secondo tests successful" | mailx -s "Secondo tests successful" -r $from -S smtp=smtp://$server $to
|
|
else
|
|
echo "Secondo tests successful" | mailx -s "Secondo tests successful" -r $from -c "$additionalcs" -S smtp=smtp://$server $to
|
|
fi
|
|
|
|
|
|
|
|
rm -f $logdir/_failed_*
|
|
rm -rf $failed_log_dir
|
|
rm -f $logdir/Changes.txt $logdir/changerNames.txt $logdir/ChangerMails.txt $logdir/mailcontent.txt $logdir/failed.tgz
|
|
|
|
|
|
# create a tar-gz from the last stable version
|
|
|
|
mkdir -p $last_stable_dir
|
|
cd $last_stable_dir
|
|
rm -rf secondo
|
|
if [ -z "$rev" ]; then
|
|
cvs -q export -r LAST_STABLE secondo 2>&1 >/dev/null
|
|
rm -f secondo_LAST_STABLE.tgz
|
|
else
|
|
cvs -q export -r $rev secondo 2>&1 >/dev/null
|
|
fi
|
|
|
|
|
|
|
|
# tar -czf secondo_LAST_STABLE.tgz secondo
|
|
|
|
# create public version of secondo
|
|
cd secondo
|
|
source $envfile $PWD
|
|
if [ -z "$rev" ]; then
|
|
CM-Scripts/makepublicsecondo LAST_STABLE >$logdir/pubsec.log
|
|
else
|
|
CM-Scripts/makepublicsecondo $rev >$logdir/pubsec.log
|
|
fi
|
|
|
|
n=$?
|
|
|
|
if [ "$n" != "0" ]; then
|
|
|
|
if [ -z "$additionalcs" ]; then
|
|
echo "Public secondo version could not be created." | mailx -s "building public version failed" -a $logdir/pubsec.log -r $from -S smtp=smtp://$server $to
|
|
else
|
|
echo "Public secondo version could not be created." | mailx -s "building public version failed" -a $logdir/pubsec.log -c "$additionalcs" -r $from -S smtp=smtp://$server $to
|
|
fi
|
|
rm -f $logdir/pubsec.log
|
|
exit 1
|
|
fi
|
|
|
|
|
|
if [ -z "$rev" ]; then
|
|
rm ../secondo_LAST_STABLE_PUBLIC.tgz
|
|
mv secondo-LAST_STABLE-LAT1.tar.gz ../secondo_LAST_STABLE_PUBLIC.tgz
|
|
else
|
|
rm ../secondo_${rev}_PUBLIC.tgz
|
|
mv secondo-${rev}-LAT1.tar.gz ../secondo_${rev}_PUBLIC.tgz
|
|
fi
|
|
|
|
|
|
cd ..
|
|
rm -rf secondo
|
|
rm -f $logdir/pubsec.log
|
|
|
|
|
|
|
|
if [ -z "$additionalcs" ]; then
|
|
echo "Public secondo version created." | mailx -s "building public version successful" -r $from -S smtp=smtp://$server $to
|
|
else
|
|
echo "Public secondo version created." | mailx -s "building public version successful" -r $from -c "$additionalcs" -S smtp=smtp://$server $to
|
|
fi
|
|
|
|
echo "Public version created"
|
|
|
|
cd $last_stable_dir
|
|
if [ -z "$rev" ]; then
|
|
tar -xzf secondo_LAST_STABLE_PUBLIC.tgz
|
|
else
|
|
tar -xzf secondo_${rev}_PUBLIC.tgz
|
|
fi
|
|
|
|
cd secondo
|
|
pubtestdir=$PWD
|
|
source $envfile $PWD
|
|
|
|
make >make.log 2>&1
|
|
|
|
n=$?
|
|
if [ "$n" != "0" ]; then
|
|
gzip make.log
|
|
if [ -z "$additionalcs" ]; then
|
|
echo "Making public version failed." | mailx -s "making public version failed" -a make.log.gz -r $from -S smtp=smtp://$server $to
|
|
else
|
|
echo "Making public version failed." | mailx -s "making public version failed" -a make.log.gz -r $from -c "$additionalcs" -S smtp=smtp://$server $to
|
|
fi
|
|
exit 1
|
|
else
|
|
rm make.log
|
|
fi
|
|
|
|
cd CM-Scripts
|
|
run-tests.sh -tty $logdir $timeout
|
|
|
|
n=$?
|
|
|
|
if [ "$n" != "0" ]; then
|
|
#automatic test failed, collect log files into $failed_log_dir
|
|
failed_tests=$(find $logdir -maxdepth 1 -name "_failed_*" -printf "%f " | sed "s/_failed_//g")
|
|
for f in $failed_tests; do
|
|
find $pubtestdir -name $f.log -exec cp {} $failed_log_dir \;
|
|
done
|
|
sendMail "Automatic tests of the public version failed" $testStart
|
|
cd $last_stable_dir
|
|
rm -rf secondo
|
|
exit 1
|
|
fi
|
|
|
|
# runtests successful, build a new gui binary
|
|
|
|
if [ -z "$rev" ];then
|
|
cd ..
|
|
cd Javagui
|
|
make demo
|
|
cd Demo
|
|
zip -r JavaGui_Latest.zip *
|
|
scp JavaGui_Latest.zip dna.fernuni-hagen.de:/www/pi4/secondo/files/lastversion/
|
|
cd ..
|
|
rm -rf Demo
|
|
fi
|
|
|
|
|
|
cd $last_stable_dir
|
|
rm -rf secondo
|
|
|
|
rm -f $logdir/_failed_*
|
|
rm -rf $failed_log_dir
|
|
rm -f $logdir/Changes.txt $logdir/changerNames.txt $logdir/ChangerMails.txt $logdir/mailcontent.txt $logdir/failed.tgz
|
|
|
|
echo "Public version tests successful"
|
|
|
|
PUBLISHED="but not published at dna"
|
|
if [ "$PUBLISH" == "yes" ]; then
|
|
echo "Public version"
|
|
if [ -z "$rev" ];then
|
|
scp secondo_LAST_STABLE_PUBLIC.tgz dna.fernuni-hagen.de:/www/pi4/secondo/files/lastversion/secondo_LAST.tgz
|
|
pv="PublicVersion.html"
|
|
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">" >$pv
|
|
echo "<html>" >>$pv
|
|
echo "<head>" >>$pv
|
|
echo "<title> SECONDO Latest Version </title>" >>$pv
|
|
echo "<meta name=\"description\" content=\"erweiterbares Datenbanksystem\">" >>$pv
|
|
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../../secondo.css\">" >>$pv
|
|
echo "<link rel=\"shortcut icon\" href=\"../../favicon.ico\">" >>$pv
|
|
echo "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">" >>$pv
|
|
echo "</head>" >>$pv
|
|
echo "<body>" >>$pv
|
|
echo "<div align=\"center\">" >>$pv
|
|
echo "<img alt=\"SECONDO\" width=\"598\" height=\"107\" src=\"../../images/logo.gif\"> " >>$pv
|
|
echo "</div>" >>$pv
|
|
echo "<h1> Last Version of Secondo </h1>" >>$pv
|
|
echo "<div>" >>$pv
|
|
echo "Here you can download the latest sources of Secondo Database system " >>$pv
|
|
echo "having passed simple automatic tests." >>$pv
|
|
echo "Note that this version is not so good tested as the official releases." >> $pv
|
|
echo "</div>" >>$pv
|
|
echo "<div>" >>$pv
|
|
echo "<a href=\"secondo_LAST.tgz\"> Download Link </a>" >> $pv
|
|
echo "</div>" >>$pv
|
|
echo "<div>" >>$pv
|
|
echo "<a href=\"JavaGui_Latest.zip\"> JavaGui Binaries </a>" >> $pv
|
|
echo "</div>" >>$pv
|
|
FD=$(fileDate secondo_LAST_STABLE_PUBLIC.tgz)
|
|
FD=$(echo $FD | sed "s/\..*//")
|
|
echo "<div>" >>$pv
|
|
echo "This version was created: $FD" >> $pv
|
|
echo "</div>" >>$pv
|
|
echo "</body>" >>$pv
|
|
echo "</html>" >>$pv
|
|
scp $pv dna.fernuni-hagen.de:/www/pi4/secondo/files/lastversion/index.html
|
|
PUBLISHED="and published to DNA"
|
|
else
|
|
scp secondo_${rev}_PUBLIC.tgz dna.fernuni-hagen.de:/www/pi4/secondo/files/lastversion/secondo_${rev}.tgz
|
|
PUBLISHED="and copyied to DNA"
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
if [ -z "$additionalcs" ]; then
|
|
echo "Public secondo successful tested $PUBLISHED ." | mailx -s "testing public version successful" -r $from -S smtp=smtp://$server $to
|
|
else
|
|
echo "Public secondo successful tested $PUBLISHED ." | mailx -s "testing public version successful" -r $from -c "$additionalcs" -S smtp=smtp://$server $to
|
|
fi
|
|
|
|
|
|
exit 0
|
|
|