github.com/dolthub/go-mysql-server@v0.18.0/check_repo.sh (about)

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