11#! /bin/bash
2+ #
3+ # Generate license files for all platform/arch combinations.
4+ # This script handles architecture-specific dependency differences by:
5+ # 1. Generating separate license reports per GOOS/GOARCH combination
6+ # 2. Grouping identical reports together (comma-separated arch names)
7+ # 3. Creating an index at the top of each platform file
8+ # 4. Copying all license files to third-party/
9+ #
10+ # Note: we ignore warnings because we want the command to succeed, however the output should be checked
11+ # for any new warnings, and potentially we may need to add license information.
12+ #
13+ # Normally these warnings are packages containing non go code, which may or may not require explicit attribution,
14+ # depending on the license.
15+
16+ set -e
217
318go install github.com/google/go-licenses@latest
419
@@ -8,14 +23,105 @@ export TEMPDIR="$(mktemp -d)"
823
924trap " rm -fr ${TEMPDIR} " EXIT
1025
11- for goos in linux darwin windows ; do
12- # Note: we ignore warnings because we want the command to succeed, however the output should be checked
13- # for any new warnings, and potentially we may need to add license information.
14- #
15- # Normally these warnings are packages containing non go code, which may or may not require explicit attribution,
16- # depending on the license.
17- GOOS=" ${goos} " GOFLAGS=-mod=mod go-licenses save ./... --save_path=" ${TEMPDIR} /${goos} " --force || echo " Ignore warnings"
18- GOOS=" ${goos} " GOFLAGS=-mod=mod go-licenses report ./... --template .github/licenses.tmpl > third-party-licenses.${goos} .md || echo " Ignore warnings"
19- cp -fR " ${TEMPDIR} /${goos} " /* third-party/
26+ # Define platforms and their architectures
27+ declare -A PLATFORM_ARCHS
28+ PLATFORM_ARCHS[" linux" ]=" amd64 arm64 386"
29+ PLATFORM_ARCHS[" darwin" ]=" amd64 arm64"
30+ PLATFORM_ARCHS[" windows" ]=" amd64 arm64 386"
31+
32+ # Generate reports for each platform/arch combination
33+ for goos in linux darwin windows; do
34+ echo " Processing ${goos} ..."
35+
36+ # Store reports per arch for this platform
37+ declare -A ARCH_REPORTS
38+ declare -A ARCH_HASHES
39+
40+ for goarch in ${PLATFORM_ARCHS[$goos]} ; do
41+ echo " Generating for ${goos} /${goarch} ..."
42+
43+ # Generate the license report for this arch
44+ report_file=" ${TEMPDIR} /${goos} _${goarch} _report.md"
45+ GOOS=" ${goos} " GOARCH=" ${goarch} " GOFLAGS=-mod=mod go-licenses report ./... --template .github/licenses.tmpl > " ${report_file} " 2> /dev/null || echo " (warnings ignored for ${goos} /${goarch} )"
46+
47+ # Save licenses to temp directory
48+ GOOS=" ${goos} " GOARCH=" ${goarch} " GOFLAGS=-mod=mod go-licenses save ./... --save_path=" ${TEMPDIR} /${goos} _${goarch} " --force 2> /dev/null || echo " (warnings ignored for ${goos} /${goarch} )"
49+
50+ # Copy to third-party (accumulate all)
51+ if [ -d " ${TEMPDIR} /${goos} _${goarch} " ]; then
52+ cp -fR " ${TEMPDIR} /${goos} _${goarch} " /* third-party/ 2> /dev/null || true
53+ fi
54+
55+ # Extract just the package list (skip header) and hash it
56+ packages=$( grep -E ' ^ - \[' " ${report_file} " 2> /dev/null | sort || echo " " )
57+ hash=$( echo " ${packages} " | md5sum | cut -d' ' -f1)
58+
59+ ARCH_REPORTS[" ${goarch} " ]=" ${packages} "
60+ ARCH_HASHES[" ${goarch} " ]=" ${hash} "
61+ done
62+
63+ # Group architectures with identical reports
64+ declare -A HASH_TO_ARCHS
65+ for goarch in ${PLATFORM_ARCHS[$goos]} ; do
66+ hash=" ${ARCH_HASHES[$goarch]} "
67+ if [ -n " ${HASH_TO_ARCHS[$hash]} " ]; then
68+ HASH_TO_ARCHS[" ${hash} " ]=" ${HASH_TO_ARCHS[$hash]} , ${goarch} "
69+ else
70+ HASH_TO_ARCHS[" ${hash} " ]=" ${goarch} "
71+ fi
72+ done
73+
74+ # Generate the combined report for this platform
75+ output_file=" third-party-licenses.${goos} .md"
76+
77+ cat > " ${output_file} " << 'EOF '
78+ # GitHub MCP Server dependencies
79+
80+ The following open source dependencies are used to build the [github/github-mcp-server][] GitHub Model Context Protocol Server.
81+
82+ ## Table of Contents
83+
84+ EOF
85+
86+ # Build table of contents
87+ for hash in " ${! HASH_TO_ARCHS[@]} " ; do
88+ archs=" ${HASH_TO_ARCHS[$hash]} "
89+ # Create anchor-friendly name
90+ anchor=$( echo " ${archs} " | tr ' , ' ' -' | tr -s ' -' )
91+ echo " - [${archs} ](#${anchor} )" >> " ${output_file} "
92+ done
93+
94+ echo " " >> " ${output_file} "
95+ echo " ---" >> " ${output_file} "
96+ echo " " >> " ${output_file} "
97+
98+ # Add each unique report section
99+ for hash in " ${! HASH_TO_ARCHS[@]} " ; do
100+ archs=" ${HASH_TO_ARCHS[$hash]} "
101+ # Get the packages from the first arch in this group
102+ first_arch=$( echo " ${archs} " | cut -d' ,' -f1 | tr -d ' ' )
103+ packages=" ${ARCH_REPORTS[$first_arch]} "
104+
105+ cat >> " ${output_file} " << EOF
106+ ## ${archs}
107+
108+ The following packages are included for the ${archs} architecture(s).
109+
110+ ${packages}
111+
112+ EOF
113+ done
114+
115+ # Add footer
116+ echo " [github/github-mcp-server]: https://github.com/github/github-mcp-server" >> " ${output_file} "
117+
118+ echo " Generated ${output_file} "
119+
120+ # Clean up associative arrays for next platform
121+ unset ARCH_REPORTS
122+ unset ARCH_HASHES
123+ unset HASH_TO_ARCHS
20124done
21125
126+ echo " Done! License files generated."
127+
0 commit comments