Fix go work vendor command to exit with correct code#1016
Merged
Conversation
89bfef0 to
0bebdc2
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes the Go version probe in scripts/gomod-patch.sh so the script correctly detects whether go work vendor is available (Go ≥ 1.22) and uses workspace-aware vendoring when a go.work file is present.
Changes:
- Replace
go work vendor -h(always exits non-zero) withgo help work vendoras the availability probe. - Ensure
go work vendoris used when supported, avoiding incomplete vendoring when using Go workspaces.
invidian
reviewed
Mar 31, 2026
| if [ -f "$gowork_path" ]; then | ||
| # Check if 'go work vendor' is available (Go 1.22+) | ||
| if go work vendor -h >/dev/null 2>&1; then | ||
| if go help work vendor >/dev/null 2>&1; then |
Contributor
There was a problem hiding this comment.
Can we add some tests to cover this code path?
…stead of 2 Signed-off-by: Brian Chuo <brianchuo@microsoft.com>
Signed-off-by: Brian Chuo <brianchuo@microsoft.com>
fb427ff to
f1c02bd
Compare
Signed-off-by: Brian Chuo <brianchuo@microsoft.com>
Signed-off-by: Brian Chuo <brianchuo@microsoft.com>
3051b49 to
bf4842e
Compare
Signed-off-by: Brian Chuo <brianchuo@microsoft.com>
a57b35e to
6be759b
Compare
MorrisLaw
approved these changes
Apr 6, 2026
Collaborator
|
Ideally this would have been squashed into one commit before merge. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What this PR does / why we need it: In
scripts/gomod-patch.sh, line 113 usesgo work vendor -hto probe whether thego work vendorsubcommand is available (i.e., Go ≥ 1.22):if go work vendor -h >/dev/null 2>&1; thenThis check always fails because Go's CLI exits with code 2 when
-his passed to a subcommand (usage error convention), regardless of Go version. As a result, the script always falls through to theelsebranch and runsGOWORK=off go mod vendoreven on Go 1.26.For repositories using
go.work,GOWORK=off go mod vendoronly vendors the root module's import graph and silently misses any transitive dependencies that are only reachable through workspace sub-modules. In the case of Kubernetes (which has ~40 staging sub-modules undergo.work), this means modules likegithub.com/cncf/xds/goare not vendored, causing build failures at compile time withGOPROXY=off.Which issue(s) this PR fixes (optional, using
fixes #<issue number>(, fixes #<issue_number>, ...)format, will close the issue(s) when the PR gets merged):Fixes #1015
Special notes for your reviewer: