github.com/cactusblossom/fabric-ca@v0.0.0-20200611062428-0082fc643826/scripts/check_imports (about) 1 #!/bin/bash 2 # 3 # Copyright IBM Corp. All Rights Reserved. 4 # 5 # SPDX-License-Identifier: Apache-2.0 6 # 7 8 # shellcheck source=/dev/null 9 source "$(cd "$(dirname "$0")" && pwd)/functions.sh" 10 11 GOIMPORTS="$GOPATH/bin/goimports" 12 13 if [[ ! -f $GOIMPORTS ]]; then 14 echo "Installing goimports ..." 15 go get golang.org/x/tools/cmd/goimports 16 if [[ $? -ne 0 ]]; then 17 echo "Failed to install goimports" 18 exit 1 19 fi 20 fi 21 22 fabric_ca_dir="$(cd "$(dirname "$0")/.." && pwd)" 23 source_dirs=() 24 while IFS=$'\n' read -r source_dir; do 25 source_dirs+=("$source_dir") 26 done < <(go list -f '{{.Dir}}' ./... | sed s,"${fabric_ca_dir}".,,g | cut -f 1 -d / | sort -u) 27 28 echo "Checking imports ..." 29 OUTPUT="$(goimports -l "${source_dirs[@]}")" 30 OUTPUT="$(filterExcludedAndGeneratedFiles "$OUTPUT")" 31 if [[ $OUTPUT != "" ]]; then 32 echo "The following files have import problems:" 33 echo "$OUTPUT" 34 echo "You may run 'goimports -w <file>' to fix each file." 35 exit 1 36 fi 37 echo "All files are properly formatted"