From e7e292566633acdb892eddf77e42a76c83e6e337 Mon Sep 17 00:00:00 2001 From: Sam Morrow Date: Fri, 12 Dec 2025 12:31:24 +0100 Subject: [PATCH] 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 --- script/licenses | 8 ++++++++ script/licenses-check | 41 +++++++++++++++++++++++++++-------------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/script/licenses b/script/licenses index ebc97c86..062e8e28 100755 --- a/script/licenses +++ b/script/licenses @@ -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)" diff --git a/script/licenses-check b/script/licenses-check index 67b567d0..430c8170 100755 --- a/script/licenses-check +++ b/script/licenses-check @@ -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."