Skip to content

Commit dfdc8a2

Browse files
Add apidiff target (#790)
Signed-off-by: Prajyot-Parab <[email protected]>
1 parent 4d9e911 commit dfdc8a2

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
3131
GO_INSTALL = ./scripts/go_install.sh
3232
E2E_CONF_FILE_ENVSUBST := $(REPO_ROOT)/test/e2e/config/ibmcloud-e2e-envsubst.yaml
3333

34+
GO_APIDIFF := $(TOOLS_BIN_DIR)/go-apidiff
3435
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/golangci-lint
3536
KUSTOMIZE := $(TOOLS_BIN_DIR)/kustomize
3637
GOJQ := $(TOOLS_BIN_DIR)/gojq
@@ -405,6 +406,20 @@ lint: $(GOLANGCI_LINT) ## Lint codebase
405406
lint-fix: $(GOLANGCI_LINT) ## Lint the codebase and run auto-fixers if supported by the linter
406407
GOLANGCI_LINT_EXTRA_ARGS=--fix $(MAKE) lint
407408

409+
APIDIFF_OLD_COMMIT ?= $(shell git rev-parse origin/main)
410+
411+
.PHONY: apidiff
412+
apidiff: $(GO_APIDIFF) ## Check for API differences.
413+
@if ($(call checkdiff) | grep "api/"); then \
414+
$(GO_APIDIFF) $(APIDIFF_OLD_COMMIT) --print-compatible; \
415+
else \
416+
echo "No changes to 'api/'. Nothing to do."; \
417+
fi
418+
419+
define checkdiff
420+
git --no-pager diff --name-only FETCH_HEAD
421+
endef
422+
408423
ALL_VERIFY_CHECKS = doctoc boilerplate shellcheck modules gen manifests conversions #tiltfile
409424

410425
.PHONY: verify

hack/tools/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ help: # Display this help
5252

5353
##@ hack/tools:
5454

55+
GO_APIDIFF := $(BIN_DIR)/go-apidiff
56+
$(GO_APIDIFF): $(BIN_DIR) go.mod go.sum ## Build a local copy of go-apidiff.
57+
go build -tags=tools -o $@ github.com/joelanford/go-apidiff
58+
5559
GOLANGCI_LINT := $(BIN_DIR)/golangci-lint
5660
$(GOLANGCI_LINT): $(BIN_DIR) go.mod go.sum ## Build a local copy of golangci-lint.
5761
go build -tags=tools -o $@ github.com/golangci/golangci-lint/cmd/golangci-lint

scripts/ci-apidiff.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
# Copyright 2022 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+
# shellcheck source=../hack/ensure-go.sh
23+
source "${REPO_ROOT}/hack/ensure-go.sh"
24+
25+
cd "${REPO_ROOT}" && APIDIFF_OLD_COMMIT="${PULL_BASE_SHA}" make apidiff

0 commit comments

Comments
 (0)