From 5a28a02b97219520502f4f91d843bbc9c86037d1 Mon Sep 17 00:00:00 2001 From: Piotr Tabor Date: Wed, 28 Dec 2022 16:34:04 +0100 Subject: [PATCH] ./scripts/fix.sh: Takes care of goimports across the whole project. Signed-off-by: Piotr Tabor --- scripts/fix.sh | 12 +++++++++++- scripts/test.sh | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/fix.sh b/scripts/fix.sh index 1925f87bc..d845c1149 100755 --- a/scripts/fix.sh +++ b/scripts/fix.sh @@ -8,6 +8,8 @@ go mod tidy source ./scripts/test_lib.sh source ./scripts/updatebom.sh +ROOTDIR=`pwd` + # To fix according to newer version of go: # go get golang.org/dl/gotip # gotip download @@ -29,11 +31,19 @@ function bash_ws_fix { find ./ -name '*.sh.bak' -print0 | xargs -0 rm } -log_callout -e "\\nFixing etcd code for you...\\n" +function go_imports_fix { + GOFILES=$(run ${GO_CMD} list --f '{{with $d:=.}}{{range .GoFiles}}{{$d.Dir}}/{{.}}{{"\n"}}{{end}}{{end}}' ./...) + cd ${ROOTDIR}/tools/mod + echo "$GOFILES" | grep -v '.gw.go' | grep -v '.pb.go' | xargs -n 100 go run golang.org/x/tools/cmd/goimports -w -local go.etcd.io +} + +log_callout -e "\\nFixing etcd code for you...\n" run_for_modules mod_tidy_fix || exit 2 run_for_modules run ${GO_CMD} fmt || exit 2 run_for_module tests bom_fix || exit 2 +run_for_modules go_imports_fix || exit 2 bash_ws_fix || exit 2 + log_success -e "\\nSUCCESS: etcd code is fixed :)" diff --git a/scripts/test.sh b/scripts/test.sh index c71560713..9042cce2f 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -51,7 +51,7 @@ if [ -n "${OUTPUT_FILE}" ]; then exec > >(tee -a "${OUTPUT_FILE}") 2>&1 fi -PASSES=${PASSES:-"fmt bom dep build unit"} +PASSES=${PASSES:-"gofmt bom dep build unit"} PKG=${PKG:-} SHELLCHECK_VERSION=${SHELLCHECK_VERSION:-"v0.8.0"}