mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-18 02:50:30 +00:00
ci: updated shell script to run individual test
Earlier we were running all the linter for non-go files in one short, this wont be helpful for the users who want to run particular tests. now the Makefile as different target to run separate lint test for different type of non-go files. Fixes: #979 Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
parent
f889dc20bd
commit
3482cb7091
@ -81,7 +81,7 @@ jobs:
|
||||
| bash -s -- -v "${HELM_VERSION}"
|
||||
script:
|
||||
- make go-lint
|
||||
- make go-lint-text
|
||||
- make lint-extras
|
||||
- make gosec
|
||||
- make go-test
|
||||
- make mod-check
|
||||
|
20
Makefile
20
Makefile
@ -60,9 +60,9 @@ endif
|
||||
|
||||
all: cephcsi
|
||||
|
||||
.PHONY: go-test static-check mod-check go-lint go-lint-text gosec
|
||||
.PHONY: go-test static-check mod-check go-lint lint-extras gosec
|
||||
test: go-test static-check mod-check
|
||||
static-check: check-env go-lint go-lint-text gosec
|
||||
static-check: check-env go-lint lint-extras gosec
|
||||
|
||||
go-test: check-env
|
||||
./scripts/test-go.sh
|
||||
@ -74,8 +74,20 @@ mod-check: check-env
|
||||
go-lint:
|
||||
./scripts/lint-go.sh
|
||||
|
||||
go-lint-text:
|
||||
./scripts/lint-text.sh --require-all
|
||||
lint-extras:
|
||||
./scripts/lint-extras.sh lint-all
|
||||
|
||||
lint-shell:
|
||||
./scripts/lint-extras.sh lint-shell
|
||||
|
||||
lint-markdown:
|
||||
./scripts/lint-extras.sh lint-markdown
|
||||
|
||||
lint-yaml:
|
||||
./scripts/lint-extras.sh lint-yaml
|
||||
|
||||
lint-helm:
|
||||
./scripts/lint-extras.sh lint-helm
|
||||
|
||||
gosec:
|
||||
./scripts/gosec.sh
|
||||
|
96
scripts/lint-extras.sh
Executable file
96
scripts/lint-extras.sh
Executable file
@ -0,0 +1,96 @@
|
||||
#!/bin/bash
|
||||
# vim: set ts=4 sw=4 et :
|
||||
|
||||
# This script will be used to lint non-go files
|
||||
# Usage: ./scripts/lint-extras.sh <command>
|
||||
# Available commands are [lint-shell lint-yaml lint-markdown lint-helmlint-all ]
|
||||
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...]
|
||||
# Pass empty regex when no regex is needed
|
||||
function run_check() {
|
||||
local regex="$1"
|
||||
shift
|
||||
local exe="$1"
|
||||
shift
|
||||
|
||||
if [ -x "$(command -v "${exe}")" ]; then
|
||||
if [ -z "${regex}" ]; then
|
||||
"$exe" "$@"
|
||||
else
|
||||
find . -path ./vendor -prune -o -regextype egrep -iregex "$regex" -print0 |
|
||||
xargs -0rt -n1 "$exe" "$@"
|
||||
fi
|
||||
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
|
||||
|
||||
function lint_markdown() {
|
||||
# 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
|
||||
}
|
||||
|
||||
function lint_shell() {
|
||||
# Install via: dnf install shellcheck
|
||||
run_check '.*\.(ba)?sh' shellcheck --external-sources
|
||||
run_check '.*\.(ba)?sh' bash -n
|
||||
}
|
||||
|
||||
function lint_yaml() {
|
||||
# Install via: pip install yamllint
|
||||
# disable yamlint check for helm charts
|
||||
run_check '.*\.ya?ml' yamllint -s -d "{extends: default, rules: {line-length: {allow-non-breakable-inline-mappings: true}},ignore: charts/*/templates/*.yaml}"
|
||||
}
|
||||
|
||||
function lint_helm() {
|
||||
# Install via: https://github.com/helm/helm/blob/master/docs/install.md
|
||||
run_check '' helm lint --namespace=test charts/*
|
||||
}
|
||||
|
||||
function lint_all() {
|
||||
# runs all checks
|
||||
all_required=1
|
||||
lint_shell
|
||||
lint_yaml
|
||||
lint_markdown
|
||||
lint_helm
|
||||
}
|
||||
case "${1:-}" in
|
||||
lint-shell)
|
||||
lint_shell
|
||||
;;
|
||||
lint-yaml)
|
||||
lint_yaml
|
||||
;;
|
||||
lint-markdown)
|
||||
lint_markdown
|
||||
;;
|
||||
lint-helm)
|
||||
lint_helm
|
||||
;;
|
||||
lint-all)
|
||||
lint_all
|
||||
;;
|
||||
*)
|
||||
echo " $0 [command]
|
||||
Available Commands:
|
||||
lint-shell Lint shell files
|
||||
lint-yaml Lint yaml files
|
||||
lint-markdown Lint markdown files
|
||||
lint-helm Lint helm charts
|
||||
lint-all Run lint on all non-go files
|
||||
" >&2
|
||||
;;
|
||||
esac
|
@ -1,57 +0,0 @@
|
||||
#! /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...]
|
||||
# Pass empty regex when no regex is needed
|
||||
function run_check() {
|
||||
regex="$1"
|
||||
shift
|
||||
exe="$1"
|
||||
shift
|
||||
|
||||
if [ -x "$(command -v "$exe")" ]; then
|
||||
if [ -z "$regex" ]; then
|
||||
"$exe" "$@"
|
||||
else
|
||||
find . -path ./vendor -prune -o -regextype egrep -iregex "$regex" -print0 |
|
||||
xargs -0rt -n1 "$exe" "$@"
|
||||
fi
|
||||
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 --external-sources
|
||||
run_check '.*\.(ba)?sh' bash -n
|
||||
|
||||
# Install via: pip install yamllint
|
||||
# disable yamlint check for helm charts
|
||||
run_check '.*\.ya?ml' yamllint -s -d "{extends: default, rules: {line-length: {allow-non-breakable-inline-mappings: true}},ignore: charts/*/templates/*.yaml}"
|
||||
|
||||
# Install via: https://github.com/helm/helm/blob/master/docs/install.md
|
||||
run_check '' helm lint --namespace=test charts/*
|
||||
|
||||
echo "ALL OK."
|
Loading…
Reference in New Issue
Block a user