Skip to content

Commit eb7d73c

Browse files
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: google/go-licenses#244
1 parent ea9a04d commit eb7d73c

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

script/licenses

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ set -e
2121

2222
go install github.com/google/go-licenses@latest
2323

24+
# actions/setup-go does not setup the installed toolchain to be preferred over the system install,
25+
# which causes go-licenses to raise "Package ... does not have module info" errors in CI.
26+
# For more information, https://github.com/google/go-licenses/issues/244#issuecomment-1885098633
27+
if [ "$CI" = "true" ]; then
28+
export GOROOT=$(go env GOROOT)
29+
export PATH=${GOROOT}/bin:$PATH
30+
fi
31+
2432
rm -rf third-party
2533
mkdir -p third-party
2634
export TEMPDIR="$(mktemp -d)"

script/licenses-check

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
#!/bin/bash
2+
#
3+
# Check that license files are up to date.
4+
# This script regenerates the license files and compares them with the committed versions.
5+
# If there are differences, it exits with an error.
26

3-
go install github.com/google/go-licenses@latest
4-
5-
for goos in linux darwin windows ; do
6-
# Note: we ignore warnings because we want the command to succeed, however the output should be checked
7-
# for any new warnings, and potentially we may need to add license information.
8-
#
9-
# Normally these warnings are packages containing non go code, which may or may not require explicit attribution,
10-
# depending on the license.
11-
GOOS="${goos}" GOFLAGS=-mod=mod go-licenses report ./... --template .github/licenses.tmpl > third-party-licenses.${goos}.copy.md || echo "Ignore warnings"
12-
if ! diff -s third-party-licenses.${goos}.copy.md third-party-licenses.${goos}.md; then
13-
printf "License check failed.\n\nPlease update the license file by running \`.script/licenses\` and committing the output."
14-
rm -f third-party-licenses.${goos}.copy.md
15-
exit 1
16-
fi
17-
rm -f third-party-licenses.${goos}.copy.md
7+
set -e
8+
9+
# Store original files for comparison
10+
TEMPDIR="$(mktemp -d)"
11+
trap "rm -fr ${TEMPDIR}" EXIT
12+
13+
# Save original license markdown files
14+
for goos in darwin linux windows; do
15+
cp "third-party-licenses.${goos}.md" "${TEMPDIR}/"
1816
done
1917

18+
# Save the state of third-party directory
19+
cp -r third-party "${TEMPDIR}/third-party.orig"
20+
21+
# Regenerate using the same script
22+
./script/licenses
23+
24+
# Check for any differences in workspace
25+
if ! git diff --exit-code --quiet third-party-licenses.*.md third-party/; then
26+
echo "License files are out of date:"
27+
git diff third-party-licenses.*.md third-party/
28+
echo ""
29+
printf "\nLicense check failed.\n\nPlease update the license files by running \`./script/licenses\` and committing the output.\n"
30+
exit 1
31+
fi
2032

33+
echo "License check passed for all platforms."
2134

0 commit comments

Comments
 (0)