mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
325c3a457b
The hack/vendor.sh script is used to (re)vendor dependencies. However, it did not run `go mod tidy` before doing so, wheras the vendor _validation_ script did. This could result in vendor validation failing if go mod tidy resulted in changes (which could be in `vendor.sum`). In "usual" situations, this could be easily done by the user (`go mod tidy` before running `go mod vendor`), but due to our (curent) uses of `vendor.mod`, and having to first set up a (dummy) `go.mod`, this is more complicated. Instead, just make the script do this, so that `hack/vendor.sh` will always produce the expected result. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
53 lines
1.5 KiB
Bash
Executable file
53 lines
1.5 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
source "${SCRIPTDIR}/.validate"
|
|
|
|
validate_vendor_diff(){
|
|
IFS=$'\n'
|
|
check_files=( 'vendor.sum' 'vendor.mod' 'vendor/' )
|
|
# shellcheck disable=SC2207
|
|
changed_files=( $(validate_diff --diff-filter=ACMR --name-only -- "${check_files[@]}" || true) )
|
|
unset IFS
|
|
|
|
if [ -n "${TEST_FORCE_VALIDATE:-}" ] || [ "${#changed_files[@]}" -gt 0 ]; then
|
|
# recreate vendor/
|
|
./hack/vendor.sh
|
|
# check if any files have changed
|
|
diffs="$(git status --porcelain -- "${check_files[@]}" 2>/dev/null)"
|
|
mfiles="$(echo "$diffs" | awk '/^ M / {print $2}')"
|
|
if [ "$diffs" ]; then
|
|
{
|
|
echo 'The result of go mod vendor differs'
|
|
echo
|
|
echo "$diffs"
|
|
echo
|
|
echo 'Please vendor your package with hack/vendor.sh.'
|
|
echo
|
|
if [ -n "$mfiles" ] ; then
|
|
git diff -- "$mfiles"
|
|
fi
|
|
} >&2
|
|
false
|
|
else
|
|
echo 'Congratulations! All vendoring changes are done the right way.'
|
|
fi
|
|
else
|
|
echo 'No vendor changes in diff.'
|
|
fi
|
|
}
|
|
|
|
# 1. make sure all the vendored packages are used
|
|
# 2. make sure all the packages contain license information (just warning, because it can cause false-positive)
|
|
validate_vendor_used() {
|
|
for f in $(mawk '$1 = "#" { print $2 }' 'vendor/modules.txt'); do
|
|
if [ -d "vendor/$f" ]; then
|
|
if ! echo "vendor/$f"/* | grep -qiEc '/(LICENSE|COPYING)'; then
|
|
echo "WARNING: could not find copyright information for $f"
|
|
fi
|
|
fi
|
|
done
|
|
}
|
|
|
|
validate_vendor_diff
|
|
validate_vendor_used
|