This repository has been archived by the owner on Feb 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcode_check.sh
executable file
·157 lines (139 loc) · 4.15 KB
/
code_check.sh
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/bin/bash
# ** does not work out of the box on our jenkins machine
start=$(date +%s)
set -e
shopt -s extglob
BRANCH=${CHANGE_BRANCH:-local}
# If run in local, add `local` as a param to the script to not recreate the venv
echo "Building ${BRANCH}"
if ! [ -z "${1+x}" ] && [ "$1" == "local" ]; then
echo "Executing locally"
echo "Assuming we are in a venv, that is up-to-date"
if [ -z "${VIRTUAL_ENV+x}" ]; then
echo "Not in a virtualenv, aborting"
exit 1
fi
else
echo "Creating the venv"
VENV=venv
if [ ! -d ${VENV} -o ! -f ${VENV}/bin/activate ]; then
virtualenv -p python3.6 ${VENV}
fi
source ${VENV}/bin/activate
set -x
pip install -r requirements/dev.txt
set +x
fi
# New apps should have all their code under a folder. This is not the case here yet
# APP="cloud_processing git_helpers tests utils web_mapper"
APPS=()
APPS_NO_TESTS=()
for folder in `find . -maxdepth 1 -type d | grep -v settings | sed s^\.\/^^`
do
if [ -f "${folder}/__init__.py" ]; then
APPS+=("$folder")
if [ "${folder}" != "tests" ]; then
APPS_NO_TESTS+=("$folder")
fi
fi
done
echo "Re-creating the reports folder"
REPORTS=reports
if [ -d ${REPORTS} ]; then
rm -rf ${REPORTS}
fi
mkdir ${REPORTS}
# We don't allow the setup to fail. But then we execute each step whether the previous ran or not
# and consolidate the error codes at the end
set +e
#### PYLINT
pylint_start=$(date +%s)
ret_code=0
set -x
`pylint -j 2 --output-format=parseable --rcfile=.pylintrc ${APPS_NO_TESTS[@]} >> "${REPORTS}/pylint.txt" 2>&1`
cmd_ret_pylint=$?
set +x
if [ $cmd_ret_pylint -ne 0 ]; then
printf "\x1b[31m[ERROR]\x1b[0m Pylint failed\n"
fi
pylint_end=$(date +%s)
ret_code=$(expr $ret_code + $cmd_ret_pylint)
#### FLAKE8
flake8_start=$(date +%s)
set -x
flake8 --config=setup.cfg ${APPS[@]} > ${REPORTS}/flake8.txt 2>&1
cmd_ret_flake8=$?
set +x
if [ $cmd_ret_flake8 -ne 0 ]; then
printf "\x1b[31m[ERROR]\x1b[0m Flake8 failed\n"
fi
flake8_end=$(date +%s)
ret_code=$(expr $ret_code + $cmd_ret_flake8)
#### MYPY
mypy_start=$(date +%s)
set -x
mypy --config-file=setup.cfg ${APPS_NO_TESTS[@]} > ${REPORTS}/mypy.txt 2>&1
cmd_ret_mypy=$?
set +x
if [ $cmd_ret_mypy -ne 0 ]; then
printf "\x1b[31m[ERROR]\x1b[0m Mypy failed\n"
fi
mypy_end=$(date +%s)
ret_code=$(expr $ret_code + $cmd_ret_mypy)
#### TEST
test_start=$(date +%s)
set -x
coverage run -m pytest > ${REPORTS}/test.txt 2>&1
cmd_ret_test=$?
set +x
if [ $cmd_ret_test -ne 0 ]; then
printf "\x1b[31m[ERROR]\x1b[0m Test failed\n"
fi
test_end=$(date +%s)
ret_code=$(expr $ret_code + $cmd_ret_test)
cov_start=$(date +%s)
set -x
coverage html --rcfile=${REPORTS}/../setup.cfg
cmd_ret_cov=$?
set +x
if [ $cmd_ret_cov -ne 0 ]; then
printf "\x1b[31m[ERROR]\x1b[0m Coverage failed\n"
fi
cov_end=$(date +%s)
set +x
end=$(date +%s)
echo ""
echo ""
echo "================== SUMMARY =================="
if [ $cmd_ret_pylint -ne 0 ]; then
printf "* PYLINT: \x1b[31m[ERROR]\x1b[0m %s s\n" $((pylint_end-pylint_start))
else
printf "* PYLINT: \x1b[32m[SUCCESS]\x1b[0m %s s\n" $((pylint_end-pylint_start))
fi
if [ $cmd_ret_flake8 -ne 0 ]; then
printf "* FLAKE8: \x1b[31m[ERROR]\x1b[0m %s s\n" $((flake8_end-flake8_start))
else
printf "* FLAKE8: \x1b[32m[SUCCESS]\x1b[0m %s s\n" $((flake8_end-flake8_start))
fi
if [ $cmd_ret_mypy -ne 0 ]; then
printf "* MYPY: \x1b[31m[ERROR]\x1b[0m %s s\n" $((mypy_end-mypy_start))
else
printf "* MYPY: \x1b[32m[SUCCESS]\x1b[0m %s s\n" $((mypy_end-mypy_start))
fi
if [ $cmd_ret_test -ne 0 ]; then
printf "* TEST: \x1b[31m[ERROR]\x1b[0m %s s\n" $((test_end-test_start))
else
printf "* TEST: \x1b[32m[SUCCESS]\x1b[0m %s s\n" $((test_end-test_start))
fi
if [ $cmd_ret_cov -ne 0 ]; then
printf "* COVERAGE: \x1b[31m[ERROR]\x1b[0m %s s\n" $((cov_end-cov_start))
else
printf "* COVERAGE: \x1b[32m[SUCCESS]\x1b[0m %s s\n" $((cov_end-cov_start))
fi
echo "============================================="
echo " Execution time:" $((end-start)) "sec"
echo ""
echo "Note that E2E tests were not run. You can run them with"
echo " python -m unittest test_processing.test"
set -x
exit $ret_code