Skip to content

Commit

Permalink
Add Sanity Check To prevent the scenario
Browse files Browse the repository at this point in the history
Add a check to be called in the verify where we can add adtional
sanity checks to ensure the qiality of the project
  • Loading branch information
camilamacedo86 committed Jan 10, 2025
1 parent 3f56eba commit 27f6d94
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions hack/ci/sanity.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 27f6d94

Please sign in to comment.