Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1 | #!/bin/bash |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2 | # |
| 3 | # patchtest: Run patchtest on commits starting at master |
| 4 | # |
| 5 | # Copyright (c) 2017, Intel Corporation. |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 6 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 7 | # SPDX-License-Identifier: GPL-2.0-or-later |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 8 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 9 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 10 | set -o errexit |
| 11 | |
| 12 | # Default values |
| 13 | pokydir='' |
| 14 | |
| 15 | usage() { |
| 16 | CMD=$(basename $0) |
| 17 | cat <<EOM |
| 18 | Usage: $CMD [-h] [-p pokydir] |
| 19 | -p pokydir Defaults to current directory |
| 20 | EOM |
| 21 | >&2 |
| 22 | exit 1 |
| 23 | } |
| 24 | |
| 25 | function 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 | |
| 35 | while 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 |
| 52 | done |
| 53 | shift $((OPTIND-1)) |
| 54 | |
| 55 | CDIR="$PWD" |
| 56 | |
| 57 | # default pokydir to current directory if user did not specify one |
| 58 | if [ -z "$pokydir" ]; then |
| 59 | pokydir="$CDIR" |
| 60 | fi |
| 61 | |
| 62 | PTENV="$PWD/patchtest" |
| 63 | PT="$PTENV/patchtest" |
| 64 | PTOE="$PTENV/patchtest-oe" |
| 65 | |
| 66 | if ! which virtualenv > /dev/null; then |
| 67 | echo "Install virtualenv before proceeding" |
| 68 | exit 1; |
| 69 | fi |
| 70 | |
| 71 | # activate the virtual env |
| 72 | virtualenv $PTENV --quiet |
| 73 | source $PTENV/bin/activate |
| 74 | |
| 75 | cd $PTENV |
| 76 | |
| 77 | # clone or pull |
| 78 | clone git://git.yoctoproject.org/patchtest $PT |
| 79 | clone git://git.yoctoproject.org/patchtest-oe $PTOE |
| 80 | |
| 81 | # install requirements |
| 82 | pip install -r $PT/requirements.txt --quiet |
| 83 | pip install -r $PTOE/requirements.txt --quiet |
| 84 | |
| 85 | PATH="$PT:$PT/scripts:$PATH" |
| 86 | |
| 87 | # loop through parent to HEAD and execute patchtest on each commit |
| 88 | for commit in $(git rev-list master..HEAD --reverse) |
| 89 | do |
| 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 "" |
| 100 | done |
| 101 | |
| 102 | deactivate |
| 103 | |
| 104 | cd $CDIR |