I got an email from someone asking about automating hourly tests, what we call a "smokebot". Here's the code for it:
# set -xv # Watch it run
if [ $# -lt 2 ]
then
echo Must pass at least a branch, and one email address,
echo plus any parms to pass to smoke.
exit 1
fi
BRANCH=$1
shift
MAIL=$1
shift
TMP=/tmp/smoke
STAMP=`date +%m%d-%H%M`
TWROOT=$TMP/tw-$STAMP
export TWROOT
# the -n switch to ln allow ln to force-replace (-f)
# a symlink to a directory.
ln -fsn $TWROOT ~/tw
# OLD: cvs -d/home/cvs -Q co -d $DIR -r $REV tw > /dev/null
svn export file:///home/svn/tw/$BRANCH $TWROOT > /dev/null
# devapache = personal Apache instance
DEVAPACHE=$TWROOT/Dev/devapache
SMOKEOUT=$TWROOT/smoke.out
SMOKEOUTFAIL=$TWROOT/smoke.out.fail
$DEVAPACHE stop > /dev/null 2>&1
$DEVAPACHE start > $SMOKEOUT 2>&1
cd $TWROOT
smoke $@ >> $SMOKEOUT 2>&1
$DEVAPACHE stop >> $SMOKEOUT 2>&1
rm -f ~/tw
grep -i "^Failed" $SMOKEOUT > $SMOKEOUTFAIL
if [ -s $SMOKEOUTFAIL ]
then
STATUS="FAILED"
mail -s"Smoke $REV $@ $STATUS `date`" $MAIL < $SMOKEOUT
else
STATUS="passed"
rm -fr $TWROOT
fi
# Smoke the trunk at :00
0 * * * * smokebot trunk smokereports@mycompany.com
# Smoke the branch at :30
30 * * * * smokebot branch/proj-name smokereports@mycompany.com
# More branches possible, of course.
A couple of notes: "TW" is TITLEWAVE, our website, and everything lives in the user's ~/tw directory. The smoke program is a TW-specific predecessor of prove that comes with Test::Harness. The smokereports email address is an alias that explodes to the entire department. If the smoke fails, it leaves the temp directory for port-mortem.
At some point I'll have a genericized version of this in Test::Harness.