forked from dolthub/go-mysql-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_repo.sh
executable file
·31 lines (25 loc) · 921 Bytes
/
check_repo.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
set -eo pipefail
go mod download golang.org/x/tools
go install golang.org/x/tools/cmd/goimports
paths=`find . -maxdepth 1 -mindepth 1 \( -name gen -prune -o -type d -print -o -type f -name '*.go' -print \)`
bad_files=$(goimports -l -local github.com/dolthub/dolt $paths)
if [ "$bad_files" != "" ]; then
echo "ERROR: The following files do not match goimports output:"
echo "$bad_files"
echo
echo "Please format the go code in the repository with 'format_repo.sh'"
exit 1
fi
bad_files=$(find $paths -name '*.go' | while read f; do
if [[ $(awk '/import \(/{flag=1;next}/\)/{flag=0}flag' < $f | egrep -c '$^') -gt 2 ]]; then
echo $f
fi
done)
if [ "$bad_files" != "" ]; then
echo "ERROR: The following files have more than three import groups:"
echo "$bad_files"
echo
echo "Please format the go code in the repository with 'format_repo.sh'"
exit 1
fi