Skip to content

Commit bdc44fa

Browse files
fix: update licenses-check to use new architecture-aware format
The check now regenerates using script/licenses and compares with committed files, ensuring it matches the architecture-grouped format.
1 parent ea9a04d commit bdc44fa

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

script/licenses-check

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,41 @@
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
7+
set -e
8+
9+
# Store original files for comparison
10+
TEMPDIR="$(mktemp -d)"
11+
trap "rm -fr ${TEMPDIR}" EXIT
12+
13+
for goos in darwin linux windows; do
14+
cp "third-party-licenses.${goos}.md" "${TEMPDIR}/"
15+
done
16+
17+
# Regenerate using the same script
18+
./script/licenses
19+
20+
# Compare with originals
21+
has_diff=0
22+
for goos in darwin linux windows; do
23+
if ! diff -q "${TEMPDIR}/third-party-licenses.${goos}.md" "third-party-licenses.${goos}.md" >/dev/null 2>&1; then
24+
echo "License file for ${goos} is out of date:"
25+
diff "${TEMPDIR}/third-party-licenses.${goos}.md" "third-party-licenses.${goos}.md" || true
26+
has_diff=1
1627
fi
17-
rm -f third-party-licenses.${goos}.copy.md
1828
done
1929

30+
# Restore original files (check shouldn't modify anything)
31+
for goos in darwin linux windows; do
32+
cp "${TEMPDIR}/third-party-licenses.${goos}.md" "./"
33+
done
34+
35+
if [ $has_diff -eq 1 ]; then
36+
printf "\nLicense check failed.\n\nPlease update the license files by running \`./script/licenses\` and committing the output.\n"
37+
exit 1
38+
fi
2039

40+
echo "License check passed for all platforms."
2141

0 commit comments

Comments
 (0)