fix: update licenses-check to use new architecture-aware format

- Check now regenerates using ./script/licenses and compares
- Add GOROOT/PATH setup in CI to fix go-licenses module info errors
- Check both license files AND third-party directory for changes
- See: https://github.com/google/go-licenses/issues/244
This commit is contained in:
Sam Morrow
2025-12-12 12:31:24 +01:00
committed by Sam Morrow
parent 3a1844c22c
commit e7e2925666
2 changed files with 35 additions and 14 deletions
+8
View File
@@ -21,6 +21,14 @@ set -e
go install github.com/google/go-licenses@latest
# actions/setup-go does not setup the installed toolchain to be preferred over the system install,
# which causes go-licenses to raise "Package ... does not have module info" errors in CI.
# For more information, https://github.com/google/go-licenses/issues/244#issuecomment-1885098633
if [ "$CI" = "true" ]; then
export GOROOT=$(go env GOROOT)
export PATH=${GOROOT}/bin:$PATH
fi
rm -rf third-party
mkdir -p third-party
export TEMPDIR="$(mktemp -d)"
+27 -14
View File
@@ -1,21 +1,34 @@
#!/bin/bash
#
# Check that license files are up to date.
# This script regenerates the license files and compares them with the committed versions.
# If there are differences, it exits with an error.
go install github.com/google/go-licenses@latest
set -e
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.
#
# Normally these warnings are packages containing non go code, which may or may not require explicit attribution,
# depending on the license.
GOOS="${goos}" GOFLAGS=-mod=mod go-licenses report ./... --template .github/licenses.tmpl > third-party-licenses.${goos}.copy.md || echo "Ignore warnings"
if ! diff -s third-party-licenses.${goos}.copy.md third-party-licenses.${goos}.md; then
printf "License check failed.\n\nPlease update the license file 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
# Store original files for comparison
TEMPDIR="$(mktemp -d)"
trap "rm -fr ${TEMPDIR}" EXIT
# Save original license markdown files
for goos in darwin linux windows; do
cp "third-party-licenses.${goos}.md" "${TEMPDIR}/"
done
# Save the state of third-party directory
cp -r third-party "${TEMPDIR}/third-party.orig"
# Regenerate using the same script
./script/licenses
# Check for any differences in workspace
if ! git diff --exit-code --quiet third-party-licenses.*.md third-party/; then
echo "License files are out of date:"
git diff third-party-licenses.*.md third-party/
echo ""
printf "\nLicense check failed.\n\nPlease update the license files by running \`./script/licenses\` and committing the output.\n"
exit 1
fi
echo "License check passed for all platforms."