github.com/rumpl/bof@v23.0.0-rc.2+incompatible/hack/validate/pkg-imports (about) 1 #!/usr/bin/env bash 2 set -e 3 4 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 if [ "$f" = "pkg/urlutil/deprecated.go" ]; then 14 # pkg/urlutil is deprecated, but has a temporary alias to help migration, 15 # see https://github.com/moby/moby/pull/43477 16 # TODO(thaJeztah) remove this exception once pkg/urlutil aliases are removed 17 continue 18 fi 19 IFS=$'\n' 20 badImports=($(go list -e -f '{{ join .Deps "\n" }}' "$f" | sort -u | grep -vE '^github.com/docker/docker/pkg/' | grep -vE '^github.com/docker/docker/vendor' | grep -E '^github.com/docker/docker' || true)) 21 unset IFS 22 23 for import in "${badImports[@]}"; do 24 badFiles+=("$f imports $import") 25 done 26 done 27 28 if [ ${#badFiles[@]} -eq 0 ]; then 29 echo 'Congratulations! Packages in "./pkg/..." are safely isolated from internal code.' 30 else 31 { 32 echo 'These files import internal code: (either directly or indirectly)' 33 for f in "${badFiles[@]}"; do 34 echo " - $f" 35 done 36 echo 37 } >&2 38 false 39 fi