-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
75 lines (66 loc) · 1.43 KB
/
entrypoint.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
set -o noglob
POLINT='/go/bin/po-lint'
error() {
echo >&2 ":: [Error]: $*"
exit 1
}
info() {
echo >&1 ":: [Info]: $*"
return 0
}
_command() {
local _return cmd
cmd="$1"
_return=1
command -v "$cmd" >/dev/null && _return=0
return ${_return}
}
# shellcheck disable=SC2086
_find() {
local path="$1"
local glob_pattern="${2:-*.y*ml}"
local cmd="$path -name ${glob_pattern}"
local files
files="$(find $cmd)"
echo "$files"
}
_check() {
local files="$1"
local exclude="${2:-""}"
local errors=0
for file in $files; do
if [[ -n $exclude ]]; then
if echo "$file" | grep -Eq "$exclude"; then
info "Skipping file: $file"
continue
fi
fi
info "Checking file: $file"
if ! "$POLINT" "$file"; then
((errors+=1))
fi
done
return $errors
}
lint() {
local path="$1"
local glob_pattern="${2:-*.y*ml}"
local exclude="${3:-""}"
_command "$POLINT" || error "$POLINT linter not installed"
local files
files=$(_find "$path" "${glob_pattern}")
info "Linting '${glob_pattern}' files in '${path}' directory"
_check "$files" "$exclude"
}
main() {
local path="$1"
local glob_pattern="${2:-*.y*ml}"
local exclude="${3:-""}"
[[ ! -d $path ]] && error "$path directory not found"
if ! lint "$path" "${glob_pattern}" "$exclude"; then
error "Linting failed"
fi
info "Linting succeded"
}
main "$@"