Skip to content

Commit 96b763a

Browse files
committed
fix: update apidiff script to install tool and set up remote repository
1 parent 23d89dc commit 96b763a

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

Diff for: .gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.idea
1+
.idea

Diff for: hack/apidiff.sh

+27-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ usage() {
2424
echo " -t <revision>: Report changes in code up to and including this revision."
2525
echo " Default is the current working tree instead of a revision."
2626
echo " -r <revision>: Report changes in code added since this revision."
27-
echo " Default is the common base of origin/master and HEAD."
27+
echo " Default is the common base of master and HEAD."
2828
exit 1
2929
}
3030

@@ -53,16 +53,39 @@ if [ "$#" -ge 1 ]; then
5353
TARGET_DIR="$1"
5454
fi
5555

56+
# Ensure LOCAL_GOBIN is an absolute path
57+
LOCAL_GOBIN="$(pwd)/_output/bin"
58+
mkdir -p "${LOCAL_GOBIN}"
59+
60+
# Add cleanup trap to remove the temporary binary directory
61+
trap 'rm -rf "${LOCAL_GOBIN}"' EXIT
62+
5663
# Check for apidiff tool, install it if not found
5764
if ! command -v "${API_DIFF_TOOL}" &> /dev/null; then
65+
GOBIN=${LOCAL_GOBIN}
5866
echo "Installing apidiff into ${GOBIN}."
59-
go install golang.org/x/exp/cmd/apidiff@latest
67+
GOBIN=${LOCAL_GOBIN} go install golang.org/x/exp/cmd/apidiff@latest
68+
# Add GOBIN to PATH
69+
export PATH=$PATH:${GOBIN}
6070
fi
6171

6272
# Fetch common base if -r is not set
6373
if [ -z "${REFERENCE_REVISION}" ]; then
64-
echo "Determining common base with origin/master..."
65-
REFERENCE_REVISION=$(git merge-base origin/master HEAD)
74+
# First try using Prow environment variables
75+
if [ -n "${PULL_BASE_SHA:-}" ] && [ -n "${PULL_PULL_SHA:-}" ]; then
76+
echo "Using Prow environment variables to determine base revision..."
77+
if ! REFERENCE_REVISION=$(git merge-base "${PULL_BASE_SHA}" "${PULL_PULL_SHA}"); then
78+
echo "Error: Failed to detect base revision using Prow environment variables." >&2
79+
exit 1
80+
fi
81+
else
82+
# Fall back to upstream/master
83+
echo "Determining common base with upstream/master..."
84+
if ! REFERENCE_REVISION=$(git merge-base upstream/master HEAD); then
85+
echo "Error: Could not determine base revision. Please set -r explicitly." >&2
86+
exit 1
87+
fi
88+
fi
6689
fi
6790

6891
# Step 1: Create a temporary directory for worktrees

0 commit comments

Comments
 (0)