blob: b1e1ea334b95601c805e9ac8518818f7750ba628 [file] [log] [blame]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001#!/bin/bash
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002#
3# patchtest: Run patchtest on commits starting at master
4#
5# Copyright (c) 2017, Intel Corporation.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05006#
Brad Bishopc342db32019-05-15 21:57:59 -04007# SPDX-License-Identifier: GPL-2.0-or-later
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008#
Brad Bishopc342db32019-05-15 21:57:59 -04009
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010set -o errexit
11
12# Default values
13pokydir=''
14
15usage() {
16CMD=$(basename $0)
17cat <<EOM
18Usage: $CMD [-h] [-p pokydir]
19 -p pokydir Defaults to current directory
20EOM
21>&2
22 exit 1
23}
24
25function clone() {
26 local REPOREMOTE=$1
27 local REPODIR=$2
28 if [ ! -d $REPODIR ]; then
29 git clone $REPOREMOTE $REPODIR --quiet
30 else
31 ( cd $REPODIR; git pull --quiet )
32 fi
33}
34
35while getopts ":p:h" opt; do
36 case $opt in
37 p)
38 pokydir=$OPTARG
39 ;;
40 h)
41 usage
42 ;;
43 \?)
44 echo "Invalid option: -$OPTARG" >&2
45 usage
46 ;;
47 :)
48 echo "Option -$OPTARG requires an argument." >&2
49 usage
50 ;;
51 esac
52done
53shift $((OPTIND-1))
54
55CDIR="$PWD"
56
57# default pokydir to current directory if user did not specify one
58if [ -z "$pokydir" ]; then
59 pokydir="$CDIR"
60fi
61
62PTENV="$PWD/patchtest"
63PT="$PTENV/patchtest"
64PTOE="$PTENV/patchtest-oe"
65
66if ! which virtualenv > /dev/null; then
67 echo "Install virtualenv before proceeding"
68 exit 1;
69fi
70
71# activate the virtual env
72virtualenv $PTENV --quiet
73source $PTENV/bin/activate
74
75cd $PTENV
76
77# clone or pull
78clone git://git.yoctoproject.org/patchtest $PT
79clone git://git.yoctoproject.org/patchtest-oe $PTOE
80
81# install requirements
82pip install -r $PT/requirements.txt --quiet
83pip install -r $PTOE/requirements.txt --quiet
84
85PATH="$PT:$PT/scripts:$PATH"
86
87# loop through parent to HEAD and execute patchtest on each commit
88for commit in $(git rev-list master..HEAD --reverse)
89do
90 shortlog="$(git log "$commit^1..$commit" --pretty='%h: %aN: %cd: %s')"
91 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)"
92 if [ -z "$log" ]; then
93 shortlog="$shortlog: OK"
94 else
95 shortlog="$shortlog: FAIL"
96 fi
97 echo "$shortlog"
98 echo "$log" | sed -n -e '/Issue/p' -e '/Suggested fix/p'
99 echo ""
100done
101
102deactivate
103
104cd $CDIR