-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
80 lines (72 loc) · 2.22 KB
/
docker-entrypoint.sh
File metadata and controls
80 lines (72 loc) · 2.22 KB
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
#!/bin/bash
if [ -f "~/.bashrc" ]; then
source ~/.bashrc
fi
command=""
if [[ $# == 0 ]]
then
echo "No arguments passed."
exit 1
else
command=$1
fi
if [[ $USE_GIT = "1" || $USE_GIT = "true" ]]; then
mapfile -t PYTHON_DIRS < <(git diff --cached --name-status | awk -e '$1 != "D" && $2 ~ /\.py$/ {print $2}')
if [[ ${#PYTHON_DIRS[@]} = 0 ]]; then
echo "No changes detected in the .py files. Try to detect the whole project."
fi
else
declare -a PYTHON_DIRS=()
fi
if [[ ${#PYTHON_DIRS[@]} = 0 ]]; then
PYTHON_DIRS=(./*.py test/ commitytools/)
fi
function print_yapf_tips() {
echo "If you add a new directory to the project, or create a Python file in a directory that didn't contain any scritps, please make sur that the directory is added to the following YAPF commands:"
echo " * In ./docker-entrypoint.sh, the variable PYTHON_DIRS must contain all directories that have Python scripts."
echo " * In ./github/worksflows/main.yml, the job \"lint\" contains a YAPF command."
echo " * In ./.git/hooks/pre-commit must have the specified directories as well, at two different places."
echo ''
echo "Please update those elements if necessary."
}
exit_code=0
# Parse command
if [ $command == "run" ]
then
echo "${@:2}"
python commity.py "${@:2}"
exit_code=$?
elif [[ $command = "lint" ]]; then
if [[ $USE_GIT != "1" && $USE_GIT != "true" ]]; then
print_yapf_tips
fi
echo "Running lint..."
begin=$(date +%s)
yapf -r --diff "${PYTHON_DIRS[@]}"
exit_code=$?
end=$(date +%s)
echo "Time elapsed to run lint: $((end - begin))s"
elif [[ $command = "fix lint" || $command = "fix-lint" || $command = "lint fix" || $command = "lint-fix" ]]; then
if [[ $USE_GIT != "1" && $USE_GIT != "true" ]]; then
print_yapf_tips
fi
echo "Running fix-lint..."
begin=$(date +%s)
yapf -ir "${PYTHON_DIRS[@]}"
exit_code=$?
end=$(date +%s)
echo "Time elapsed to run lint and fix syntax: $((end - begin))s"
elif [ $command == "test" ]
then
echo "Covering Python code..."
begin=$(date +%s)
coverage run --source="$(pwd)" -m unittest discover --failfast -p "*_test.py" -v
exit_code=$?
coverage report --include="$(pwd)/*" -m
end=$(date +%s)
else
echo -e "Couldn't interpret command '$command'.\All arguments: $*"
exit 1
fi
echo "$exit_code"
exit $exit_code