Merge pull request #117526 from BenTheElder/mock-fun
call kube::golang::setup_env before setting up worktree, cleanup update-mocks.sh
This commit is contained in:
		@@ -18,7 +18,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
# The golang package that we are building.
 | 
					# The golang package that we are building.
 | 
				
			||||||
readonly KUBE_GO_PACKAGE=k8s.io/kubernetes
 | 
					readonly KUBE_GO_PACKAGE=k8s.io/kubernetes
 | 
				
			||||||
readonly KUBE_GOPATH="${KUBE_OUTPUT}/go"
 | 
					readonly KUBE_GOPATH="${KUBE_GOPATH:-"${KUBE_OUTPUT}/go"}"
 | 
				
			||||||
 | 
					export KUBE_GOPATH
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# The server platform we are building on.
 | 
					# The server platform we are building on.
 | 
				
			||||||
readonly KUBE_SUPPORTED_SERVER_PLATFORMS=(
 | 
					readonly KUBE_SUPPORTED_SERVER_PLATFORMS=(
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -26,16 +26,6 @@ source "${KUBE_ROOT}/hack/lib/init.sh"
 | 
				
			|||||||
# Explicitly opt into go modules, even though we're inside a GOPATH directory
 | 
					# Explicitly opt into go modules, even though we're inside a GOPATH directory
 | 
				
			||||||
export GO111MODULE=on
 | 
					export GO111MODULE=on
 | 
				
			||||||
 | 
					
 | 
				
			||||||
_tmp="${KUBE_ROOT}/_tmp_build_tag_files"
 | 
					 | 
				
			||||||
mkdir -p "${_tmp}"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function cleanup {
 | 
					 | 
				
			||||||
    rm -rf "$_tmp"
 | 
					 | 
				
			||||||
    rm -f "tempfile"
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
trap cleanup EXIT
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
kube::golang::verify_go_version
 | 
					kube::golang::verify_go_version
 | 
				
			||||||
kube::golang::setup_env
 | 
					kube::golang::setup_env
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -61,6 +51,10 @@ cd "${KUBE_ROOT}"
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
GENERATED_MOCK_FILE_REGEX="^// Code generated by MockGen. DO NOT EDIT.$"
 | 
					GENERATED_MOCK_FILE_REGEX="^// Code generated by MockGen. DO NOT EDIT.$"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# pick a tempfile path for writing to
 | 
				
			||||||
 | 
					tmp=$(mktemp)
 | 
				
			||||||
 | 
					kube::util::trap_add "rm -f ${tmp:?}" EXIT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# We use this pattern here rather than `git grep` because we don't really want
 | 
					# We use this pattern here rather than `git grep` because we don't really want
 | 
				
			||||||
# to encode the pathspec list in multiple places and anything more complicated
 | 
					# to encode the pathspec list in multiple places and anything more complicated
 | 
				
			||||||
# just isn't worth the effort.
 | 
					# just isn't worth the effort.
 | 
				
			||||||
@@ -112,7 +106,7 @@ git ls-files -mo --exclude-standard -z | while read -r -d $'\0' file; do
 | 
				
			|||||||
    new_header=$(echo -e "//""$go_build_tag_string""\n""//" "$build_tag_string""\n" | cat - hack/boilerplate/boilerplate.generatego.txt)
 | 
					    new_header=$(echo -e "//""$go_build_tag_string""\n""//" "$build_tag_string""\n" | cat - hack/boilerplate/boilerplate.generatego.txt)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # ignore the first line (build tag) from the file
 | 
					    # ignore the first line (build tag) from the file
 | 
				
			||||||
    tail -n +3 "$file" > tempfile
 | 
					    tail -n +3 "$file" >"${tmp}"
 | 
				
			||||||
  fi
 | 
					  fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # if the file has only // +build !providerless header
 | 
					  # if the file has only // +build !providerless header
 | 
				
			||||||
@@ -122,7 +116,7 @@ git ls-files -mo --exclude-standard -z | while read -r -d $'\0' file; do
 | 
				
			|||||||
    new_header=$(echo -e "//" "$build_tag_string""\n" | cat - hack/boilerplate/boilerplate.generatego.txt)
 | 
					    new_header=$(echo -e "//" "$build_tag_string""\n" | cat - hack/boilerplate/boilerplate.generatego.txt)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # ignore the first line (build tag) from the file
 | 
					    # ignore the first line (build tag) from the file
 | 
				
			||||||
    tail -n +2 "$file" > tempfile
 | 
					    tail -n +2 "$file" >"${tmp}"
 | 
				
			||||||
  fi
 | 
					  fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # if the file has only //go:build !providerless header
 | 
					  # if the file has only //go:build !providerless header
 | 
				
			||||||
@@ -132,17 +126,17 @@ git ls-files -mo --exclude-standard -z | while read -r -d $'\0' file; do
 | 
				
			|||||||
    new_header=$(echo -e "//""$go_build_tag_string""\n" | cat - hack/boilerplate/boilerplate.generatego.txt)
 | 
					    new_header=$(echo -e "//""$go_build_tag_string""\n" | cat - hack/boilerplate/boilerplate.generatego.txt)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # ignore the first line (build tag) from the file
 | 
					    # ignore the first line (build tag) from the file
 | 
				
			||||||
    tail -n +2 "$file" > tempfile
 | 
					    tail -n +2 "$file" >"${tmp}"
 | 
				
			||||||
  fi
 | 
					  fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # if the header is generated
 | 
					  # if the header is generated
 | 
				
			||||||
  if [ -n "$new_header" ]
 | 
					  if [ -n "$new_header" ]
 | 
				
			||||||
  then
 | 
					  then
 | 
				
			||||||
    # write the newly generated header file to the original file
 | 
					    # write the newly generated header file to the original file
 | 
				
			||||||
    echo -e "$new_header" | cat - tempfile > "$file"
 | 
					    echo -e "$new_header" | cat - "${tmp}" > "$file"
 | 
				
			||||||
  else
 | 
					  else
 | 
				
			||||||
    # if no build string insert at the top
 | 
					    # if no build string insert at the top
 | 
				
			||||||
    cat hack/boilerplate/boilerplate.generatego.txt "$file" > tempfile && \
 | 
					    cat hack/boilerplate/boilerplate.generatego.txt "$file" >"${tmp}" && \
 | 
				
			||||||
    mv tempfile "$file"
 | 
					    mv "${tmp}" "$file"
 | 
				
			||||||
  fi
 | 
					  fi
 | 
				
			||||||
done
 | 
					done
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,7 +21,7 @@ set -o pipefail
 | 
				
			|||||||
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
 | 
					KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
 | 
				
			||||||
source "${KUBE_ROOT}/hack/lib/init.sh"
 | 
					source "${KUBE_ROOT}/hack/lib/init.sh"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
kube::golang::verify_go_version
 | 
					kube::golang::setup_env
 | 
				
			||||||
 | 
					
 | 
				
			||||||
cd "${KUBE_ROOT}"
 | 
					cd "${KUBE_ROOT}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,9 +22,11 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
 | 
				
			|||||||
source "${KUBE_ROOT}/hack/lib/init.sh"
 | 
					source "${KUBE_ROOT}/hack/lib/init.sh"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
kube::util::ensure_clean_working_dir
 | 
					kube::util::ensure_clean_working_dir
 | 
				
			||||||
 | 
					# This sets up the environment, like GOCACHE, which keeps the worktree cleaner.
 | 
				
			||||||
 | 
					kube::golang::setup_env
 | 
				
			||||||
 | 
					
 | 
				
			||||||
_tmpdir="$(kube::realpath "$(mktemp -d -t verify-internal-modules.XXXXXX)")"
 | 
					_tmpdir="$(kube::realpath "$(mktemp -d -t verify-internal-modules.XXXXXX)")"
 | 
				
			||||||
#kube::util::trap_add "rm -rf ${_tmpdir}" EXIT
 | 
					kube::util::trap_add "rm -rf ${_tmpdir:?}" EXIT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
_tmp_gopath="${_tmpdir}/go"
 | 
					_tmp_gopath="${_tmpdir}/go"
 | 
				
			||||||
_tmp_kuberoot="${_tmp_gopath}/src/k8s.io/kubernetes"
 | 
					_tmp_kuberoot="${_tmp_gopath}/src/k8s.io/kubernetes"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -27,7 +27,8 @@ source "${KUBE_ROOT}/hack/lib/init.sh"
 | 
				
			|||||||
source "${KUBE_ROOT}/hack/lib/util.sh"
 | 
					source "${KUBE_ROOT}/hack/lib/util.sh"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
kube::golang::verify_go_version
 | 
					# This sets up the environment, like GOCACHE, which keeps the worktree cleaner.
 | 
				
			||||||
 | 
					kube::golang::setup_env
 | 
				
			||||||
kube::util::ensure-temp-dir
 | 
					kube::util::ensure-temp-dir
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -31,6 +31,8 @@ source "${KUBE_ROOT}/hack/lib/init.sh"
 | 
				
			|||||||
export GO111MODULE=on
 | 
					export GO111MODULE=on
 | 
				
			||||||
 | 
					
 | 
				
			||||||
kube::util::ensure_clean_working_dir
 | 
					kube::util::ensure_clean_working_dir
 | 
				
			||||||
 | 
					# This sets up the environment, like GOCACHE, which keeps the worktree cleaner.
 | 
				
			||||||
 | 
					kube::golang::setup_env
 | 
				
			||||||
 | 
					
 | 
				
			||||||
_tmpdir="$(kube::realpath "$(mktemp -d -t "$(basename "$0").XXXXXX")")"
 | 
					_tmpdir="$(kube::realpath "$(mktemp -d -t "$(basename "$0").XXXXXX")")"
 | 
				
			||||||
git worktree add -f -q "${_tmpdir}" HEAD
 | 
					git worktree add -f -q "${_tmpdir}" HEAD
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,6 +28,8 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
 | 
				
			|||||||
source "${KUBE_ROOT}/hack/lib/init.sh"
 | 
					source "${KUBE_ROOT}/hack/lib/init.sh"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
kube::util::ensure_clean_working_dir
 | 
					kube::util::ensure_clean_working_dir
 | 
				
			||||||
 | 
					# This sets up the environment, like GOCACHE, which keeps the worktree cleaner.
 | 
				
			||||||
 | 
					kube::golang::setup_env
 | 
				
			||||||
 | 
					
 | 
				
			||||||
_tmpdir="$(kube::realpath "$(mktemp -d -t "$(basename "$0").XXXXXX")")"
 | 
					_tmpdir="$(kube::realpath "$(mktemp -d -t "$(basename "$0").XXXXXX")")"
 | 
				
			||||||
git worktree add -f -q "${_tmpdir}" HEAD
 | 
					git worktree add -f -q "${_tmpdir}" HEAD
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user