Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Optimize test-attribution-txt.sh to use go.mod, not vendor #4059

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 3 additions & 33 deletions bin/test-attribution-txt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,16 @@ EXIT_CODE=0

cd "$GIT_ROOT"

if [ -d vendor.bk ]; then
echo "vendor.bk exits - remove before continuing"
exit 1
fi

trap cleanup 0 1 2 3 6

cleanup()
{
cd "$GIT_ROOT"
# restore the vendor dir
rm -rf vendor
if [ -d vendor.bk ]; then
mv vendor.bk vendor
fi
exit $EXIT_CODE
}

# if the vendor directory exists, back it up so we can build a fresh one
if [ -d vendor ]; then
mv vendor vendor.bk
fi

# create a vendor dir with the mod dependencies
GO111MODULE=on go mod vendor

# turn on nullglobbing so if there is nothing in cmd dir then we don't do
# anything in this loop
shopt -s nullglob

if [ ! -f Attribution.txt ]; then
echo "An Attribution.txt file is missing, please add"
EXIT_CODE=1
else
# loop over every library in the modules.txt file in vendor
# loop over every library in the go.mod file
while IFS= read -r lib; do
if ! grep -q "$lib" Attribution.txt && [ "$lib" != "explicit" ] && [ "$lib" != "explicit;" ]; then
if ! grep -q "$lib" Attribution.txt; then
echo "An attribution for $lib is missing from Attribution.txt, please add"
# need to do this in a bash subshell, see SC2031
(( EXIT_CODE=1 ))
fi
done < <(grep '#' < "$GIT_ROOT/vendor/modules.txt" | awk '{print $2}')
done < <(cat $GIT_ROOT/go.mod | grep -v 'module ' | grep -v TODO | grep '/' | sed 's/require //' | sed 's/replace //' | awk '{print $1}')
fi