patchtest.sh 2.0 KB

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