forked from JohnStrunk/ocs-monkey-original
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-commit.sh
executable file
·51 lines (40 loc) · 1.4 KB
/
pre-commit.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
#! /bin/bash
# vim: set ts=4 sw=4 et :
# Usage: pre-commit.sh [--require-all]
# --require-all Fail instead of warn if a checker is not found
set -e
# Run checks from root of the repo
scriptdir="$(dirname "$(realpath "$0")")"
cd "$scriptdir/.."
# run_check <file_regex> <checker_exe> [optional args to checker...]
function run_check() {
regex="$1"
shift
exe="$1"
shift
if [ -x "$(command -v "$exe")" ]; then
find . -name vendor -prune -o \
-regextype egrep -iregex "$regex" -print0 | \
xargs -0rt -n1 "$exe" "$@"
elif [ "$all_required" -eq 0 ]; then
echo "Warning: $exe not found... skipping some tests."
else
echo "FAILED: All checks required, but $exe not found!"
exit 1
fi
}
all_required=0
if [ "x$1" == "x--require-all" ]; then
all_required=1
fi
# Install via: gem install asciidoctor
run_check '.*\.adoc' asciidoctor -o /dev/null -v --failure-level WARN
# markdownlint: https://github.com/markdownlint/markdownlint
# https://github.com/markdownlint/markdownlint/blob/master/docs/RULES.md
# Install via: gem install mdl
run_check '.*\.md' mdl --style "${scriptdir}/mdl-style.rb"
# Install via: dnf install shellcheck
run_check '.*\.(ba)?sh' shellcheck
# Install via: pip install yamllint
run_check '.*\.ya?ml' yamllint -s -d "{extends: default, rules: {line-length: {allow-non-breakable-inline-mappings: true}}}"
echo "ALL OK."