From 287b0a022351ec1ef82850f7fd77babdc0ac1a65 Mon Sep 17 00:00:00 2001 From: Camila Macedo <7708031+camilamacedo86@users.noreply.github.com> Date: Fri, 10 Jan 2025 20:42:23 +0000 Subject: [PATCH] Add Sanity Check To prevent the scenario Add a check to be called in the verify where we can add adtional sanity checks to ensure the qiality of the project --- Makefile | 1 + hack/ci/sanity.sh | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100755 hack/ci/sanity.sh 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..02d379baf --- /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