Skip to content

Commit

Permalink
./scripts/fix.sh: Takes care of goimports across the whole project.
Browse files Browse the repository at this point in the history
Signed-off-by: Piotr Tabor <ptab@google.com>
  • Loading branch information
ptabor committed Dec 28, 2022
1 parent 1e14a0e commit 5a28a02
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion scripts/fix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 :)"
2 changes: 1 addition & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

Expand Down

0 comments on commit 5a28a02

Please sign in to comment.