diff --git a/script/licenses b/script/licenses index d1e85fe0d..c38b12258 100755 --- a/script/licenses +++ b/script/licenses @@ -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 diff --git a/script/licenses-check b/script/licenses-check index c19c9efb0..07f9dae8d 100755 --- a/script/licenses-check +++ b/script/licenses-check @@ -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."