Use temp directory for license checks

This commit is contained in:
Andy Feller 2025-06-20 16:44:44 -04:00
parent 4e8d022448
commit 4d1eb59c36
2 changed files with 11 additions and 7 deletions

View file

@ -2,11 +2,13 @@
go install github.com/google/go-licenses@latest
# Setup temporary directory to collect updated third-party source code
export TEMPDIR="$(mktemp -d)"
trap "rm -fr ${TEMPDIR}" EXIT
# Clear third-party source code to avoid stale content
rm -rf third-party
mkdir -p third-party
export TEMPDIR="$(mktemp -d)"
trap "rm -fr ${TEMPDIR}" EXIT
for goos in linux darwin windows ; do
# Note: we ignore warnings because we want the command to succeed, however the output should be checked

View file

@ -2,6 +2,10 @@
go install github.com/google/go-licenses@latest
# Setup temporary directory for generated license reports
export TEMPDIR="$(mktemp -d)"
trap "rm -fr ${TEMPDIR}" EXIT
for goos in linux darwin windows ; do
# Note: we ignore warnings because we want the command to succeed, however the output should be checked
# for any new warnings, and potentially we may need to add license information.
@ -9,13 +13,11 @@ for goos in linux darwin windows ; do
# Normally these warnings are packages containing non go code, which may or may not require explicit attribution,
# depending on the license.
echo "Checking licenses for ${goos}..."
GOOS="${goos}" go-licenses report ./... --template .github/licenses.tmpl --ignore github.com/cli/cli > third-party-licenses.${goos}.copy.md || echo "Ignore warnings"
if ! diff -s third-party-licenses.${goos}.copy.md third-party-licenses.${goos}.md; then
GOOS="${goos}" go-licenses report ./... --template .github/licenses.tmpl --ignore github.com/cli/cli > "${TEMPDIR}/third-party-licenses.${goos}.md" || echo "Ignore warnings"
if ! diff -s "${TEMPDIR}/third-party-licenses.${goos}.md" "third-party-licenses.${goos}.md"; then
echo "::error title=License check failed::Please update the license files by running \`script/licenses\` and committing the output."
rm -f third-party-licenses.${goos}.copy.md
exit 1
fi
rm -f third-party-licenses.${goos}.copy.md
done
echo "License check passed for all platforms."