Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 3 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ SETUP_ENVTEST_VER := v0.0.0-20240522175850-2e9781e9fc60
SETUP_ENVTEST_BIN := setup-envtest
SETUP_ENVTEST := $(TOOLS_BIN_DIR)/$(SETUP_ENVTEST_BIN)

GO_APIDIFF_VER := v0.8.3
GO_APIDIFF_BIN := go-apidiff
GO_APIDIFF := $(TOOLS_BIN_DIR)/$(GO_APIDIFF_BIN)

GOTESTSUM_VER := v1.6.4
GOTESTSUM_BIN := gotestsum
GOTESTSUM := $(TOOLS_BIN_DIR)/$(GOTESTSUM_BIN)
Expand Down Expand Up @@ -260,9 +256,6 @@ $(CONVERSION_GEN): ## Build conversion-gen.
$(RELEASE_NOTES): ## Build release notes.
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) k8s.io/release/cmd/release-notes $(RELEASE_NOTES_BIN) $(RELEASE_NOTES_VER)

$(GO_APIDIFF): ## Build go-apidiff from tools folder.
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) github.com/joelanford/go-apidiff $(GO_APIDIFF_BIN) $(GO_APIDIFF_VER)

$(CONVERSION_VERIFIER): go.mod
cd $(TOOLS_DIR); go build -tags=tools -o $@ sigs.k8s.io/cluster-api/hack/tools/conversion-verifier

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

.PHONY: $(GO_APIDIFF_BIN)
$(GO_APIDIFF_BIN): $(GO_APIDIFF)

.PHONY: $(KIND_BIN)
$(KIND_BIN): $(KIND) ## Building Kind from tools folder

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

.PHONY: apidiff
apidiff: $(GO_APIDIFF) ## Check for API differences.
apidiff: APIDIFF_OLD_COMMIT ?= $(shell git rev-parse origin/main)
apidiff: $(GO_APIDIFF) ## Check for API differences
@$(call checkdiff) > /dev/null
@if ($(call checkdiff) | grep "api/"); then \
$(GO_APIDIFF) $(shell git rev-parse origin/main) --print-compatible; \
else \
echo "No changes to 'api/'. Nothing to do."; \
fi
APIDIFF_OLD_COMMIT="$(APIDIFF_OLD_COMMIT)" hack/verify-apidiff

define checkdiff
git --no-pager diff --name-only FETCH_HEAD
Expand Down
41 changes: 41 additions & 0 deletions hack/verify-apidiff
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash

# Copyright 2025 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

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

if [[ -z "${APIDIFF_OLD_COMMIT:-}" ]]; then
APIDIFF_OLD_COMMIT=$(git rev-parse origin/main)
fi


echo "*** Running go-apidiff ***"

# Run go-apidiff and filter for changes in api/ or exp/api/
apidiffs=$(go run github.com/joelanford/[email protected] ${APIDIFF_OLD_COMMIT} || true)
filtered=$(echo "$apidiffs" | grep -E 'cluster-api-provider-gcp/(api/|exp/api/)' || true)

if [[ -n "$filtered" ]]; then
echo "API differences found in api/ or exp/api/:"
echo "$apidiffs"
exit 1
else
echo "No differences found in api/ or exp/api/ packages"
fi
7 changes: 2 additions & 5 deletions scripts/ci-apidiff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ set -o pipefail

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

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

cd "${REPO_ROOT}" && make "${APIDIFF##*/}"
echo "*** Running go-apidiff ***"

${APIDIFF} "${PULL_BASE_SHA}" --print-compatible
APIDIFF_OLD_COMMIT="${PULL_BASE_SHA}" make apidiff