Merge pull request #16093 from jmhbnz/separate-fix-targets

Ensure goimports can be fixed individually
This commit is contained in:
Marek Siarkowicz
2023-06-16 13:30:02 +02:00
committed by GitHub
3 changed files with 35 additions and 14 deletions

View File

@@ -65,7 +65,7 @@ fuzz:
verify: verify-gofmt verify-bom verify-lint verify-dep verify-shellcheck verify-goword \
verify-govet verify-license-header verify-receiver-name verify-mod-tidy verify-shellcheck \
verify-shellws verify-proto-annotations verify-genproto verify-goimport verify-yamllint
fix: fix-bom fix-lint fix-yamllint
fix: fix-goimports fix-bom fix-lint fix-yamllint
./scripts/fix.sh
.PHONY: verify-gofmt
@@ -76,7 +76,7 @@ verify-gofmt:
verify-bom:
PASSES="bom" ./scripts/test.sh
.PHONY: update-bom
.PHONY: fix-bom
fix-bom:
./scripts/updatebom.sh
@@ -88,7 +88,7 @@ verify-dep:
verify-lint:
golangci-lint run --config tools/.golangci.yaml
.PHONY: update-lint
.PHONY: fix-lint
fix-lint:
golangci-lint run --config tools/.golangci.yaml --fix
@@ -132,6 +132,10 @@ verify-genproto:
verify-goimport:
PASSES="goimport" ./scripts/test.sh
.PHONY: fix-goimports
fix-goimports:
./scripts/fix-goimports.sh
.PHONY: verify-yamllint
verify-yamllint:
yamllint --config-file tools/.yamllint .

28
scripts/fix-goimports.sh Executable file
View File

@@ -0,0 +1,28 @@
#!/usr/bin/env bash
set -euo pipefail
source ./scripts/test_lib.sh
ROOTDIR=$(pwd)
# To fix according to newer version of go:
# go get golang.org/dl/gotip
# gotip download
# GO_CMD="gotip"
GO_CMD="go"
ROOTDIR=$(pwd)
function go_imports_fix {
GOFILES=$(run ${GO_CMD} list --f "{{with \$d:=.}}{{range .GoFiles}}{{\$d.Dir}}/{{.}}{{\"\n\"}}{{end}}{{end}}" ./...)
TESTGOFILES=$(run ${GO_CMD} list --f "{{with \$d:=.}}{{range .TestGoFiles}}{{\$d.Dir}}/{{.}}{{\"\n\"}}{{end}}{{end}}" ./...)
cd "${ROOTDIR}/tools/mod"
echo "${GOFILES}" "${TESTGOFILES}" | 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 goimports for you...\n"
run_for_modules go_imports_fix || exit 2
log_success -e "\\nSUCCESS: goimports are fixed :)"

View File

@@ -8,8 +8,6 @@ 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
@@ -31,20 +29,11 @@ function bash_ws_fix {
find ./ -name '*.sh.bak' -print0 | xargs -0 rm
}
function go_imports_fix {
GOFILES=$(run ${GO_CMD} list --f "{{with \$d:=.}}{{range .GoFiles}}{{\$d.Dir}}/{{.}}{{\"\n\"}}{{end}}{{end}}" ./...)
TESTGOFILES=$(run ${GO_CMD} list --f "{{with \$d:=.}}{{range .TestGoFiles}}{{\$d.Dir}}/{{.}}{{\"\n\"}}{{end}}{{end}}" ./...)
cd "${ROOTDIR}/tools/mod"
echo "${GOFILES}" "${TESTGOFILES}" | 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
log_callout "Fixing goimports..."
run_for_modules go_imports_fix || exit 2
bash_ws_fix || exit 2