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

ci: stop formatting generated files #469

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: 2 additions & 3 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: 2 additions & 3 deletions internal/pb/federation.pb.go

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

23 changes: 14 additions & 9 deletions scripts/presubmit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,23 @@
set -eEuo pipefail

ROOT="$(cd "$(dirname "$0")/.." &>/dev/null; pwd -P)"
SOURCE_DIRS="cmd internal tools"

# 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
SOURCE_FILES=($(grep -L -HR "^\/\/ Code generated .* DO NOT EDIT\.$" --include="*.go" ${ROOT}))

echo "🌳 Set up environment variables"
eval $(${ROOT}/scripts/dev init)


echo "🚒 Verify Protobufs are up to date"
${ROOT}/scripts/dev protoc
# Don't verify generated pb files here as they are tidied later.
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


echo "🧽 Verify goimports formattting"
Expand All @@ -38,11 +45,9 @@ if [ $? -ne 0 ]; then
echo "✋ to enable import cleanup. Import cleanup skipped."
else
echo "🧽 Format with goimports"
goimports -w $(echo $SOURCE_DIRS)
goimports -w ${SOURCE_FILES[@]}
# Check if there were uncommited changes.
# Ignore comment line changes as sometimes proto gen just updates versions
# of the generator
git diff -G'(^\s+[^/])' *.go | tee /dev/stderr | (! read)
git diff *.go | tee /dev/stderr | (! read)
if [ $? -ne 0 ]; then
echo "✋ Found uncommited changes after goimports."
echo "✋ Commit these changes before merging."
Expand All @@ -54,8 +59,8 @@ set -e

echo "🧹 Verify gofmt format"
set +e
diff -u <(echo -n) <(gofmt -d -s .)
git diff -G'(^\s+[^/])' *.go | tee /dev/stderr | (! read)
gofmt -s -w ${SOURCE_FILES[@]}
git diff *.go | tee /dev/stderr | (! read)
if [ $? -ne 0 ]; then
echo "✋ Found uncommited changes after gofmt."
echo "✋ Commit these changes before merging."
Expand Down