-
Notifications
You must be signed in to change notification settings - Fork 19
/
build.sh
executable file
·48 lines (40 loc) · 896 Bytes
/
build.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
#!/usr/bin/env bash
set -eo pipefail
test -n "${DEBUG:-}" && set -x
success() {
printf "\r [ \033[00;32mOK\033[0m ] Linting %s...\n" "$1"
}
fail() {
printf "\r [\033[0;31mFAIL\033[0m] Linting %s...\n" "$1"
exit 1
}
info() {
printf "\r [ \033[00;34m??\033[0m ] %s\n" "$1"
}
check() {
local script="$1"
shellcheck "$script" || fail "$script"
success "$script"
}
find_scripts() {
git ls-tree -r HEAD | grep -E '^1007|.*\..*sh$' | awk '{print $4}'
}
is_compatible() {
head -n1 "$1" | grep -E -w "sh|bash|ksh" >/dev/null 2>&1
}
check_all_executables() {
echo "Linting all executables and .*sh files..."
find_scripts | while read -r script; do
if is_compatible "$script"; then
check "$script"
else
info "Skipping $script..."
fi
done
}
# if being executed, check all executables, otherwise do nothing
if [ $SHLVL -gt 1 ]; then
check_all_executables
else
return 0
fi