Skip to content

Commit ea41264

Browse files
Add a Makefile target and start running the API diff linter as part of CI.
1 parent 6601b29 commit ea41264

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ help-extended: #HELP Display extended help.
118118
#SECTION Development
119119

120120
.PHONY: lint
121-
lint: lint-custom $(GOLANGCI_LINT) #HELP Run golangci linter.
121+
lint: lint-custom lint-api-diff $(GOLANGCI_LINT) #HELP Run golangci linter.
122122
$(GOLANGCI_LINT) run --build-tags $(GO_BUILD_TAGS) $(GOLANGCI_LINT_ARGS)
123123

124124
.PHONY: lint-helm
@@ -149,6 +149,10 @@ custom-linter-build: #EXHELP Build custom linter
149149
lint-custom: custom-linter-build #EXHELP Call custom linter for the project
150150
go vet -tags=$(GO_BUILD_TAGS) -vettool=./bin/custom-linter ./...
151151

152+
.PHONY: lint-api-diff
153+
lint-api-diff: $(GOLANGCI_LINT) #HELP Validate API changes using kube-api-linter with diff-aware analysis
154+
bash hack/api-lint-diff/run.sh
155+
152156
.PHONY: k8s-pin
153157
k8s-pin: #EXHELP Pin k8s staging modules based on k8s.io/kubernetes version (in go.mod or from K8S_IO_K8S_VERSION env var) and run go mod tidy.
154158
K8S_IO_K8S_VERSION='$(K8S_IO_K8S_VERSION)' go run hack/tools/k8smaintainer/main.go
@@ -198,7 +202,7 @@ generate: $(CONTROLLER_GEN) #EXHELP Generate code containing DeepCopy, DeepCopyI
198202
$(CONTROLLER_GEN) --load-build-tags=$(GO_BUILD_TAGS) object:headerFile="hack/boilerplate.go.txt" paths="./..."
199203

200204
.PHONY: verify
201-
verify: k8s-pin kind-verify-versions fmt generate manifests update-tls-profiles crd-ref-docs verify-bingo #HELP Verify all generated code is up-to-date. Runs k8s-pin instead of just tidy.
205+
verify: k8s-pin kind-verify-versions fmt generate manifests update-tls-profiles crd-ref-docs verify-bingo lint-api-diff #HELP Verify all generated code is up-to-date. Runs k8s-pin instead of just tidy.
202206
git diff --exit-code
203207

204208
.PHONY: verify-bingo

hack/api-lint-diff/run.sh

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,31 @@ check_linter_support() {
196196

197197
# Find golangci-lint binary
198198
find_golangci_lint() {
199-
# Check for custom build first
199+
# Check if Variables.mk exists and extract golangci-lint path
200+
if [[ -f ".bingo/Variables.mk" ]]; then
201+
# Extract the full path from GOLANGCI_LINT := $(GOBIN)/golangci-lint-v2.7.2
202+
local gobin
203+
gobin=$(grep '^GOBIN' .bingo/Variables.mk | head -1 | sed -E 's/^GOBIN[[:space:]]*:?=[[:space:]]*//' | sed 's/\$([^)]*)//' | xargs)
204+
205+
# If GOBIN is not found, use default
206+
if [[ -z "${gobin}" ]]; then
207+
gobin=$(go env GOPATH | cut -d: -f1)/bin
208+
fi
209+
210+
# Extract version from GOLANGCI_LINT variable
211+
local version
212+
version=$(grep '^GOLANGCI_LINT' .bingo/Variables.mk | sed -E 's/.*golangci-lint-(v[0-9.]+).*/\1/')
213+
214+
if [[ -n "${version}" ]]; then
215+
local bingo_path="${gobin}/golangci-lint-${version}"
216+
if [[ -f "${bingo_path}" ]]; then
217+
echo "${bingo_path}"
218+
return 0
219+
fi
220+
fi
221+
fi
222+
223+
# Check for custom build
200224
if [[ -f ".bingo/golangci-lint" ]]; then
201225
echo ".bingo/golangci-lint"
202226
return 0
@@ -216,6 +240,7 @@ find_golangci_lint() {
216240

217241
echo -e "${RED}Error: golangci-lint not found.${NC}" >&2
218242
echo -e "${RED}Searched for:${NC}" >&2
243+
echo -e " - .bingo/Variables.mk (bingo-managed versioned binary)" >&2
219244
echo -e " - .bingo/golangci-lint" >&2
220245
echo -e " - bin/golangci-lint" >&2
221246
echo -e " - golangci-lint on your \$PATH" >&2

0 commit comments

Comments
 (0)