github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/hack/validate/vendor (about)

     1  #!/usr/bin/env bash
     2  
     3  SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
     4  source "${SCRIPTDIR}/.validate"
     5  
     6  validate_vendor_diff(){
     7  	IFS=$'\n'
     8  	files=( $(validate_diff --diff-filter=ACMR --name-only -- 'vendor.conf' 'vendor/' || true) )
     9  	unset IFS
    10  
    11  	if [ -n "${TEST_FORCE_VALIDATE:-}" ] || [ ${#files[@]} -gt 0 ]; then
    12  		# recreate vendor/
    13  		vndr -whitelist=^archive/tar
    14  		# check if any files have changed
    15  		diffs="$(git status --porcelain -- vendor 2>/dev/null)"
    16  		mfiles="$(echo "$diffs" | awk '/^ M / {print $2}')"
    17  		if [ "$diffs" ]; then
    18  			{
    19  				echo 'The result of vndr differs'
    20  				echo
    21  				echo "$diffs"
    22  				echo
    23  				echo 'Please vendor your package with github.com/LK4D4/vndr.'
    24  				echo
    25  				if [ -n "$mfiles" ] ; then
    26  					git diff -- "$mfiles"
    27  				fi
    28  			} >&2
    29  			false
    30  		else
    31  			echo 'Congratulations! All vendoring changes are done the right way.'
    32  		fi
    33  	else
    34  		echo 'No vendor changes in diff.'
    35  	fi
    36  }
    37  
    38  # 1. make sure all the vendored packages are used
    39  # 2. make sure all the packages contain license information (just warning, because it can cause false-positive)
    40  validate_vendor_used() {
    41  	for f in $(mawk '/^[a-zA-Z0-9]/ { print $1 }' vendor.conf); do
    42  	if [ -d "vendor/$f" ]; then
    43  		if ! echo "vendor/$f"/* | grep -qiEc '/(LICENSE|COPYING)'; then
    44  		echo "WARNING: could not find copyright information for $f"
    45  		fi
    46  	else
    47  		echo "WARNING: $f is vendored but unused"
    48  	fi
    49  	done
    50  }
    51  
    52  validate_vendor_diff
    53  validate_vendor_used