-
Notifications
You must be signed in to change notification settings - Fork 23
/
run-code-analysis.sh
executable file
·92 lines (66 loc) · 2.43 KB
/
run-code-analysis.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
#!/bin/bash
declare -a RESULT
# specifies a set of variables to declare CLI output color
FAILED_OUT="\033[0;31m"
PASSED_OUT="\033[0;32m"
NONE_OUT="\033[0m"
# specifies a set of variables to declare files to be used for code assessment
PROJECT_FILES="./"
LIB_FILES="demoauto"
function store-failures {
RESULT+=("$1")
}
function remove-pycache-trash {
local PYCACHE_DIR="__pycache__"
echo "Removing ${PYCACHE_DIR} directories if present ..."
( find . -d -name ${PYCACHE_DIR} | xargs rm -r ) || echo -e "No ${PYCACHE_DIR} found"
}
function remove-analysis-trash {
local PYTEST_CACHE_DIR='.pytest_cache'
local MYPY_CACHE_DIR='.mypy_cache'
echo "Removing code analysis trash if present ..."
[[ -d "$PYTEST_CACHE_DIR" ]] && rm -rf ${PYTEST_CACHE_DIR} && echo "pytest trash is removed"
[[ -d "$MYPY_CACHE_DIR" ]] && rm -rf ${MYPY_CACHE_DIR} && echo "mypy trash is removed"
}
function install-dependencies {
echo "Installing python code analysis packages ..." \
&& ( pip install --no-cache-dir --upgrade pip ) \
&& ( pip install --no-cache-dir -r requirements-dev.txt )
}
function run-unittests {
echo "Running unittests ..." && ( pytest -m unit )
}
function run-black-analysis {
echo "Running black analysis ..." && ( black --check "${PROJECT_FILES}" )
}
function run-flake8-analysis {
echo "Running flake8 analysis ..." && ( flake8 "${PROJECT_FILES}" )
}
function run-mypy-analysis() {
echo "Running mypy analysis ..." && mypy --package "${LIB_FILES}"
}
function run-code-analysis {
echo "Running code analysis ..."
remove-pycache-trash
run-unittests || store-failures "Unittests are failed!"
run-black-analysis || store-failures "black analysis is failed!"
run-flake8-analysis || store-failures "flake8 analysis is failed!"
run-mypy-analysis || store-failures "mypy analysis is failed!"
if [[ ${#RESULT[@]} -ne 0 ]];
then echo -e "${FAILED_OUT}Some errors occurred while analysing the code quality.${NONE_OUT}"
for failed_item in "${RESULT[@]}"; do
echo -e "${FAILED_OUT}- ${failed_item}${NONE_OUT}"
done
remove-analysis-trash
exit 1
fi
remove-analysis-trash
echo -e "${PASSED_OUT}Code analysis is passed${NONE_OUT}"
}
function main() {
if [[ "$1" == "install-dependencies" ]];
then install-dependencies || store-failures "Python packages installation is failed!";
fi
run-code-analysis
}
main "$@"