NSB NFVi BNG test fails to run - stops after one step
[yardstick.git] / tools / coding-checks.sh
1 #!/bin/sh
2 # source: https://github.com/openstack/neutron/blob/master/tools/coding-checks.sh
3
4 set -eu
5
6 usage () {
7     echo "Usage: $0 [OPTION]..."
8     echo "Run Yardstick's coding check(s)"
9     echo ""
10     echo "  -Y, --pylint [<basecommit>] Run pylint check on the entire neutron module or just files changed in basecommit (e.g. HEAD~1)"
11     echo "  -h, --help                  Print this usage message"
12     echo
13     exit 0
14 }
15
16 process_options () {
17     i=1
18     while [ $i -le $# ]; do
19         eval opt=\$$i
20         case $opt in
21             -h|--help) usage;;
22             -Y|--pylint) pylint=1;;
23             *) scriptargs="$scriptargs $opt"
24         esac
25         i=$((i+1))
26     done
27 }
28
29 run_pylint () {
30     local target="${scriptargs:-all}"
31     local output_format=""
32
33     if [ "$target" = "all" ]; then
34         files="ansible api tests yardstick"
35     else
36         case "$target" in
37             *HEAD*|*HEAD~[0-9]*) files=$(git diff --diff-filter=AM --name-only $target -- "*.py");;
38             *) echo "$target is an unrecognized basecommit"; exit 1;;
39         esac
40     fi
41     # make Jenkins output parseable because Jenkins doesn't handle color
42     # enventually we should use the Jenkins Pylint plugin or other tools
43     if [ -n "${BRANCH:-}" ] ; then
44         output_format="--output-format=parseable"
45     fi
46     echo "Running pylint..."
47     echo "You can speed this up by running it on 'HEAD~[0-9]' (e.g. HEAD~0, this change only)..."
48     if [ -n "${files}" ]; then
49         pylint --rcfile=.pylintrc ${output_format} ${files}
50     else
51         echo "No python changes in this commit, pylint check not required."
52         exit 0
53     fi
54 }
55
56 scriptargs=
57 pylint=1
58
59 process_options $@
60
61 if [ $pylint -eq 1 ]; then
62     run_pylint
63     exit 0
64 fi