diff --git a/Makefile b/Makefile index 4d2209a72..ce7571f92 100644 --- a/Makefile +++ b/Makefile @@ -119,6 +119,7 @@ generate: $(CONTROLLER_GEN) #EXHELP Generate code containing DeepCopy, DeepCopyI .PHONY: verify verify: tidy fmt vet generate manifests crd-ref-docs #HELP Verify all generated code is up-to-date. git diff --exit-code + ./hack/ci/sanity.sh .PHONY: fix-lint fix-lint: $(GOLANGCI_LINT) #EXHELP Fix lint issues diff --git a/hack/ci/sanity.sh b/hack/ci/sanity.sh new file mode 100755 index 000000000..8ecf70456 --- /dev/null +++ b/hack/ci/sanity.sh @@ -0,0 +1,25 @@ +#################################################### +# The purpose of this script is allow us to do sanity +# checks to ensure the quality of the code +#################################################### + +#!/bin/bash + +set -e + +echo_error() { + echo "[Sanity Check Fail]: $1" +} + +# Criteria 1: Do not use setupLog.Error(nil, ...) +CRITERIA1_RULE="setupLog\.Error\(nil," +CRITERIA1_MSG="Avoid using 'setupLog.Error(nil, ...)'. Instead, use 'errors.New()' or 'fmt.Errorf()' \ +to ensure logs are created. Using 'nil' for errors can result in silent failures, making bugs harder to detect." + +if grep -r --include="*.go" "$CRITERIA1_RULE" .; then + echo_error "$CRITERIA1_MSG" + exit 1 +fi + +echo "Sanity checks passed with success." +exit 0 \ No newline at end of file