mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-18 02:50:30 +00:00
Add static check tools
Added md check to check .md style Add yamllint to check yaml style Moved gometalinter to scripts folder Signed-off-by: Madhu Rajanna <mrajanna@redhat.com>
This commit is contained in:
parent
a44da1ba5d
commit
1f3b32085c
12
scripts/lint-go.sh
Executable file
12
scripts/lint-go.sh
Executable file
@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
|
if [[ -x "$(command -v gometalinter)" ]]; then
|
||||||
|
gometalinter -j "${GO_METALINTER_THREADS:-1}" \
|
||||||
|
--sort path --sort line --sort column --deadline=10m \
|
||||||
|
--enable=misspell --enable=staticcheck \
|
||||||
|
--vendor "${@-./...}"
|
||||||
|
else
|
||||||
|
echo "WARNING: gometalinter not found, skipping lint tests" >&2
|
||||||
|
fi
|
49
scripts/lint-text.sh
Executable file
49
scripts/lint-text.sh
Executable file
@ -0,0 +1,49 @@
|
|||||||
|
#! /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 . -path ./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
|
||||||
|
|
||||||
|
# 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 scripts/mdl-style.rb
|
||||||
|
|
||||||
|
# Install via: dnf install shellcheck
|
||||||
|
run_check '.*\.(ba)?sh' shellcheck
|
||||||
|
run_check '.*\.(ba)?sh' bash -n
|
||||||
|
|
||||||
|
# Install via: pip install yamllint
|
||||||
|
# disable yamlint chekck for helm chats
|
||||||
|
run_check '.*\.ya?ml' yamllint -s -d "{extends: default, rules: {line-length: {allow-non-breakable-inline-mappings: true}},ignore: deploy/rbd/helm/templates/*.yaml}"
|
||||||
|
|
||||||
|
echo "ALL OK."
|
9
scripts/mdl-style.rb
Normal file
9
scripts/mdl-style.rb
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
all
|
||||||
|
|
||||||
|
#Refer below url for more information about the markdown rules.
|
||||||
|
#https://github.com/markdownlint/markdownlint/blob/master/docs/RULES.md
|
||||||
|
|
||||||
|
rule 'MD013', :code_blocks => false, :tables => false
|
||||||
|
|
||||||
|
exclude_rule 'MD040' # Fenced code blocks should have a language specified
|
||||||
|
exclude_rule 'MD041' # First line in file should be a top level header
|
42
scripts/test-go.sh
Executable file
42
scripts/test-go.sh
Executable file
@ -0,0 +1,42 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
GOPACKAGES="$(go list ./... | grep -v vendor | grep -v e2e)"
|
||||||
|
COVERFILE="${GO_COVER_DIR}profile.cov"
|
||||||
|
|
||||||
|
# no special options, exec to go test w/ all pkgs
|
||||||
|
if [[ ${TEST_EXITFIRST} != "yes" && -z ${TEST_COVERAGE} ]]; then
|
||||||
|
# shellcheck disable=SC2086
|
||||||
|
exec go test ${GOPACKAGES}
|
||||||
|
fi
|
||||||
|
|
||||||
|
# our options are set so we need to handle each go package one
|
||||||
|
# at at time
|
||||||
|
if [[ ${TEST_COVERAGE} ]]; then
|
||||||
|
GOTESTOPTS="-covermode=count -coverprofile=cover.out"
|
||||||
|
echo "mode: count" > "${COVERFILE}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
failed=0
|
||||||
|
for gopackage in ${GOPACKAGES}; do
|
||||||
|
echo "--- testing: ${gopackage} ---"
|
||||||
|
# shellcheck disable=SC2086
|
||||||
|
go test ${GOTESTOPTS} "${gopackage}" || ((failed+=1))
|
||||||
|
if [[ -f cover.out ]]; then
|
||||||
|
# Append to coverfile
|
||||||
|
grep -v "^mode: count" cover.out >> "${COVERFILE}"
|
||||||
|
fi
|
||||||
|
if [[ ${TEST_COVERAGE} = "stdout" && -f cover.out ]]; then
|
||||||
|
go tool cover -func=cover.out
|
||||||
|
fi
|
||||||
|
if [[ ${TEST_COVERAGE} = "html" && -f cover.out ]]; then
|
||||||
|
mkdir -p coverage
|
||||||
|
fn="coverage/${gopackage////-}.html"
|
||||||
|
echo " * generating coverage html: ${fn}"
|
||||||
|
go tool cover -html=cover.out -o "${fn}"
|
||||||
|
fi
|
||||||
|
rm -f cover.out
|
||||||
|
if [[ ${failed} -ne 0 && ${TEST_EXITFIRST} = "yes" ]]; then
|
||||||
|
exit ${failed}
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
exit ${failed}
|
Loading…
Reference in New Issue
Block a user