mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 04:06:03 +00:00
Merge pull request #126540 from skitt/avoid-double-mock-headers
Handle all mock header generation with mockery
This commit is contained in:
commit
b860feb2a6
@ -44,10 +44,6 @@ cd "${KUBE_ROOT}"
|
||||
|
||||
GENERATED_MOCK_FILE_REGEX="^// Code generated by mockery v[0-9.]\+. DO NOT EDIT.$"
|
||||
|
||||
# pick a tempfile path for writing to
|
||||
tmp=$(mktemp)
|
||||
kube::util::trap_add "rm -f ${tmp:?}" EXIT
|
||||
|
||||
git_grep -l -z "${GENERATED_MOCK_FILE_REGEX}" | xargs -0 rm -f
|
||||
|
||||
echo 'executing go generate command on below files'
|
||||
@ -73,58 +69,3 @@ git_grep -l -z "//go:generate mockery" | while read -r -d $'\0' file; do
|
||||
go -C "$(dirname "$file")" generate "$(basename "$file")"
|
||||
fi
|
||||
done
|
||||
|
||||
# get the changed or new mock files
|
||||
git ls-files -mo --exclude-standard -z | while read -r -d $'\0' file; do
|
||||
# only process files that appear to be mocks
|
||||
test -f "$file" || continue
|
||||
grep -q "${GENERATED_MOCK_FILE_REGEX}" "$file" || continue
|
||||
|
||||
# search for build tags used in file
|
||||
# //go:build !providerless
|
||||
# // +build !providerless
|
||||
go_build_tag_string=$(grep -o 'go:build.*$' "$file") || true
|
||||
build_tag_string=$(grep -o '+build.*$' "$file") || true
|
||||
new_header=''
|
||||
|
||||
# if the file has both headers
|
||||
if [ -n "$build_tag_string" ] && [ -n "$go_build_tag_string" ]
|
||||
then
|
||||
# create a new header with the build string and the copyright text
|
||||
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" >"${tmp}"
|
||||
fi
|
||||
|
||||
# if the file has only // +build !providerless header
|
||||
if [ -n "$build_tag_string" ] && [ -z "$go_build_tag_string" ]
|
||||
then
|
||||
# create a new header with the build string and the copyright text
|
||||
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" >"${tmp}"
|
||||
fi
|
||||
|
||||
# if the file has only //go:build !providerless header
|
||||
if [ -z "$build_tag_string" ] && [ -n "$go_build_tag_string" ]
|
||||
then
|
||||
# create a new header with the build string and the copyright text
|
||||
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" >"${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 - "${tmp}" > "$file"
|
||||
else
|
||||
# if no build string insert at the top
|
||||
cat hack/boilerplate/boilerplate.generatego.txt "$file" >"${tmp}" && \
|
||||
mv "${tmp}" "$file"
|
||||
fi
|
||||
done
|
||||
|
@ -14,22 +14,6 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by mockery v2.40.3. DO NOT EDIT.
|
||||
|
||||
package testing
|
||||
|
@ -14,22 +14,6 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by mockery v2.40.3. DO NOT EDIT.
|
||||
|
||||
package handlers
|
||||
|
@ -14,22 +14,6 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by mockery v2.40.3. DO NOT EDIT.
|
||||
|
||||
package handlers
|
||||
|
Loading…
Reference in New Issue
Block a user