From 9d368636866d3a0c86f1506db1e49af0d1e258cd Mon Sep 17 00:00:00 2001 From: Mike Helmick Date: Wed, 3 Jun 2020 09:29:42 -0700 Subject: [PATCH] Revert "ci: stop formatting generated files (#509)" This reverts commit 6435ae8dcdcea2d3fedcb2802b097f51b2782c90. --- internal/pb/export/export.pb.go | 5 +++-- internal/pb/federation.pb.go | 5 +++-- scripts/presubmit.sh | 25 +++++++++---------------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/internal/pb/export/export.pb.go b/internal/pb/export/export.pb.go index 36d6e92c7..376977b7b 100644 --- a/internal/pb/export/export.pb.go +++ b/internal/pb/export/export.pb.go @@ -21,11 +21,12 @@ package export import ( + reflect "reflect" + sync "sync" + proto "github.com/golang/protobuf/proto" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" ) const ( diff --git a/internal/pb/federation.pb.go b/internal/pb/federation.pb.go index e57f32cfb..bf42411e5 100644 --- a/internal/pb/federation.pb.go +++ b/internal/pb/federation.pb.go @@ -22,14 +22,15 @@ package pb import ( context "context" + reflect "reflect" + sync "sync" + proto "github.com/golang/protobuf/proto" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" ) const ( diff --git a/scripts/presubmit.sh b/scripts/presubmit.sh index 5078cfca2..fda02db0f 100755 --- a/scripts/presubmit.sh +++ b/scripts/presubmit.sh @@ -17,6 +17,8 @@ set -eEuo pipefail ROOT="$(cd "$(dirname "$0")/.." &>/dev/null; pwd -P)" +SOURCE_DIRS="cmd internal tools" + echo "๐ŸŒณ Set up environment variables" eval $(${ROOT}/scripts/dev init) @@ -24,12 +26,7 @@ eval $(${ROOT}/scripts/dev init) echo "๐Ÿš’ Verify Protobufs are up to date" ${ROOT}/scripts/dev protoc -git diff *.go | tee /dev/stderr | (! read) -if [ $? -ne 0 ]; then - echo "โœ‹ Found uncommited changes after regenerating Protobufs." - echo "โœ‹ Commit these changes before merging." - exit 1 -fi +# Don't verify generated pb files here as they are tidied later. echo "๐Ÿงฝ Verify goimports formattting" @@ -41,12 +38,11 @@ if [ $? -ne 0 ]; then echo "โœ‹ to enable import cleanup. Import cleanup skipped." else echo "๐Ÿงฝ Format with goimports" - # Find all non-generated Go files. This works by excluding - # files that start with the official "generated file" header. - # See https://github.com/golang/go/issues/13560#issuecomment-288457920 - grep -L -HR "^\/\/ Code generated .* DO NOT EDIT\.$" --include="*.go" "${ROOT}" | xargs goimports -w + goimports -w $(echo $SOURCE_DIRS) # Check if there were uncommited changes. - git diff *.go | tee /dev/stderr | (! read) + # Ignore comment line changes as sometimes proto gen just updates versions + # of the generator + git diff -G'(^\s+[^/])' *.go | tee /dev/stderr | (! read) if [ $? -ne 0 ]; then echo "โœ‹ Found uncommited changes after goimports." echo "โœ‹ Commit these changes before merging." @@ -58,11 +54,8 @@ set -e echo "๐Ÿงน Verify gofmt format" set +e -# Find all non-generated Go files. This works by excluding -# files that start with the official "generated file" header. -# See https://github.com/golang/go/issues/13560#issuecomment-288457920 -grep -L -HR "^\/\/ Code generated .* DO NOT EDIT\.$" --include="*.go" "${ROOT}" | xargs gofmt -s -w -git diff *.go | tee /dev/stderr | (! read) +diff -u <(echo -n) <(gofmt -d -s .) +git diff -G'(^\s+[^/])' *.go | tee /dev/stderr | (! read) if [ $? -ne 0 ]; then echo "โœ‹ Found uncommited changes after gofmt." echo "โœ‹ Commit these changes before merging."