-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdo-static-analysis.sh
executable file
·75 lines (67 loc) · 1.83 KB
/
do-static-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
#!/usr/bin/env bash
# Check potential problems in the project
# Copyright 2024 林博仁(Buo-ren Lin) <[email protected]>
# SPDX-License-Identifier: CC-BY-SA-4.0 OR LicenseRef-Apache-2.0-If-Not-Used-In-Template-Projects
set \
-o errexit \
-o nounset
script="${BASH_SOURCE[0]}"
if ! script="$(
realpath \
--strip \
"${script}"
)"; then
printf \
'Error: Unable to determine the absolute path of the program.\n' \
1>&2
exit 1
fi
script_dir="${script%/*}"
project_dir="$(dirname "${script_dir}")"
cache_dir="${project_dir}/.cache"
if ! test -e "${script_dir}/venv"; then
printf \
'Info: Initializing the Python virtual environment...\n'
if ! python3 -m venv "${script_dir}/venv"; then
printf \
'Error: Unable to initialize the Python virtual environment.\n' \
1>&2
exit 2
fi
fi
printf \
'Info: Activating the Python virtual environment...\n'
# Out of scope
# shellcheck source=/dev/null
if ! source "${script_dir}/venv/bin/activate"; then
printf \
'Error: Unable to activate the Python virtual environment.\n' \
1>&2
exit 2
fi
printf \
'Info: Installing pre-commit...\n'
if ! pip show pre-commit &>/dev/null; then
if ! pip install pre-commit; then
printf \
'Error: Unable to install pre-commit.\n' \
1>&2
exit 2
fi
fi
printf \
'Info: Setting up the command search PATHs so that the installed shellcheck command can be located...\n'
PATH="${cache_dir}/shellcheck-stable:${PATH}"
printf \
'Info: Running pre-commit...\n'
if ! \
pre-commit run \
--all-files \
--color always; then
printf \
'Error: pre-commit check has failed, please verify.\n' \
1>&2
exit 3
fi
printf \
'Info: Operation completed without errors.\n'