Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Revert "ci: stop formatting generated files" #533

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions internal/pb/export/export.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions internal/pb/federation.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 9 additions & 16 deletions scripts/presubmit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,16 @@
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)


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"
Expand All @@ -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."
Expand All @@ -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."
Expand Down