Skip to content

Commit

Permalink
build: Optimize test-attribution-txt.sh to use go.mod, not vendor (#4059
Browse files Browse the repository at this point in the history
)

Signed-off-by: Leonard Goodell <leonard.goodell@intel.com>
  • Loading branch information
Lenny Goodell committed Jun 22, 2022
1 parent a33d295 commit 25cc1d4
Showing 1 changed file with 3 additions and 33 deletions.
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

0 comments on commit 25cc1d4

Please sign in to comment.