mirror of https://github.com/k3s-io/k3s
Diff between PULL_BASE_SHA and HEAD when detecting file changes from
Prowpull/564/head
parent
bfa5876311
commit
d6801b8211
|
@ -496,25 +496,42 @@ kube::util::ensure_single_dir_gopath() {
|
|||
fi
|
||||
}
|
||||
|
||||
# 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() {
|
||||
# Find the base commit using:
|
||||
# $PULL_BASE_SHA if set (from Prow)
|
||||
# current ref from the remote upstream branch
|
||||
kube::util::base_ref() {
|
||||
local -r git_branch=$1
|
||||
local -r pattern=$2
|
||||
local -r not_pattern=${3:-totallyimpossiblepattern}
|
||||
local full_branch
|
||||
|
||||
if [[ -n ${PULL_BASE_SHA:-} ]]; then
|
||||
echo "${PULL_BASE_SHA}"
|
||||
return
|
||||
fi
|
||||
|
||||
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
|
||||
# abort!
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "${full_branch}"
|
||||
}
|
||||
|
||||
# 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() {
|
||||
local -r git_branch=$1
|
||||
local -r pattern=$2
|
||||
local -r not_pattern=${3:-totallyimpossiblepattern}
|
||||
|
||||
local base_ref=$(kube::util::base_ref "${git_branch}")
|
||||
echo "Checking for '${pattern}' changes against '${base_ref}'"
|
||||
|
||||
# notice this uses ... to find the first shared ancestor
|
||||
if git diff --name-only "${full_branch}...HEAD" | grep -v -E "${not_pattern}" | grep "${pattern}" > /dev/null; then
|
||||
if git diff --name-only "${base_ref}...HEAD" | grep -v -E "${not_pattern}" | grep "${pattern}" > /dev/null; then
|
||||
return 0
|
||||
fi
|
||||
# also check for pending changes
|
||||
|
|
|
@ -23,8 +23,8 @@ source "${KUBE_ROOT}/hack/lib/init.sh"
|
|||
|
||||
readonly branch=${1:-${KUBE_VERIFY_GIT_BRANCH:-master}}
|
||||
if ! [[ ${KUBE_FORCE_VERIFY_CHECKS:-} =~ ^[yY]$ ]] && \
|
||||
! kube::util::has_changes_against_upstream_branch "${branch}" 'Godeps/' && \
|
||||
! kube::util::has_changes_against_upstream_branch "${branch}" 'vendor/'; then
|
||||
! kube::util::has_changes "${branch}" 'Godeps/' && \
|
||||
! kube::util::has_changes "${branch}" 'vendor/'; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
|
|
@ -23,10 +23,10 @@ source "${KUBE_ROOT}/hack/lib/init.sh"
|
|||
|
||||
readonly branch=${1:-${KUBE_VERIFY_GIT_BRANCH:-master}}
|
||||
if ! [[ ${KUBE_FORCE_VERIFY_CHECKS:-} =~ ^[yY]$ ]] && \
|
||||
! kube::util::has_changes_against_upstream_branch "${branch}" 'Godeps/' && \
|
||||
! kube::util::has_changes_against_upstream_branch "${branch}" 'vendor/' && \
|
||||
! kube::util::has_changes_against_upstream_branch "${branch}" 'hack/lib/' && \
|
||||
! kube::util::has_changes_against_upstream_branch "${branch}" 'hack/.*godep'; then
|
||||
! kube::util::has_changes "${branch}" 'Godeps/' && \
|
||||
! kube::util::has_changes "${branch}" 'vendor/' && \
|
||||
! kube::util::has_changes "${branch}" 'hack/lib/' && \
|
||||
! kube::util::has_changes "${branch}" 'hack/.*godep'; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ find_files() {
|
|||
IFS=$'\n'
|
||||
conflicts=($(find_files | sed 's|/.readonly||' | while read dir; do
|
||||
dir=${dir#./}
|
||||
if kube::util::has_changes_against_upstream_branch "${branch}" "^${dir}/[^/]*\$" '/\.readonly$|/BUILD$|/zz_generated|/\.generated\.|\.proto$|\.pb\.go$' >/dev/null; then
|
||||
if kube::util::has_changes "${branch}" "^${dir}/[^/]*\$" '/\.readonly$|/BUILD$|/zz_generated|/\.generated\.|\.proto$|\.pb\.go$' >/dev/null; then
|
||||
echo "${dir}"
|
||||
fi
|
||||
done))
|
||||
|
|
|
@ -23,12 +23,12 @@ source "${KUBE_ROOT}/hack/lib/init.sh"
|
|||
|
||||
readonly branch=${1:-${KUBE_VERIFY_GIT_BRANCH:-master}}
|
||||
if ! [[ ${KUBE_FORCE_VERIFY_CHECKS:-} =~ ^[yY]$ ]] && \
|
||||
! kube::util::has_changes_against_upstream_branch "${branch}" 'staging/' && \
|
||||
! kube::util::has_changes_against_upstream_branch "${branch}" 'build/' && \
|
||||
! kube::util::has_changes_against_upstream_branch "${branch}" 'Godeps/' && \
|
||||
! kube::util::has_changes_against_upstream_branch "${branch}" 'vendor/' && \
|
||||
! kube::util::has_changes_against_upstream_branch "${branch}" 'hack/lib/' && \
|
||||
! kube::util::has_changes_against_upstream_branch "${branch}" 'hack/.*godep'; then
|
||||
! kube::util::has_changes "${branch}" 'staging/' && \
|
||||
! kube::util::has_changes "${branch}" 'build/' && \
|
||||
! kube::util::has_changes "${branch}" 'Godeps/' && \
|
||||
! kube::util::has_changes "${branch}" 'vendor/' && \
|
||||
! kube::util::has_changes "${branch}" 'hack/lib/' && \
|
||||
! kube::util::has_changes "${branch}" 'hack/.*godep'; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
|
Loading…
Reference in New Issue