From 679195d8cc56e7f6ed4f75cde13ce484f452c996 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Thu, 25 Apr 2024 09:04:32 +0200 Subject: [PATCH] hack/apidiff.sh: handle lack of origin The script failed in the Prow job with: fatal: Not a valid object name origin/master That came from "git merge-base origin/master HEAD", which isn't needed because the Prow job intentionally sets -r explicitly. Now the fallback is only tried if needed. While at it, the informational messages get enhanced. --- hack/apidiff.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/hack/apidiff.sh b/hack/apidiff.sh index 4f949b3c755..504937480b7 100755 --- a/hack/apidiff.sh +++ b/hack/apidiff.sh @@ -36,7 +36,7 @@ set -o pipefail KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. source "${KUBE_ROOT}/hack/lib/init.sh" -base="$(git merge-base origin/master HEAD)" +base= while getopts "r:" o; do case "${o}" in r) @@ -72,18 +72,30 @@ if [ ${#targets[@]} -eq 0 ]; then ) fi +# Default if -r was not given. +if [ -z "${base}" ]; then + if ! base="$(git merge-base origin/master HEAD)"; then + echo >&2 "Could not determine default base revision. -r must be used explicitly." + exit 1 + fi +fi + # Must be a something that git can resolve to a commit. # "git rev-parse --verify" checks that and prints a detailed # error. base="$(git rev-parse --verify "$base")" +# Give some information about what's happening. Failures from "git describe" are ignored +# silently, that's optional information. +echo "Checking for API changes since ${base}$(if descr=$(git describe --tags "${base}" 2>/dev/null); then echo " = ${descr}"; fi)." + kube::golang::setup_env kube::util::ensure-temp-dir # Install apidiff and make sure it's found. export GOBIN="${KUBE_TEMP}" PATH="${GOBIN}:${PATH}" -echo "installing apidiff into ${GOBIN}" +echo "Installing apidiff into ${GOBIN}." go install golang.org/x/exp/cmd/apidiff@latest cd "${KUBE_ROOT}"