Skip to content

Fix go work vendor command to exit with correct code#1016

Merged
bchuo merged 6 commits into
project-dalec:mainfrom
bchuo:BrianC/fix-gomod-patch-script
Apr 6, 2026
Merged

Fix go work vendor command to exit with correct code#1016
bchuo merged 6 commits into
project-dalec:mainfrom
bchuo:BrianC/fix-gomod-patch-script

Conversation

@bchuo

@bchuo bchuo commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

What this PR does / why we need it: In scripts/gomod-patch.sh, line 113 uses go work vendor -h to probe whether the go work vendor subcommand is available (i.e., Go ≥ 1.22):

if go work vendor -h >/dev/null 2>&1; then
This check always fails because Go's CLI exits with code 2 when -h is passed to a subcommand (usage error convention), regardless of Go version. As a result, the script always falls through to the else branch and runs GOWORK=off go mod vendor even on Go 1.26.

For repositories using go.work, GOWORK=off go mod vendor only 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 under go.work), this means modules like github.com/cncf/xds/go are not vendored, causing build failures at compile time with GOPROXY=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:

Copilot AI review requested due to automatic review settings March 31, 2026 15:42
@bchuo bchuo force-pushed the BrianC/fix-gomod-patch-script branch from 89bfef0 to 0bebdc2 Compare March 31, 2026 15:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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) with go help work vendor as the availability probe.
  • Ensure go work vendor is used when supported, avoiding incomplete vendoring when using Go workspaces.

Comment thread scripts/gomod-patch.sh
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we add some tests to cover this code path?

bchuo added 3 commits April 1, 2026 11:55
…stead of 2

Signed-off-by: Brian Chuo <brianchuo@microsoft.com>
Signed-off-by: Brian Chuo <brianchuo@microsoft.com>
Signed-off-by: Brian Chuo <brianchuo@microsoft.com>
@bchuo bchuo force-pushed the BrianC/fix-gomod-patch-script branch from fb427ff to f1c02bd Compare April 1, 2026 15:55
bchuo added 2 commits April 1, 2026 14:07
Signed-off-by: Brian Chuo <brianchuo@microsoft.com>
Signed-off-by: Brian Chuo <brianchuo@microsoft.com>
@bchuo bchuo force-pushed the BrianC/fix-gomod-patch-script branch from 3051b49 to bf4842e Compare April 1, 2026 19:29
Signed-off-by: Brian Chuo <brianchuo@microsoft.com>
@bchuo bchuo force-pushed the BrianC/fix-gomod-patch-script branch from a57b35e to 6be759b Compare April 2, 2026 18:40
@bchuo bchuo merged commit 00477ac into project-dalec:main Apr 6, 2026
25 checks passed
@cpuguy83

cpuguy83 commented Apr 6, 2026

Copy link
Copy Markdown
Collaborator

Ideally this would have been squashed into one commit before merge.
Nothing breaking here, just makes the commit history less clean (and harder to cherry-pick).

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.

[BUG] gomod-patch.sh: go work vendor availability check always fails due to incorrect exit code assumption

5 participants