summaryrefslogtreecommitdiff
path: root/devtools/flockdriver
blob: 746471df8cc0ca4b62e21d4b790c8e73d7b1149d (plain)
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
#!/bin/sh
#
# flockdriver - conduct regression tests as an argent for a remote flocktest
#
# usage: flockdriver -d subdir
#
# The -d argument must be a subdirectory name
# The -m option must be a valid address for notification mail.
#
#  This will perform the following steps:
#
#  * If required, create the origin repo in a directory named after 
#     you beneath the test account home,
#
#   * git pull and build in that repo.
#
#   * make check, capturing the output
#
#   * Notify the #gpsd chabnnel of success or failyre via CIA
#
#   * mail the output back to you if the test failed.
#

# Project-specific configuration
project=GPSD
origin="git://git.berlios.de/gpsd"
generator="http://gpsd.berlios/de"

# No project-specific stuff below this line

while getopts dm opt
do
    case $opt in
        d) subdir=$2; shift; shift ;;
	m) mailto=$2; shift; shift ;;
    esac
done

site=`hostname --fqdn`

if [ -f "flockdriver.lock" ]
then
    logmessage="A test was already running when you initiated this one."
    cd $subdir
    mailback=no
else
    (
	echo "Test begins: "`date`

	echo "Site: $site" 
	echo "Directory: ${PWD}/${subdir}"
	echo "Mailto: $mailto"
    ) >"flockdriver-${subdir}.log"

    # Set up or update the repo
    if [ ! -d $subdir ]
    then
	git clone $origin $subdir >>"flockdriver-${subdir}.log" 2>&1
	cd $subdir
    else
	cd $subdir; git pull >>"../flockdriver-${subdir}.log" 2>&1
    fi

    # Perform the test
    if ( ./autogen.sh && make && make check ) >>"../flockdriver-${subdir}.log" 2>&1
    then
	logmessage="Regression test succeeded."
	mailback=no
    else
	logmessage="Regression test failed."
	mailback=yes
    fi

    echo "Test ends: "`date` >>"../flockdriver-${subdir}.log" 2>&1
    mv "../flockdriver-${subdir}.log" TEST.LOG
fi

# Here's where we abuse CIA to do our notfications for us.

# Addresses for the e-mail
from="FLOCKDRIVER-NOREPLY@${site}"
to="cia@cia.navi.cx"

# SMTP client to use
sendmail="sendmail -t -f ${from}"

# Should include all places sendmail is likely to lurk. 
PATH="$PATH:/usr/sbin/"

# Identify what just succeeded or failed
merged=$(git rev-parse HEAD)
rev=$(git describe ${merged} 2>/dev/null)
[ -z ${rev} ] && rev=${merged}
refname=$(git symbolic-ref HEAD 2>/dev/null)
refname=${refname##refs/heads/}

# And the git version
gitver=$(git --version)
gitver=${gitver##* }

# Compose and ship the CIA notification
out="
<message>
  <generator>
    <name>${project} Remote Test Flock Driver</name>
    <version>${gitver}</version>
    <url>${generator}</url>
  </generator>
  <source>
    <project>${project}</project>
    <branch>${refname}@${site}</branch>
  </source>
  <timestamp>`date`</timestamp>
  <body>
    <commit>
      <author>${subdir}</author>
      <revision>${rev}</revision>
      <log>${logmessage}</log>
    </commit>
  </body>
</message>"

${sendmail} << EOM
Message-ID: <${merged}.${subdir}.blip@${project}>
From: ${from}
To: ${to}
Content-type: text/xml
Subject: DeliverXML
${out}
EOM

# Now ship the error log if need be.
cat >/tmp/flockdriver$$ <<EOM
Message-ID: <${merged}.${subdir}.log@${project}>
From: ${from}
To: ${mailto}
Content-type: text/plain; charset=us-ascii
Subject: flockdriver test log

$logmessage
EOM

if [ "$mailback" = yes ]
then
    cat "/tmp/flockdriver$$" TEST.LOG | ${sendmail}
fi
rm -f "/tmp/flockdriver$$"

# End.