summaryrefslogtreecommitdiff
path: root/run.sh
blob: fe105032e71fd0bdf4ef107e6653b8d1d9103c1b (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
#!/bin/bash
# Usage ./run.sh

# $WORKSPACE - Jenkins Workspace Variable
# $BUILD_URL - Jenkins Build URL
# $GERRIT_* - Gerrit Jenkins Plugin Variables
GIT_SERVER="http://staging.git.linaro.org/git"
GERRIT_SERVER="ssh://lava-bot@staging.review.linaro.org:29418"
LAVA_PROJECT=$(echo $GERRIT_PROJECT | cut -c 6-)

function add_gerrit_comment()
{
	ssh staging.review.linaro.org gerrit review --code-review $1 -m "\"$2"\" $3
}

function notify_committer ()
{
	echo "* Hello $GERRIT_CHANGE_OWNER_NAME" >> $WORKSPACE/message
        echo "* Your patch set $GERRIT_PATCHSET_REVISION has triggered a PEP8 check." >> $WORKSPACE/message
        echo "* Please do not merge this commit until after I have reviewed the results with you." >> $WORKSPACE/message
	echo "* $BUILD_URL" >> $WORKSPACE/message
	GREETING_MESSAGE=$(cat $WORKSPACE/message)
	add_gerrit_comment 0 "$GREETING_MESSAGE" $GERRIT_PATCHSET_REVISION
	echo "* Test results for patch set: $GERRIT_PATCHSET_REVISION" >> $WORKSPACE/results
}

function check_step ()
{
	"$@"
	if [ $? -ne "0" ]
	then
		echo "* Step Failed: $@" >> $WORKSPACE/results
		publish_results
		exit 1
	else
		echo "* Step Passed: $@" >> $WORKSPACE/results
	fi
}

function pep8_check ()
{
	cd cd $WORKSPACE/$LAVA_PROJECT

        pep8 --ignore E501 --show-source >> $WORKSPACE/pep8

	if [[ -s $WORKSPACE/pep8 ]]
	then
		echo "* Test Failed: PEP8" >> $WORKSPACE/results
		sed 's/^/*/g' $WORKSPACE/pep8 >> $WORKSPACE/results
		echo "PEP8 CHECK FAILED:"
                pep8 --ignore E501 --show-source --show-pep8
                echo "* Please see the $BUILD_URL/console for verbose PEP8 output" >> $WORKSPACE/results
	else
		echo "* Test Passed: PEP8" >> $WORKSPACE/results
	fi
}

function checkout_and_rebase ()
{
	cd $WORKSPACE
	git clone $GIT_SERVER/$GERRIT_PROJECT
	cd $LAVA_PROJECT
	git fetch $GERRIT_SERVER/$GERRIT_PROJECT $GERRIT_REFSPEC && git checkout FETCH_HEAD && git rebase master
}

function publish_results ()
{
	echo "* $BUILD_URL" >> $WORKSPACE/results
	RESULTS_MESSAGE=$(cat $WORKSPACE/results)
	echo "$RESULTS_MESSAGE"
	if grep 'Failed' $WORKSPACE/results
	then
		add_gerrit_comment -1 "$RESULTS_MESSAGE" $GERRIT_PATCHSET_REVISION
	else
		add_gerrit_comment +1 "$RESULTS_MESSAGE" $GERRIT_PATCHSET_REVISION
	fi
}

notify_committer
check_step checkout_and_rebase
check_step pep8_check
publish_results