Skip to content

Commit 27f6d94

Browse files
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
1 parent 3f56eba commit 27f6d94

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ generate: $(CONTROLLER_GEN) #EXHELP Generate code containing DeepCopy, DeepCopyI
119119
.PHONY: verify
120120
verify: tidy fmt vet generate manifests crd-ref-docs #HELP Verify all generated code is up-to-date.
121121
git diff --exit-code
122+
./hack/ci/sanity.sh
122123

123124
.PHONY: fix-lint
124125
fix-lint: $(GOLANGCI_LINT) #EXHELP Fix lint issues

hack/ci/sanity.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
####################################################
2+
# The purpose of this script is allow us to do sanity
3+
# checks to ensure the quality of the code
4+
####################################################
5+
6+
#!/bin/bash
7+
8+
set -e
9+
10+
echo_error() {
11+
echo "[Sanity Check Fail]: $1"
12+
}
13+
14+
# Criteria 1: Do not use setupLog.Error(nil, ...)
15+
CRITERIA1_RULE="setupLog\.Error\(nil,"
16+
CRITERIA1_MSG="Avoid using 'setupLog.Error(nil, ...)'. Instead, use 'errors.New()' or 'fmt.Errorf()' \
17+
to ensure logs are created. Using 'nil' for errors can result in silent failures, making bugs harder to detect."
18+
19+
if grep -r --include="*.go" "$CRITERIA1_RULE" .; then
20+
echo_error "$CRITERIA1_MSG"
21+
exit 1
22+
fi
23+
24+
echo "Sanity checks passed with success."
25+
exit 0

0 commit comments

Comments
 (0)