This repository has been archived by the owner on Jun 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
precommit-total.sh
127 lines (104 loc) · 2.52 KB
/
precommit-total.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
#!/bin/sh
# ------ Variables
# Colors to be used
CLR_RED=[31m
CLR_GREEN=[32m
CLR_YELLOW=[33m
CLR_MAGENTA=[35m
CLR_CYAN=[36m
CLR_NC=[0m
# Linted modules
linted_modules="bot doc extdiscord extline extutils flags"
# ------ Functions
# Execute a django test of the module $1.
exec_django_test() {
echo
echo "${CLR_YELLOW}Running tests ($1)...${CLR_NC}"
echo
run_cmd_exit_on_err "py manage.py test $1 --failfast" "Django test ($1) - try run the tests using IDE"
}
# Runs command $1.
# If it returns error, print "Error @ $2" and exit the script with code 1.
#
# 1st parameter: command to run
# 2nd parameter: text to output if error
run_cmd_exit_on_err() {
echo "Command to run: ${CLR_MAGENTA}$1${CLR_NC}"
if ! $1; then
echo "${CLR_RED}Error @ $2${CLR_NC}"
exit 1
fi
}
# ------ Subroutines
# Print the intro output
print_intro() {
echo
echo "${CLR_CYAN}Checking the whole project...${CLR_NC}"
echo
}
# Check for errors with flake8
check_flake8_error() {
echo
echo "${CLR_YELLOW}Checking Flake8 error...${CLR_NC}"
echo
run_cmd_exit_on_err "flake8 $linted_modules --config .flake8-error --benchmark" "flake8 error check"
}
# Check for stylistic errors with flake8
check_flake8_style() {
echo
echo "${CLR_YELLOW}Checking Flake8 style...${CLR_NC}"
echo
run_cmd_exit_on_err "flake8 $linted_modules --config .flake8-style --benchmark" "flake8 style check"
}
# Lint with pydocstyle
check_pydocstyle() {
echo
echo "${CLR_YELLOW}Checking pydocstyle...${CLR_NC}"
echo
run_cmd_exit_on_err "pydocstyle $linted_modules --count" "pydocstyle check"
}
# Lint with pylint
check_pylint() {
echo
echo "${CLR_YELLOW}Checking pylint...${CLR_NC}"
echo
run_cmd_exit_on_err "pylint $linted_modules" "pylint check"
}
# Check translations
check_translations() {
echo
echo "${CLR_YELLOW}Checking translations...${CLR_NC}"
echo
run_cmd_exit_on_err "py script_check_trans.py" "translations check - incomplete translation"
}
# Django test - unit
django_test_unit() {
exec_django_test "tests.unit"
}
# Django test - integration
django_test_integration() {
exec_django_test "tests.integration"
}
# Django test - system
django_test_system() {
exec_django_test "tests.system"
}
# Print the passing message
print_pass_message() {
echo "${CLR_GREEN}Project check PASSED${CLR_NC}"
}
# ------ Main
# Intro
print_intro
# Code linting
check_flake8_error
check_flake8_style
check_pydocstyle
check_pylint
check_translations
# Tests
django_test_unit
django_test_integration
django_test_system
# Outro
print_pass_message