Skip to content

Conversation

@SamMorrowDrums
Copy link
Collaborator

Summary

This PR improves the license script to handle architecture-specific dependency differences. Some dependencies have different module graphs for different GOARCH values (e.g., x/sys/cpu vs x/sys/unix), which can result in different licenses being exported per architecture.

Problem

As discovered in github/cli, some deps change which changes the mod graph for different GOARCH values. For example:

  • amd64 might have x/sys/cpu and x/sys/unix so the common ancestor is x/sys
  • arm64 might just have x/sys/unix so the common ancestor is x/sys/unix

This means license reports can differ between architectures on the same platform.

Solution

Updated script/licenses to:

  1. Check all architectures per platform - linux (amd64, arm64, 386), darwin (amd64, arm64), windows (amd64, arm64, 386)
  2. Group identical results - Architectures with the same dependencies are grouped together with comma-separated headers
  3. Show divergent lists - Only shows separate sections when architectures actually differ
  4. Add index at top - Each platform file now has a table of contents linking to each architecture section
  5. Save per-arch licenses - Each architecture's licenses are saved in the third-party folder

Changes

  • script/licenses: Enhanced to handle multi-architecture license generation with grouping
  • third-party-licenses.*.md: Updated with architecture sections and index
  • third-party/: Contains architecture-specific license folders

Example Output

When all architectures have the same deps:

## Index

- [amd64, arm64, 386](#amd64-arm64-386)

## amd64, arm64, 386

| Module | License |
|--------|---------|
| ... | ... |

When architectures differ:

## Index

- [amd64](#amd64)
- [arm64, 386](#arm64-386)

## amd64

| Module | License |
|--------|---------|
| ... | ... |

## arm64, 386

| Module | License |
|--------|---------|
| ... | ... |

The licenses script now:
- Generates separate license reports per GOOS/GOARCH combination
- Groups identical reports together (comma-separated arch names)
- Adds a Table of Contents at the top of each platform file
- Handles cases where different architectures have different dependencies
  (e.g., x/sys/unix vs x/sys/windows, mousetrap on Windows only)

This addresses the issue discovered in cli/cli where some deps changed
which changed the mod graph for different GOARCH and affected the
exported licenses because go-licenses tries to find common ancestors.
@SamMorrowDrums SamMorrowDrums requested a review from a team as a code owner December 12, 2025 10:43
Copilot AI review requested due to automatic review settings December 12, 2025 10:43
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the license generation script to properly handle architecture-specific dependency differences across GOOS/GOARCH combinations. The script now generates separate reports per architecture, groups identical results with comma-separated headers, and adds a table of contents to each platform file.

Key changes:

  • Multi-architecture license generation for Linux (amd64, arm64, 386), Darwin (amd64, arm64), and Windows (amd64, arm64, 386)
  • Grouping logic that consolidates architectures with identical dependency lists
  • Automated table of contents generation with anchor links

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.

File Description
script/licenses Complete rewrite to support multi-architecture license generation with grouping logic, TOC generation, and per-arch report handling
third-party-licenses.linux.md Restructured with TOC and architecture sections; packages reordered alphabetically
third-party-licenses.darwin.md Restructured with TOC and architecture sections; packages reordered alphabetically
third-party-licenses.windows.md Restructured with TOC and architecture sections; packages reordered alphabetically

Address review feedback:
- Remove bash 4.0+ associative array requirement for macOS compatibility
- Add cross-platform hash function (md5sum on Linux, md5 on macOS)
- Ensure deterministic iteration order using sorted groups file
- Add better error handling for failed go-licenses commands
- Fix grammar: 'architecture(s)' -> 'architectures'
- Add documentation for third-party/ being a union of all architectures
- Use file-based state instead of associative arrays for portability
@SamMorrowDrums SamMorrowDrums force-pushed the fix/arch-specific-licenses branch 2 times, most recently from ee28e6d to 8855c2c Compare December 12, 2025 11:43
- 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
@SamMorrowDrums SamMorrowDrums force-pushed the fix/arch-specific-licenses branch from 8855c2c to eb7d73c Compare December 12, 2025 12:23
The sort command uses locale-specific ordering which can differ between
systems. Use LC_ALL=C to ensure consistent ordering in CI and locally.
@SamMorrowDrums SamMorrowDrums merged commit adaa6a1 into main Dec 12, 2025
16 checks passed
@SamMorrowDrums SamMorrowDrums deleted the fix/arch-specific-licenses branch December 12, 2025 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants