summaryrefslogtreecommitdiffstats
path: root/scripts/contrib/patchtest.sh
blob: 7fe566666e1a1d2013a85d09e806b00a53f0e6a2 (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
#!/bin/bash
# ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
#
# patchtest: Run patchtest on commits starting at master
#
# Copyright (c) 2017, Intel Corporation.
# All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
set -o errexit

# Default values
pokydir=''

usage() {
CMD=$(basename $0)
cat <<EOM
Usage: $CMD [-h] [-p pokydir]
  -p pokydir  Defaults to current directory
EOM
>&2
    exit 1
}

function clone() {
    local REPOREMOTE=$1
    local REPODIR=$2
    if [ ! -d $REPODIR ]; then
	git clone $REPOREMOTE $REPODIR --quiet
    else
	( cd $REPODIR; git pull --quiet )
    fi
}

while getopts ":p:h" opt; do
    case $opt in
	p)
	    pokydir=$OPTARG
	    ;;
	h)
	    usage
	    ;;
	\?)
	    echo "Invalid option: -$OPTARG" >&2
	    usage
	    ;;
	:)
	    echo "Option -$OPTARG requires an argument." >&2
	    usage
	    ;;
    esac
done
shift $((OPTIND-1))

CDIR="$PWD"

# default pokydir to current directory if user did not specify one
if [ -z "$pokydir" ]; then
    pokydir="$CDIR"
fi

PTENV="$PWD/patchtest"
PT="$PTENV/patchtest"
PTOE="$PTENV/patchtest-oe"

if ! which virtualenv > /dev/null; then
    echo "Install virtualenv before proceeding"
    exit 1;
fi

# activate the virtual env
virtualenv $PTENV --quiet
source $PTENV/bin/activate

cd $PTENV

# clone or pull
clone git://git.yoctoproject.org/patchtest $PT
clone git://git.yoctoproject.org/patchtest-oe $PTOE

# install requirements
pip install -r $PT/requirements.txt --quiet
pip install -r $PTOE/requirements.txt --quiet

PATH="$PT:$PT/scripts:$PATH"

# loop through parent to HEAD and execute patchtest on each commit
for commit in $(git rev-list master..HEAD --reverse)
do
    shortlog="$(git log "$commit^1..$commit" --pretty='%h: %aN: %cd: %s')"
    log="$(git format-patch "$commit^1..$commit" --stdout | patchtest - -r $pokydir -s $PTOE/tests --base-commit $commit^1 --json 2>/dev/null | create-summary --fail --only-results)"
    if [ -z "$log" ]; then
	shortlog="$shortlog: OK"
    else
	shortlog="$shortlog: FAIL"
    fi
    echo "$shortlog"
    echo "$log" | sed -n -e '/Issue/p' -e '/Suggested fix/p'
    echo ""
done

deactivate

cd $CDIR