Make verify-yamlfmt.sh use git worktree

This commit is contained in:
Tim Hockin 2022-09-11 18:54:55 -07:00
parent d2504c94a0
commit 90e290e495
No known key found for this signature in database
2 changed files with 13 additions and 32 deletions

View File

@ -39,4 +39,5 @@ find_files() {
\) -name 'OWNERS*' \) -name 'OWNERS*'
} }
export GO111MODULE=on
find_files | xargs go run cmd/yamlfmt/yamlfmt.go find_files | xargs go run cmd/yamlfmt/yamlfmt.go

View File

@ -25,43 +25,23 @@ set -o nounset
set -o pipefail set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
export KUBE_ROOT
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
_tmpdir="$(kube::realpath "$(mktemp -d -t verify-yamlfmt.XXXXXX)")" _tmpdir="$(kube::realpath "$(mktemp -d -t "$(basename "$0").XXXXXX")")"
git worktree add -f -q "${_tmpdir}" HEAD
kube::util::trap_add "git worktree remove -f ${_tmpdir}" EXIT
cd "${_tmpdir}"
_tmp_gopath="${_tmpdir}/go" # Format YAML files
_tmp_kuberoot="${_tmp_gopath}/src/k8s.io/kubernetes" hack/update-yamlfmt.sh
git worktree add -f "${_tmp_kuberoot}" HEAD
kube::util::trap_add "git worktree remove -f ${_tmp_kuberoot} && rm -rf ${_tmpdir}" EXIT
find_files() { # Test for diffs
pushd "${_tmp_kuberoot}" >/dev/null 2>&1 diffs=$(git status --porcelain | wc -l)
find "$(pwd)" -not \( \ if [[ ${diffs} -gt 0 ]]; then
\( \ echo "YAML files need to be formatted" >&2
-wholename './output' \ git diff
-o -wholename './.git' \ echo "Please run 'hack/update-yamlfmt.sh'" >&2
-o -wholename './_output' \
-o -wholename './_gopath' \
-o -wholename './release' \
-o -wholename './target' \
-o -wholename '*/vendor/*' \
\) -prune \
\) -name 'OWNERS*'
popd >/dev/null 2>&1
}
find_files | xargs go run cmd/yamlfmt/yamlfmt.go
cd "${_tmp_kuberoot}"
changed_files=$(git status --porcelain)
if [[ -n "${changed_files}" ]]; then
echo "!!! OWNERS files need to be updated:" >&2
echo "${changed_files}" >&2
echo >&2
echo "Please run hack/update-yamlfmt.sh." >&2
exit 1 exit 1
fi fi