mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 03:57:41 +00:00
cleanup update-mocks.sh
- remove unused tempdir - use mktemp instead of creating tmpfile in repo - normalize indent
This commit is contained in:
parent
726992f9db
commit
4d736a0435
@ -26,16 +26,6 @@ source "${KUBE_ROOT}/hack/lib/init.sh"
|
||||
# Explicitly opt into go modules, even though we're inside a GOPATH directory
|
||||
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::setup_env
|
||||
|
||||
@ -61,6 +51,10 @@ cd "${KUBE_ROOT}"
|
||||
|
||||
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
|
||||
# to encode the pathspec list in multiple places and anything more complicated
|
||||
# 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)
|
||||
|
||||
# ignore the first line (build tag) from the file
|
||||
tail -n +3 "$file" > tempfile
|
||||
tail -n +3 "$file" >"${tmp}"
|
||||
fi
|
||||
|
||||
# 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)
|
||||
|
||||
# ignore the first line (build tag) from the file
|
||||
tail -n +2 "$file" > tempfile
|
||||
tail -n +2 "$file" >"${tmp}"
|
||||
fi
|
||||
|
||||
# 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)
|
||||
|
||||
# ignore the first line (build tag) from the file
|
||||
tail -n +2 "$file" > tempfile
|
||||
tail -n +2 "$file" >"${tmp}"
|
||||
fi
|
||||
|
||||
# if the header is generated
|
||||
if [ -n "$new_header" ]
|
||||
then
|
||||
# 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
|
||||
# if no build string insert at the top
|
||||
cat hack/boilerplate/boilerplate.generatego.txt "$file" > tempfile && \
|
||||
mv tempfile "$file"
|
||||
cat hack/boilerplate/boilerplate.generatego.txt "$file" >"${tmp}" && \
|
||||
mv "${tmp}" "$file"
|
||||
fi
|
||||
done
|
||||
|
Loading…
Reference in New Issue
Block a user