Use license in repo root, when appropriate #328
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
resolves #73, resolves #186
This is an alternative solution to PR #110 - Downside to this approach is it depends on the module cache behaving a certain way. Upside is it does not require network access to validate URLs (i hit github rate limits with the other approach).
For modules that are not at the root of the repo, Go will make a copy of the LICENSE file from the repo root into the module's directory when creating the .zip file (see https://go.dev/ref/mod#vcs-license)
This throws off URL generation, as FileURL will create a link to a repo URL to the license that doesn't exist as the file was synthesized by Go.
Attempt to detect this case by examining the zip file that Go creates - As it stands, it appends the LICENSE file to the zip's file directory; we can generally assume that if we see such an addition, it's a result of Go copying it there and therefore it's not a real file in the repo, instead being copied from the root.
If we find that to be the case, generate a link to the original LICENSE file at the root of the repo instead.
The complex e2e test here exercises this nicely (updated links didn't work before, now they do).