Automatically determine remote upstream name.

Also add option to force Godeps verification checks on post-commit
Jenkins.
This commit is contained in:
Jeff Grafton 2016-03-09 15:47:16 -08:00
parent 4242fd2ee1
commit 59a91326fa
4 changed files with 37 additions and 18 deletions

View File

@ -9,6 +9,7 @@
builders:
- shell: 'bash <(curl -fsS --retry 3 "https://raw.githubusercontent.com/kubernetes/kubernetes/master/hack/jenkins/upload-started.sh")'
- shell: |
export KUBE_FORCE_VERIFY_CHECKS='y'
export KUBE_VERIFY_GIT_BRANCH='{branch}'
timeout -k {kill-timeout}m {timeout}m ./hack/jenkins/gotest-dockerized.sh && rc=$? || rc=$?
{report-rc}

View File

@ -312,4 +312,33 @@ kube::util::gv-to-swagger-name() {
esac
}
# Returns the name of the upstream remote repository name for the local git
# repo, e.g. "upstream" or "origin".
kube::util::git_upstream_remote_name() {
git remote -v | grep fetch |\
grep -E 'github.com/kubernetes/kubernetes|k8s.io/kubernetes' |\
head -n 1 | awk '{print $1}'
}
# Checks whether there are any files matching pattern $2 changed between the
# current branch and upstream branch named by $1.
# Returns 1 (false) if there are no changes, 0 (true) if there are changes
# detected.
kube::util::has_changes_against_upstream_branch() {
local -r git_branch=$1
local -r pattern=$2
readonly full_branch="$(kube::util::git_upstream_remote_name)/${git_branch}"
echo "Checking for '${pattern}' changes against '${full_branch}'"
# make sure the branch is valid, otherwise the check will pass erroneously.
if ! git describe "${full_branch}" >/dev/null; then
exit 1
fi
# notice this uses ... to find the first shared ancestor
if ! git diff --name-only "${full_branch}...HEAD" | grep "${pattern}" > /dev/null; then
echo "No '${pattern}' changes detected."
return 1
fi
}
# ex: ts=2 sw=2 et filetype=sh

View File

@ -19,16 +19,11 @@ set -o nounset
set -o pipefail
KUBE_ROOT="$(cd "$(dirname "${BASH_SOURCE}")/.." && pwd -P)"
source "${KUBE_ROOT}/hack/lib/init.sh"
readonly branch="origin/${1:-${KUBE_VERIFY_GIT_BRANCH:-master}}"
echo "Checking for Godeps changes against ${branch}"
# make sure the branch is valid, otherwise the next check will pass erroneously.
if ! git describe "${branch}" >/dev/null; then
exit 1
fi
# notice this uses ... to find the first shared ancestor
if ! git diff --name-only "${branch}...HEAD" | grep 'Godeps/' > /dev/null; then
echo "No Godeps changes detected."
readonly branch=${1:-${KUBE_VERIFY_GIT_BRANCH:-master}}
if ! [[ ${KUBE_FORCE_VERIFY_CHECKS:-} =~ ^[yY]$ ]] && \
! kube::util::has_changes_against_upstream_branch "${branch}" 'Godeps/'; then
exit 0
fi

View File

@ -39,15 +39,9 @@ preload-dep() {
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${KUBE_ROOT}/hack/lib/init.sh"
readonly branch="origin/${1:-${KUBE_VERIFY_GIT_BRANCH:-master}}"
echo "Checking for Godeps changes against ${branch}"
# make sure the branch is valid, otherwise the next check will pass erroneously.
if ! git describe "${branch}" >/dev/null; then
exit 1
fi
# notice this uses ... to find the first shared ancestor
if ! git diff --name-only "${branch}...HEAD" | grep 'Godeps/' > /dev/null; then
echo "No Godeps changes detected."
readonly branch=${1:-${KUBE_VERIFY_GIT_BRANCH:-master}}
if ! [[ ${KUBE_FORCE_VERIFY_CHECKS:-} =~ ^[yY]$ ]] && \
! kube::util::has_changes_against_upstream_branch "${branch}" 'Godeps/'; then
exit 0
fi