|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | | -C_RESET='\033[0m' |
4 | | -C_I_BLUE='\033[0;94m' |
5 | | -C_I_GREEN='\033[0;92m' |
6 | | -C_I_RED='\033[0;91m' |
| 3 | +readonly C_RESET='\033[0m' |
| 4 | +readonly C_I_BLUE='\033[0;94m' |
| 5 | +readonly C_I_GREEN='\033[0;92m' |
| 6 | +readonly C_I_RED='\033[0;91m' |
7 | 7 |
|
8 | | -echo -e "${C_I_BLUE}Running python linter...${C_RESET}" |
| 8 | +readonly MODE_FULL="full" |
| 9 | +readonly MODE_BACKEND="backend" |
| 10 | +readonly MODE_FRONTEND="frontend" |
9 | 11 |
|
10 | | -poetry run -q flake8 |
| 12 | +MODE=$MODE_FULL |
11 | 13 |
|
12 | | -if [ $? -ne 0 ]; then |
13 | | - echo -e "${C_I_RED}Python linting failed${C_RESET} \xf0\x9f\x98\xb1" |
14 | | - exit 1 |
15 | | -fi |
| 14 | +usage() { |
| 15 | + echo "Usage: $0 [ -m MODE ]" 1>&2 |
| 16 | +} |
| 17 | + |
| 18 | +exit_abnormal() { |
| 19 | + usage |
| 20 | + exit 1 |
| 21 | +} |
| 22 | + |
| 23 | +while getopts ":m:" options; do |
| 24 | + case "${options}" in |
| 25 | + m) |
| 26 | + MODE=${OPTARG} |
| 27 | + |
| 28 | + case $MODE in |
| 29 | + $MODE_FULL|$MODE_BACKEND|$MODE_FRONTEND) |
| 30 | + ;; |
| 31 | + *) |
| 32 | + echo "Error: MODE must be one of (${MODE_FULL},${MODE_BACKEND},${MODE_FRONTEND})." |
| 33 | + exit_abnormal |
| 34 | + ;; |
| 35 | + esac |
| 36 | + |
| 37 | + ;; |
| 38 | + :) |
| 39 | + echo "Error: -${OPTARG} requires an argument." |
| 40 | + exit_abnormal |
| 41 | + ;; |
| 42 | + *) |
| 43 | + exit_abnormal |
| 44 | + ;; |
| 45 | + esac |
| 46 | +done |
| 47 | + |
| 48 | +if [[ $MODE = $MODE_BACKEND || $MODE = $MODE_FULL ]]; then |
| 49 | + echo -e "${C_I_BLUE}Running python linter...${C_RESET}" |
| 50 | + |
| 51 | + poetry run -q flake8 |
| 52 | + |
| 53 | + if [ $? -ne 0 ]; then |
| 54 | + echo -e "${C_I_RED}Python linting failed${C_RESET} \xf0\x9f\x98\xb1" |
| 55 | + exit 1 |
| 56 | + fi |
16 | 57 |
|
17 | 58 |
|
18 | | -echo -e "${C_I_BLUE}Running python tests suite...${C_RESET}" |
| 59 | + echo -e "${C_I_BLUE}Running python tests suite...${C_RESET}" |
19 | 60 |
|
20 | | -poetry run -q pytest |
| 61 | + poetry run -q pytest |
21 | 62 |
|
22 | | -if [ $? -ne 0 ]; then |
23 | | - echo -e "${C_I_RED}Python tests failed${C_RESET} \xf0\x9f\x98\xb1" |
24 | | - exit 1 |
| 63 | + if [ $? -ne 0 ]; then |
| 64 | + echo -e "${C_I_RED}Python tests failed${C_RESET} \xf0\x9f\x98\xb1" |
| 65 | + exit 1 |
| 66 | + fi |
25 | 67 | fi |
26 | 68 |
|
27 | | -if [ -f "package.json" ]; then |
28 | | - echo -e "${C_I_BLUE}Running JS linter...${C_RESET}" |
29 | | - npm run lint |
30 | | - if [ $? -ne 0 ]; then |
31 | | - echo -e "${C_I_RED}JS linting failed${C_RESET} \xf0\x9f\x98\xb1" |
32 | | - exit 1 |
33 | | - fi |
34 | | - echo -e "${C_I_BLUE}Running JS tests suite...${C_RESET}" |
35 | | - npm run test |
36 | | - if [ $? -ne 0 ]; then |
37 | | - echo -e "${C_I_RED}JS tests failed${C_RESET} \xf0\x9f\x98\xb1" |
38 | | - exit 1 |
39 | | - fi |
| 69 | +if [[ $MODE = $MODE_FRONTEND || $MODE = $MODE_FULL ]]; then |
| 70 | + if [ -f "package.json" ]; then |
| 71 | + echo -e "${C_I_BLUE}Running JS linter...${C_RESET}" |
| 72 | + npm run lint |
| 73 | + if [ $? -ne 0 ]; then |
| 74 | + echo -e "${C_I_RED}JS linting failed${C_RESET} \xf0\x9f\x98\xb1" |
| 75 | + exit 1 |
| 76 | + fi |
| 77 | + echo -e "${C_I_BLUE}Running JS tests suite...${C_RESET}" |
| 78 | + npm run test |
| 79 | + if [ $? -ne 0 ]; then |
| 80 | + echo -e "${C_I_RED}JS tests failed${C_RESET} \xf0\x9f\x98\xb1" |
| 81 | + exit 1 |
| 82 | + fi |
| 83 | + fi |
40 | 84 | fi |
41 | 85 |
|
42 | 86 | echo -e "${C_I_GREEN}Testing completed succesfully${C_RESET} \xf0\x9f\x8d\xba \xf0\x9f\xa5\xb3" |
0 commit comments