Skip to content

Commit 5122c21

Browse files
authored
Merge pull request #1519 from justinsb/apidiff_foucsed
chore: make apidiff focus on our APIs
2 parents 4f90210 + 1bc3266 commit 5122c21

File tree

3 files changed

+46
-21
lines changed

3 files changed

+46
-21
lines changed

Makefile

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,6 @@ SETUP_ENVTEST_VER := v0.0.0-20240522175850-2e9781e9fc60
103103
SETUP_ENVTEST_BIN := setup-envtest
104104
SETUP_ENVTEST := $(TOOLS_BIN_DIR)/$(SETUP_ENVTEST_BIN)
105105

106-
GO_APIDIFF_VER := v0.8.3
107-
GO_APIDIFF_BIN := go-apidiff
108-
GO_APIDIFF := $(TOOLS_BIN_DIR)/$(GO_APIDIFF_BIN)
109-
110106
GOTESTSUM_VER := v1.6.4
111107
GOTESTSUM_BIN := gotestsum
112108
GOTESTSUM := $(TOOLS_BIN_DIR)/$(GOTESTSUM_BIN)
@@ -260,9 +256,6 @@ $(CONVERSION_GEN): ## Build conversion-gen.
260256
$(RELEASE_NOTES): ## Build release notes.
261257
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) k8s.io/release/cmd/release-notes $(RELEASE_NOTES_BIN) $(RELEASE_NOTES_VER)
262258

263-
$(GO_APIDIFF): ## Build go-apidiff from tools folder.
264-
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) github.com/joelanford/go-apidiff $(GO_APIDIFF_BIN) $(GO_APIDIFF_VER)
265-
266259
$(CONVERSION_VERIFIER): go.mod
267260
cd $(TOOLS_DIR); go build -tags=tools -o $@ sigs.k8s.io/cluster-api/hack/tools/conversion-verifier
268261

@@ -282,9 +275,6 @@ $(KIND): ## Build kind into tools folder
282275
.PHONY: $(KUBECTL_BIN)
283276
$(KUBECTL_BIN): $(KUBECTL) ## Building kubectl from tools folder
284277

285-
.PHONY: $(GO_APIDIFF_BIN)
286-
$(GO_APIDIFF_BIN): $(GO_APIDIFF)
287-
288278
.PHONY: $(KIND_BIN)
289279
$(KIND_BIN): $(KIND) ## Building Kind from tools folder
290280

@@ -576,13 +566,10 @@ clean-release: ## Remove the release folder
576566
rm -rf $(RELEASE_DIR)
577567

578568
.PHONY: apidiff
579-
apidiff: $(GO_APIDIFF) ## Check for API differences.
569+
apidiff: APIDIFF_OLD_COMMIT ?= $(shell git rev-parse origin/main)
570+
apidiff: $(GO_APIDIFF) ## Check for API differences
580571
@$(call checkdiff) > /dev/null
581-
@if ($(call checkdiff) | grep "api/"); then \
582-
$(GO_APIDIFF) $(shell git rev-parse origin/main) --print-compatible; \
583-
else \
584-
echo "No changes to 'api/'. Nothing to do."; \
585-
fi
572+
APIDIFF_OLD_COMMIT="$(APIDIFF_OLD_COMMIT)" hack/verify-apidiff
586573

587574
define checkdiff
588575
git --no-pager diff --name-only FETCH_HEAD

hack/verify-apidiff

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2025 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
21+
REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
22+
cd "${REPO_ROOT}"
23+
24+
if [[ -z "${APIDIFF_OLD_COMMIT:-}" ]]; then
25+
APIDIFF_OLD_COMMIT=$(git rev-parse origin/main)
26+
fi
27+
28+
29+
echo "*** Running go-apidiff ***"
30+
31+
# Run go-apidiff and filter for changes in api/ or exp/api/
32+
apidiffs=$(go run github.com/joelanford/[email protected] ${APIDIFF_OLD_COMMIT} || true)
33+
filtered=$(echo "$apidiffs" | grep -E 'cluster-api-provider-gcp/(api/|exp/api/)' || true)
34+
35+
if [[ -n "$filtered" ]]; then
36+
echo "API differences found in api/ or exp/api/:"
37+
echo "$apidiffs"
38+
exit 1
39+
else
40+
echo "No differences found in api/ or exp/api/ packages"
41+
fi

scripts/ci-apidiff.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ set -o pipefail
2020

2121
REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
2222

23-
APIDIFF="${REPO_ROOT}/hack/tools/bin/go-apidiff"
23+
cd "${REPO_ROOT}"
2424

25-
cd "${REPO_ROOT}" && make "${APIDIFF##*/}"
26-
echo "*** Running go-apidiff ***"
27-
28-
${APIDIFF} "${PULL_BASE_SHA}" --print-compatible
25+
APIDIFF_OLD_COMMIT="${PULL_BASE_SHA}" make apidiff

0 commit comments

Comments
 (0)