github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/hack/validate/pkg-imports (about) 1 #!/usr/bin/env bash 2 set -e 3 4 export SCRIPTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 5 source "${SCRIPTDIR}/.validate" 6 7 IFS=$'\n' 8 files=($(validate_diff --diff-filter=ACMR --name-only -- 'pkg/*.go' || true)) 9 unset IFS 10 11 badFiles=() 12 for f in "${files[@]}"; do 13 IFS=$'\n' 14 badImports=($(go list -e -f '{{ join .Deps "\n" }}' "$f" | sort -u | grep -vE '^github.com/demonoid81/moby/pkg/' | grep -vE '^github.com/demonoid81/moby/vendor' | grep -E '^github.com/demonoid81/moby' || true)) 15 unset IFS 16 17 for import in "${badImports[@]}"; do 18 badFiles+=("$f imports $import") 19 done 20 done 21 22 if [ ${#badFiles[@]} -eq 0 ]; then 23 echo 'Congratulations! Packages in "./pkg/..." are safely isolated from internal code.' 24 else 25 { 26 echo 'These files import internal code: (either directly or indirectly)' 27 for f in "${badFiles[@]}"; do 28 echo " - $f" 29 done 30 echo 31 } >&2 32 false 33 fi