Merge pull request #115240 from thockin/codegen-9-use-ls-files

Use `git ls-files` in a few places instead of `find`
This commit is contained in:
Kubernetes Prow Robot 2023-01-23 00:26:21 -08:00 committed by GitHub
commit 0fcc3dbd55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 107 additions and 63 deletions

View File

@ -27,20 +27,17 @@ kube::golang::verify_go_version
cd "${KUBE_ROOT}" cd "${KUBE_ROOT}"
find_files() { function git_find() {
find . -not \( \ # Similar to find but faster and easier to understand. We want to include
\( \ # modified and untracked files because this might be running against code
-wholename './output' \ # which is not tracked by git yet.
-o -wholename './.git' \ git ls-files -cmo --exclude-standard \
-o -wholename './_output' \ ':!:vendor/*' `# catches vendor/...` \
-o -wholename './_gopath' \ ':!:*/vendor/*' `# catches any subdir/vendor/...` \
-o -wholename './release' \ ':!:third_party/*' `# catches third_party/...` \
-o -wholename './target' \ ':!:*/third_party/*' `# catches third_party/...` \
-o -wholename '*/third_party/*' \ ':(glob)**/*.go' \
-o -wholename '*/vendor/*' \ "$@"
-o -wholename './staging/src/k8s.io/client-go/*vendor/*' \
\) -prune \
\) -name '*.go'
} }
find_files | xargs gofmt -s -w git_find -z | xargs -0 gofmt -s -w

View File

@ -45,22 +45,18 @@ popd >/dev/null
cd "${KUBE_ROOT}" cd "${KUBE_ROOT}"
find_files() { function git_find() {
find . -not \( \ # Similar to find but faster and easier to understand. We want to include
\( \ # modified and untracked files because this might be running against code
-wholename './output' \ # which is not tracked by git yet.
-o -wholename './.git' \ git ls-files -cmo --exclude-standard \
-o -wholename './_output' \ ':!:vendor/*' `# catches vendor/...` \
-o -wholename './_gopath' \ ':!:*/vendor/*' `# catches any subdir/vendor/...` \
-o -wholename './release' \ ':!:third_party/*' `# catches third_party/...` \
-o -wholename './target' \ ':!:*/third_party/*' `# catches third_party/...` \
-o -wholename '*/third_party/*' \ ':(glob)**/*.go' \
-o -wholename '*/vendor/*' \ "$@"
-o -wholename './staging/src/k8s.io/client-go/*vendor/*' \
\) -prune \
\) -name '*.go'
} }
# replace net.ParseIP() and netParseIPCDR # replace net.ParseIP() and netParseIPCDR
find_files | xargs sloppy-netparser git_find -z | xargs -0 sloppy-netparser

View File

@ -29,37 +29,47 @@ stability_check_setup() {
kube::golang::setup_env kube::golang::setup_env
} }
find_files_to_check() { function find_files_to_check() {
find . -not \( \ # Similar to find but faster and easier to understand. We want to include
\( \ # modified and untracked files because this might be running against code
-wholename './output' \ # which is not tracked by git yet.
-o -wholename './_output' \ git ls-files -cmo --exclude-standard \
-o -wholename './_gopath' \ ':!:vendor/*' `# catches vendor/...` \
-o -wholename './release' \ ':!:*/vendor/*' `# catches any subdir/vendor/...` \
-o -wholename './target' \ ':!:third_party/*' `# catches third_party/...` \
-o -wholename '*/third_party/*' \ ':!:*/third_party/*' `# catches third_party/...` \
-o -wholename '*/vendor/*' \ ':!:hack/*' `# catches hack/...` \
-o -wholename '*/hack/*' \ ':!:*/hack/*' `# catches any subdir/hack/...` \
-o -wholename '*_test.go' \ ':!:*/*_test.go' \
-o -wholename './test/instrumentation/*.go' \ ':!:test/instrumentation' \
\) -prune \ ':(glob)**/*.go' \
\) \ "$@"
\( -wholename '**/*.go' \
\)
} }
find_test_files() { function find_test_files() {
find './test/instrumentation' -wholename '**/*.go' git ls-files -cmo --exclude-standard \
'./test/instrumentation' \
"$@"
} }
red=$(tput setaf 1) red=$(tput setaf 1)
green=$(tput setaf 2) green=$(tput setaf 2)
reset=$(tput sgr0) reset=$(tput sgr0)
kube::validate::stablemetrics() { function kube::validate::stablemetrics() {
stability_check_setup stability_check_setup
temp_file=$(mktemp) temp_file=$(mktemp)
doValidate=$(find_files_to_check | grep -E ".*.go" | grep -v ".*_test.go" | grep -v ".git" | sort | KUBE_ROOT=${KUBE_ROOT} xargs -L 200 go run "test/instrumentation/main.go" "test/instrumentation/decode_metric.go" "test/instrumentation/find_stable_metric.go" "test/instrumentation/error.go" "test/instrumentation/metric.go" -- 1>"${temp_file}") doValidate=$(find_files_to_check -z \
| sort -z \
| KUBE_ROOT=${KUBE_ROOT} xargs -0 -L 200 \
go run \
"test/instrumentation/main.go" \
"test/instrumentation/decode_metric.go" \
"test/instrumentation/find_stable_metric.go" \
"test/instrumentation/error.go" \
"test/instrumentation/metric.go" \
-- \
1>"${temp_file}")
if $doValidate; then if $doValidate; then
echo -e "${green}Diffing test/instrumentation/testdata/stable-metrics-list.yaml\n${reset}" echo -e "${green}Diffing test/instrumentation/testdata/stable-metrics-list.yaml\n${reset}"
@ -74,10 +84,20 @@ kube::validate::stablemetrics() {
exit 1 exit 1
} }
kube::validate::test::stablemetrics() { function kube::validate::test::stablemetrics() {
stability_check_setup stability_check_setup
temp_file=$(mktemp) temp_file=$(mktemp)
doValidate=$(find_test_files | grep -E ".*.go" | grep -v ".*_test.go" | grep -v ".git" | sort | KUBE_ROOT=${KUBE_ROOT} xargs -L 200 go run "test/instrumentation/main.go" "test/instrumentation/decode_metric.go" "test/instrumentation/find_stable_metric.go" "test/instrumentation/error.go" "test/instrumentation/metric.go" -- 1>"${temp_file}") doValidate=$(find_test_files -z \
| sort -z \
| KUBE_ROOT=${KUBE_ROOT} xargs -0 -L 200 \
go run \
"test/instrumentation/main.go" \
"test/instrumentation/decode_metric.go" \
"test/instrumentation/find_stable_metric.go" \
"test/instrumentation/error.go" \
"test/instrumentation/metric.go" \
-- \
1>"${temp_file}")
if $doValidate; then if $doValidate; then
echo -e "${green}Diffing test/instrumentation/testdata/test-stable-metrics-list.yaml\n${reset}" echo -e "${green}Diffing test/instrumentation/testdata/test-stable-metrics-list.yaml\n${reset}"
@ -92,10 +112,21 @@ kube::validate::test::stablemetrics() {
exit 1 exit 1
} }
kube::update::stablemetrics() { function kube::update::stablemetrics() {
stability_check_setup stability_check_setup
temp_file=$(mktemp) temp_file=$(mktemp)
doCheckStability=$(find_files_to_check | grep -E ".*.go" | grep -v ".*_test.go" | sort | KUBE_ROOT=${KUBE_ROOT} xargs -L 200 go run "test/instrumentation/main.go" "test/instrumentation/decode_metric.go" "test/instrumentation/find_stable_metric.go" "test/instrumentation/error.go" "test/instrumentation/metric.go" -- 1>"${temp_file}")
doCheckStability=$(find_files_to_check -z \
| sort -z \
| KUBE_ROOT=${KUBE_ROOT} xargs -0 -L 200 \
go run \
"test/instrumentation/main.go" \
"test/instrumentation/decode_metric.go" \
"test/instrumentation/find_stable_metric.go" \
"test/instrumentation/error.go" \
"test/instrumentation/metric.go" \
-- \
1>"${temp_file}")
if ! $doCheckStability; then if ! $doCheckStability; then
echo "${red}!!! updating golden list of metrics has failed! ${reset}" >&2 echo "${red}!!! updating golden list of metrics has failed! ${reset}" >&2
@ -105,10 +136,21 @@ kube::update::stablemetrics() {
echo "${green}Updated golden list of stable metrics.${reset}" echo "${green}Updated golden list of stable metrics.${reset}"
} }
kube::update::documentation::list() { function kube::update::documentation::list() {
stability_check_setup stability_check_setup
temp_file=$(mktemp) temp_file=$(mktemp)
doCheckStability=$(find_files_to_check | grep -E ".*.go" | grep -v ".*_test.go" | sort | KUBE_ROOT=${KUBE_ROOT} xargs -L 200 go run "test/instrumentation/main.go" "test/instrumentation/decode_metric.go" "test/instrumentation/find_stable_metric.go" "test/instrumentation/error.go" "test/instrumentation/metric.go" --allstabilityclasses -- 1>"${temp_file}") doCheckStability=$(find_files_to_check -z \
| sort -z \
| KUBE_ROOT=${KUBE_ROOT} xargs -0 -L 200 \
go run \
"test/instrumentation/main.go" \
"test/instrumentation/decode_metric.go" \
"test/instrumentation/find_stable_metric.go" \
"test/instrumentation/error.go" \
"test/instrumentation/metric.go" \
--allstabilityclasses \
-- \
1>"${temp_file}")
if ! $doCheckStability; then if ! $doCheckStability; then
echo "${red}!!! updating golden list of metrics has failed! ${reset}" >&2 echo "${red}!!! updating golden list of metrics has failed! ${reset}" >&2
@ -118,7 +160,7 @@ kube::update::documentation::list() {
echo "${green}Updated list of metrics for documentation ${reset}" echo "${green}Updated list of metrics for documentation ${reset}"
} }
kube::update::documentation() { function kube::update::documentation() {
stability_check_setup stability_check_setup
temp_file=$(mktemp) temp_file=$(mktemp)
arg1=$1 arg1=$1
@ -132,10 +174,20 @@ kube::update::documentation() {
echo "${green}Updated documentation of metrics.${reset}" echo "${green}Updated documentation of metrics.${reset}"
} }
kube::update::test::stablemetrics() { function kube::update::test::stablemetrics() {
stability_check_setup stability_check_setup
temp_file=$(mktemp) temp_file=$(mktemp)
doCheckStability=$(find_test_files | grep -E ".*.go" | grep -v ".*_test.go" | sort | KUBE_ROOT=${KUBE_ROOT} xargs -L 200 go run "test/instrumentation/main.go" "test/instrumentation/decode_metric.go" "test/instrumentation/find_stable_metric.go" "test/instrumentation/error.go" "test/instrumentation/metric.go" -- 1>"${temp_file}") doCheckStability=$(find_test_files -z \
| sort -z \
| KUBE_ROOT=${KUBE_ROOT} xargs -0 -L 200 \
go run \
"test/instrumentation/main.go" \
"test/instrumentation/decode_metric.go" \
"test/instrumentation/find_stable_metric.go" \
"test/instrumentation/error.go" \
"test/instrumentation/metric.go" \
-- \
1>"${temp_file}")
if ! $doCheckStability; then if ! $doCheckStability; then
echo "${red}!!! updating golden list of test metrics has failed! ${reset}" >&2 echo "${red}!!! updating golden list of test metrics has failed! ${reset}" >&2
@ -144,4 +196,3 @@ kube::update::test::stablemetrics() {
mv -f "$temp_file" "${KUBE_ROOT}/test/instrumentation/testdata/test-stable-metrics-list.yaml" mv -f "$temp_file" "${KUBE_ROOT}/test/instrumentation/testdata/test-stable-metrics-list.yaml"
echo "${green}Updated test list of stable metrics.${reset}" echo "${green}Updated test list of stable metrics.${reset}"
} }