[dpdk-ci] [PATCH v2 5/7] tools: add per-patch report mailer

Thomas Monjalon thomas.monjalon at 6wind.com
Thu Dec 1 14:44:50 CET 2016


The report sent by this script will be parsed and integrated in patchwork
if the patch was public.
Otherwise it will just send the report to the patch submitter.

Signed-off-by: Thomas Monjalon <thomas.monjalon at 6wind.com>
---
 config/ci.config           |   3 ++
 tools/send-patch-report.sh | 100 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 103 insertions(+)
 create mode 100755 tools/send-patch-report.sh

diff --git a/config/ci.config b/config/ci.config
index 722aeb5..b3b0376 100644
--- a/config/ci.config
+++ b/config/ci.config
@@ -3,5 +3,8 @@
 #     or  ~/.config/dpdk/ci.config
 #     or  .ciconfig
 
+# The mailer (sendmail, mail, mailx) must support the option -t
+# export DPDK_CI_MAILER=/usr/sbin/sendmail
+
 # The pwclient script is part of patchwork and is copied in dpdk-ci
 # export DPDK_CI_PWCLIENT=tools/pwclient
diff --git a/tools/send-patch-report.sh b/tools/send-patch-report.sh
new file mode 100755
index 0000000..afdf542
--- /dev/null
+++ b/tools/send-patch-report.sh
@@ -0,0 +1,100 @@
+#! /bin/sh -e
+
+# This file is in the public domain.
+
+print_usage () {
+	cat <<- END_OF_HELP
+	usage: $(basename $0) [options] < report
+
+	Send test report in a properly formatted email for patchwork integration.
+	The report is submitted to this script via stdin.
+
+	options:
+	        -t title    subject of the patch email
+	        -f from     sender of the patch email
+	        -m msgid    id of the patch email
+	        -p listid   mailing list publishing the patch
+	        -l label    title of the test
+	        -s status   one of these test results: SUCCESS, WARNING, FAILURE
+	        -d desc     few words to better describe the status
+	        -h          this help
+	END_OF_HELP
+}
+
+. $(dirname $(readlink -e $0))/load-ci-config.sh
+sendmail=${DPDK_CI_MAILER:-/usr/sbin/sendmail}
+pwclient=${DPDK_CI_PWCLIENT:-$(dirname $(readlink -m $0))/pwclient}
+
+unset title
+unset from
+unset msgid
+unset listid
+unset label
+unset status
+unset desc
+while getopts d:f:hl:m:p:s:t: arg ; do
+	case $arg in
+		t ) title=$OPTARG ;;
+		f ) from=$OPTARG ;;
+		m ) msgid=$OPTARG ;;
+		p ) listid=$OPTARG ;;
+		l ) label=$OPTARG ;;
+		s ) status=$OPTARG ;;
+		d ) desc=$OPTARG ;;
+		h ) print_usage ; exit 0 ;;
+		? ) print_usage >&2 ; exit 1 ;;
+	esac
+done
+shift $(($OPTIND - 1))
+if [ -t 0 ] ; then
+	printf 'nothing to read on stdin\n\n' >&2
+	print_usage >&2
+	exit 1
+fi
+report=$(cat)
+
+writeheaders () # <subject> <ref> <to> [cc]
+{
+	echo "Subject: $1"
+	echo "In-Reply-To: $2"
+	echo "References: $2"
+	echo "To: $3"
+	[ -z "$4" ] || echo "Cc: $4"
+	echo
+}
+
+writeheadlines () # <label> <status> <description> [pwid]
+{
+	echo "Test-Label: $1"
+	echo "Test-Status: $2"
+	[ -z "$4" ] || echo "http://dpdk.org/patch/$4"
+	echo
+	echo "_${3}_"
+	echo
+}
+
+if echo "$listid" | grep -q 'dev.dpdk.org' ; then
+	# get patchwork id
+	if [ -n "$msgid" ] ; then
+		for try in $(seq 20) ; do
+			pwid=$($pwclient list -f '%{id}' -m "$msgid")
+			[ -n "$pwid" ] && break || sleep 7
+		done
+	fi
+	[ -n "$pwid" ] || pwid='?'
+	# send public report
+	subject=$(echo $title | sed 's,\[dpdk-dev\] ,,')
+	[ "$status" = 'SUCCESS' ] && cc='' || cc="$from"
+	(
+	writeheaders "|$status| $subject" "$msgid" 'test-report at dpdk.org' "$cc"
+	writeheadlines "$label" "$status" "$desc" "$pwid"
+	echo "$report"
+	) | $sendmail -t
+else
+	# send private report
+	(
+		writeheaders "Re: $title" "$msgid" "$from"
+		writeheadlines "$label" "$status" "$desc"
+		echo "$report"
+	) | $sendmail -t
+fi
-- 
2.7.0



More information about the ci mailing list