mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
ci: add 'make test' target to validate CI job scripts
This merges several files from the master branch into ci/centos so that the scripts, MarkDown and yaml files can be checked. Run 'make' or 'make test' to validate the contents of this branch. Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
47
scripts/Dockerfile.test
Normal file
47
scripts/Dockerfile.test
Normal file
@ -0,0 +1,47 @@
|
||||
# Container image for running the Ceph-CSI tests
|
||||
#
|
||||
# This container is based on Fedora so that recent versions of tools can easily
|
||||
# be installed.
|
||||
#
|
||||
# Production containers are based one ceph/ceph:latest, which use CentOS as
|
||||
# Operating System, so generated binaries and versions of dependencies may be a
|
||||
# little different.
|
||||
#
|
||||
|
||||
FROM fedora:latest
|
||||
|
||||
ARG GOLANGCI_VERSION=v1.21.0
|
||||
ARG GOSEC_VERSION=2.0.0
|
||||
ARG GOPATH=/go
|
||||
|
||||
ENV \
|
||||
GOPATH=${GOPATH} \
|
||||
GO111MODULE=on \
|
||||
PATH="${GOPATH}/bin:/opt/commitlint/node_modules/.bin:${PATH}"
|
||||
|
||||
RUN dnf -y install \
|
||||
git \
|
||||
make \
|
||||
golang \
|
||||
gcc \
|
||||
librados-devel \
|
||||
librbd-devel \
|
||||
rubygems \
|
||||
ShellCheck \
|
||||
yamllint \
|
||||
npm \
|
||||
&& dnf -y update \
|
||||
&& dnf -y clean all \
|
||||
&& gem install mdl \
|
||||
&& curl -sf "https://install.goreleaser.com/github.com/golangci/golangci-lint.sh" \
|
||||
| bash -s -- -b ${GOPATH}/bin "${GOLANGCI_VERSION}" \
|
||||
&& curl -sfL "https://raw.githubusercontent.com/securego/gosec/master/install.sh" \
|
||||
| sh -s -- -b $GOPATH/bin "${GOSEC_VERSION}" \
|
||||
&& curl -L https://git.io/get_helm.sh | bash \
|
||||
&& mkdir /opt/commitlint && pushd /opt/commitlint \
|
||||
&& npm init -y \
|
||||
&& npm install @commitlint/cli \
|
||||
&& popd \
|
||||
&& true
|
||||
|
||||
WORKDIR /go/src/github.com/ceph/ceph-csi
|
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
|
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
|
Reference in New Issue
Block a user