Replace google/go-licenses with custom generation#36575
Replace google/go-licenses with custom generation#36575silverwind merged 26 commits intogo-gitea:mainfrom
google/go-licenses with custom generation#36575Conversation
…eration Rewrite build/generate-go-licenses.go to use `go list -m -json all` and read license files directly from the Go module cache instead of relying on the external google/go-licenses tool. This removes the need for CGO, GOOS=linux, and the intermediate temp directory, while producing more complete output (350 vs 269 entries). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
google/go-licenses with custom generation
There was a problem hiding this comment.
Pull request overview
This PR rewrites the Go license generation pipeline to avoid github.com/google/go-licenses, instead enumerating modules via go list -m -json all and reading license files directly from each module’s local directory.
Changes:
- Replaced the
go-licenses-based workflow with a new module-cache scanning implementation inbuild/generate-go-licenses.go. - Simplified the
Makefilego-licenses target to a singlego runinvocation (no temp dir, no CGO/GOOS requirements). - Removed
.go-licensesartifacts from.gitignoreand tar exclusions.
Reviewed changes
Copilot reviewed 2 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| build/generate-go-licenses.go | New implementation that shells out to go list -m -json all and scans module dirs for license files. |
| Makefile | Removes go-licenses tool install/temp-dir steps and calls the generator directly. |
| .gitignore | Drops ignore entry for the removed .go-licenses temp directory. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: silverwind <me@silverwind.io>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 4 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Use `go list -deps` to determine which modules are real non-test dependencies, excluding tool deps (e.g. gitea-vet) and test-only transitive deps (e.g. xorm/sqlfiddle). Scan main module subdirectories for separate LICENSE files to restore entries like modules/lfs which has distinct copyright attribution. Also fix JSON decoder to use io.EOF instead of dec.More() for streaming top-level objects. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
After last change license count is now 267, very close to main's 265. Likely because of elimination of test-only dependencies. |
Use GOOS=linux with CGO in go list -deps to capture all platform-specific dependencies, matching the CI environment. Skip gitignored files in subdirectory license scanning to avoid including local-only files. Skip internal directories. Add ignoredModulePaths for excluding non-third-party license files. Run the two go list commands in parallel. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This comment was marked as resolved.
This comment was marked as resolved.
Remove the getTrackedFiles/git-ls-files mechanism and sync.WaitGroup concurrency as they are unnecessary — the directory skip list in findSubdirLicenses already excludes all relevant directories. Add "public" to the skip list to handle the one edge case. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…enses Replace the separate findSubdirLicenses tree walk with package-directory scanning in findLicenseFiles, handling both dependency and main modules uniformly. This restores 11 subdirectory licenses with unique terms that were previously missed and reduces the overall diff. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Did a few more refactorings to reduce diff in both the license file and the generation script. Looks pretty good to me now. |
Signed-off-by: silverwind <me@silverwind.io>
When a module directory contains multiple license files, prefer primary files (LICENSE, LICENCE, COPYING) over variants with suffixes (LICENSE.docs, LICENSE-2.0.txt). If no primary file exists, keep only the first variant. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@lunny check the license output diff again please, I think it's pretty minimal now. |
TheFox0x7
left a comment
There was a problem hiding this comment.
I think you can just hardcode the 2 that the tool missed and it'll be good.
We're probably can do better with the notices but what matters most is that there's no regression in compliance.
Shame there's no OSS software that does it properly that I could find and verify on this...
From commercial side FOSSA has something but it's also not great.
Walk up from each package directory to the module root, scanning all intermediate parent directories for license files with unique text. This restores two internal vendored licenses that were previously missed. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Both requested licenses restored. |
Rewrite
build/generate-go-licenses.goto usego list -m -json alland read license files directly from the Go module cache instead of relying on the buggygoogle/go-licensestool.This removes the need for CGO, GOOS=linux, and the intermediate temp directory, while being like 100 times faster than before: