-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlicenses
More file actions
executable file
·84 lines (73 loc) · 3.1 KB
/
licenses
File metadata and controls
executable file
·84 lines (73 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
#
# Generate third-party license information for embedding in the binary.
#
# Usage:
# ./script/licenses <GOOS> <GOARCH> Generate licenses for a single platform
# ./script/licenses --check Verify generation works for all release platforms
#
# The single-platform mode is called by goreleaser pre-build hooks to generate
# platform-specific license information that gets embedded via go:embed.
#
# The --check mode is used in CI to catch license generation issues before release.
set -e
# Install pinned version of go-licenses
go install github.com/google/go-licenses/v2@3e084b0caf710f7bfead967567539214f598c0a2 # v2.0.1
# Verify go-licenses is available
if ! command -v go-licenses &> /dev/null; then
echo "Error: go-licenses is not installed or not on PATH"
exit 1
fi
generate_licenses() {
local goos="$1"
local goarch="$2"
local output_dir="$3"
echo "Generating licenses for ${goos}/${goarch}..."
mkdir -p "${output_dir}"
# Generate the report listing (name, license type, URL)
GOOS="${goos}" GOARCH="${goarch}" go-licenses report ./... \
--template .github/licenses.tmpl \
--ignore github.com/cli/cli \
> "${output_dir}/report.txt"
# Save license and notice files for all dependencies
rm -rf "${output_dir}/third-party"
GOOS="${goos}" GOARCH="${goarch}" go-licenses save ./... \
--save_path="${output_dir}/third-party" \
--ignore github.com/cli/cli \
--force 2>/dev/null || true
# Remove everything except LICENSE and NOTICE files. go-licenses save copies
# full source code for some licenses (e.g., MPL-2.0), but go:embed cannot
# include directories containing go.mod or .go files.
if [ -d "${output_dir}/third-party" ]; then
find "${output_dir}/third-party" -type f \
! -iname "LICENSE*" \
! -iname "LICENCE*" \
! -iname "NOTICE*" \
! -iname "COPYING*" \
! -iname "PATENTS*" \
-delete
find "${output_dir}/third-party" -type d -empty -delete
fi
}
if [ "$1" = "--check" ]; then
# Verify license generation works for all release platforms.
# This runs the same go-licenses report command that goreleaser pre-build hooks
# will run at release time, for all 9 GOOS/GOARCH combinations. Running this in
# CI on every PR ensures we catch issues (e.g., template errors, go-licenses
# incompatibilities, dependency resolution failures) before they block a release.
TEMPDIR="$(mktemp -d)"
trap "rm -fr ${TEMPDIR}" EXIT
for platform in linux/386 linux/arm linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/386 windows/amd64 windows/arm64; do
goos="${platform%/*}"
goarch="${platform#*/}"
generate_licenses "${goos}" "${goarch}" "${TEMPDIR}/${goos}-${goarch}"
done
echo "License generation verified for all platforms."
elif [ $# -eq 2 ]; then
generate_licenses "$1" "$2" "internal/licenses/embed/${1}-${2}"
echo "Licenses written to internal/licenses/embed/${1}-${2}"
else
echo "Usage: $0 <GOOS> <GOARCH>"
echo " $0 --check"
exit 1
fi