bazel check: silent env for cleaner output (#1898)

* explicitly ignore pkgs for cleaner output

* do not ignore but redirect stderr

* silent env var to silent stderr

* add silent env var to vuln,lint,tf

* fix golangci silent

* Update bazel/ci/terraform.sh.in

Co-authored-by: Malte Poll <1780588+malt3@users.noreply.github.com>

* Update bazel/ci/golicenses.sh.in

Co-authored-by: Malte Poll <1780588+malt3@users.noreply.github.com>

* Update bazel/ci/govulncheck.sh.in

Co-authored-by: Malte Poll <1780588+malt3@users.noreply.github.com>

* Update bazel/ci/golangci_lint.sh.in

Co-authored-by: Malte Poll <1780588+malt3@users.noreply.github.com>

---------

Co-authored-by: Malte Poll <1780588+malt3@users.noreply.github.com>
This commit is contained in:
Adrian Stobbe 2023-06-14 13:58:21 +02:00 committed by GitHub
parent 7a1c70d7e5
commit c1f9d86cd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 170 additions and 136 deletions

View File

@ -27,22 +27,31 @@ excludeMods=(
"hack/tools" "hack/tools"
) )
echo "The following Go modules are excluded and won't be linted with golangci-lint:" check() {
for exclude in "${excludeMods[@]}"; do echo "The following Go modules are excluded and won't be linted with golangci-lint:"
for exclude in "${excludeMods[@]}"; do
for i in "${!modules[@]}"; do for i in "${!modules[@]}"; do
if [[ ${modules[i]} == "${BUILD_WORKSPACE_DIRECTORY}/${exclude}" ]]; then if [[ ${modules[i]} == "${BUILD_WORKSPACE_DIRECTORY}/${exclude}" ]]; then
echo " ${modules[i]}" echo " ${modules[i]}"
unset 'modules[i]' unset 'modules[i]'
fi fi
done done
done done
statuscode=0 statuscode=0
echo "Linting the following Go modules with golangci-lint:" echo "Linting the following Go modules with golangci-lint:"
for mod in "${modules[@]}"; do for mod in "${modules[@]}"; do
echo " ${mod}" echo " ${mod}"
PATH="$(dirname "${go}"):${PATH}" GOROOT=$(${go} env GOROOT) GOPATH=$(${go} env GOPATH) GOCACHE=$(${go} env GOCACHE) CGO_ENABLED=0 ${golangcilint} run --timeout=15m "${mod}/..." || statuscode=$? PATH="$(dirname "${go}"):${PATH}" GOROOT=$(${go} env GOROOT) GOPATH=$(${go} env GOPATH) GOCACHE=$(${go} env GOCACHE) CGO_ENABLED=0 ${golangcilint} run --timeout=15m "${mod}/..." >&2
done statuscode=$?
done
exit "${statuscode}" exit "${statuscode}"
}
if test -v SILENT; then
check > /dev/null
else
check
fi

View File

@ -27,15 +27,12 @@ not_allowed() {
err=1 err=1
} }
${go} mod download license_report() {
PATH="$(dirname "${go}"):${PATH}" \
err=0 GOROOT=$(${go} env GOROOT) \
GOPATH=$(${go} env GOPATH) \
PATH="$(dirname "${go}"):${PATH}" \ GOCACHE=$(${go} env GOCACHE) \
GOROOT=$(${go} env GOROOT) \ ${golicenses} report ./... | {
GOPATH=$(${go} env GOPATH) \
GOCACHE=$(${go} env GOCACHE) \
${golicenses} csv ./... | {
while read -r line; do while read -r line; do
pkg=${line%%,*} pkg=${line%%,*}
@ -88,4 +85,15 @@ GOCACHE=$(${go} env GOCACHE) \
done done
exit "${err}" exit "${err}"
}
} }
${go} mod download
err=0
if test -v SILENT; then
license_report 2> /dev/null
else
license_report
fi

View File

@ -24,10 +24,11 @@ submodules=$(${go} list -f '{{.Dir}}' -m)
PATH=$(dirname "${go}"):${PATH} PATH=$(dirname "${go}"):${PATH}
err=0 check() {
err=0
echo "Scanning Go vulnerability DB for knwon vulnerabilities in modules:" echo "Scanning Go vulnerability DB for knwon vulnerabilities in modules:"
for mod in ${submodules}; do for mod in ${submodules}; do
echo " ${mod}" echo " ${mod}"
echo -n " " echo -n " "
CGO_ENABLED=0 ${govulncheck} "${mod}/..." | CGO_ENABLED=0 ${govulncheck} "${mod}/..." |
@ -36,6 +37,14 @@ for mod in ${submodules}; do
sed s/" your code and"// && sed s/" your code and"// &&
printf "\n" || printf "\n" ||
err=$? err=$?
done done
exit "${err}" exit "${err}"
}
if test -v SILENT; then
check > /dev/null
else
check
fi

View File

@ -39,18 +39,19 @@ excludeDirs=(
"build" "build"
) )
echo "The following Terraform modules are excluded and won't be tidied:" check() {
for exclude in "${excludeDirs[@]}"; do echo "The following Terraform modules are excluded and won't be tidied:"
for exclude in "${excludeDirs[@]}"; do
for i in "${!terraformModules[@]}"; do for i in "${!terraformModules[@]}"; do
if [[ ${terraformModules[i]} == "${BUILD_WORKSPACE_DIRECTORY}/${exclude}"* ]]; then if [[ ${terraformModules[i]} == "${BUILD_WORKSPACE_DIRECTORY}/${exclude}"* ]]; then
echo " ${terraformModules[i]}" echo " ${terraformModules[i]}"
unset 'terraformModules[i]' unset 'terraformModules[i]'
fi fi
done done
done done
case ${mode} in case ${mode} in
"check") "check")
echo "Checking validity and format of the following Terraform modules:" echo "Checking validity and format of the following Terraform modules:"
for script in "${terraformModules[@]}"; do for script in "${terraformModules[@]}"; do
echo " ${script}" echo " ${script}"
@ -64,7 +65,7 @@ case ${mode} in
done done
;; ;;
"format") "format")
echo "Formatting the following Terraform modules:" echo "Formatting the following Terraform modules:"
for module in "${terraformModules[@]}"; do for module in "${terraformModules[@]}"; do
echo " ${module}" echo " ${module}"
@ -72,7 +73,7 @@ case ${mode} in
done done
;; ;;
"generate") "generate")
echo "Formatting and generating lock files for the following Terraform modules:" echo "Formatting and generating lock files for the following Terraform modules:"
for script in "${terraformModules[@]}"; do for script in "${terraformModules[@]}"; do
echo " ${script}" echo " ${script}"
@ -89,8 +90,15 @@ case ${mode} in
done done
;; ;;
*) *)
echo "Error: unknown mode \"${mode}\"" echo "Error: unknown mode \"${mode}\""
exit 1 exit 1
;; ;;
esac esac
}
if test -v SILENT; then
check > /dev/null
else
check
fi