Skip to content

Commit a763448

Browse files
authored
Merge pull request kubernetes#129188 from BenTheElder/apidiff-prow
apidiff: default from prowjob env if available, default before doing anything else
2 parents 1a1f522 + 8fce9b0 commit a763448

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

hack/apidiff.sh

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,33 @@ while getopts "r:t:b:" o; do
7979
done
8080
shift $((OPTIND - 1))
8181

82+
# default from prow env if unset from args
83+
# https://docs.prow.k8s.io/docs/jobs/#job-environment-variables
84+
# TODO: handle batch PR testing
85+
86+
if [[ -z "${target:-}" && -n "${PULL_PULL_SHA:-}" ]]; then
87+
target="${PULL_PULL_SHA}"
88+
fi
89+
# target must be a something that git can resolve to a commit.
90+
# "git rev-parse --verify" checks that and prints a detailed
91+
# error.
92+
if [[ -n "${target}" ]]; then
93+
target="$(git rev-parse --verify "${target}")"
94+
fi
95+
96+
if [[ -z "${base}" && -n "${PULL_BASE_SHA:-}" && -n "${PULL_PULL_SHA:-}" ]]; then
97+
if ! base="$(git merge-base "${PULL_BASE_SHA}" "${PULL_PULL_SHA}")"; then
98+
echo >&2 "Failed to detect base revision correctly with prow environment variables."
99+
exit 1
100+
fi
101+
elif [[ -z "${base}" ]]; then
102+
if ! base="$(git merge-base origin/master "${target:-HEAD}")"; then
103+
echo >&2 "Could not determine default base revision. -r must be used explicitly."
104+
exit 1
105+
fi
106+
fi
107+
base="$(git rev-parse --verify "${base}")"
108+
82109
# Check specific directory or everything.
83110
targets=("$@")
84111
if [ ${#targets[@]} -eq 0 ]; then
@@ -93,22 +120,6 @@ if [ ${#targets[@]} -eq 0 ]; then
93120
done
94121
fi
95122

96-
# Must be a something that git can resolve to a commit.
97-
# "git rev-parse --verify" checks that and prints a detailed
98-
# error.
99-
if [ -n "${target}" ]; then
100-
target="$(git rev-parse --verify "${target}")"
101-
fi
102-
103-
# Determine defaults.
104-
if [ -z "${base}" ]; then
105-
if ! base="$(git merge-base origin/master "${target:-HEAD}")"; then
106-
echo >&2 "Could not determine default base revision. -r must be used explicitly."
107-
exit 1
108-
fi
109-
fi
110-
base="$(git rev-parse --verify "${base}")"
111-
112123
# Give some information about what's happening. Failures from "git describe" are ignored
113124
# silently, that's optional information.
114125
describe () {

0 commit comments

Comments
 (0)