Skip to content

Commit

Permalink
Disable Go Workspaces when executing 'go list' in agent packaging pro…
Browse files Browse the repository at this point in the history
…cess (#4039) (#4113)

running 'go list' with Go worspaces enabled will report all modules listed on go.work, what would make GetModuleName to fail as it requires 'go list' to return only one module, the agent itself.

(cherry picked from commit bccb12e)

Co-authored-by: Anderson Queiroz <[email protected]>
  • Loading branch information
mergify[bot] and AndersonQ authored Jan 31, 2024
1 parent 84d27d9 commit 9db5527
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions dev-tools/mage/gotool/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,18 @@ var Test goTest = runGoTest

// GetModuleName returns the name of the module.
func GetModuleName() (string, error) {
lines, err := getLines(callGo(nil, "list", "-m"))
lines, err := getLines(callGo(
// Disabling the Go workspaces prevents 'go list' from listing all
// modules within the workspace.
map[string]string{"GOWORK": "off"},
"list",
"-m"))
if err != nil {
return "", err
}
if len(lines) != 1 {
return "", fmt.Errorf("unexpected number of lines")
return "", fmt.Errorf("expected 'go list -m' to return 1 line, got %d",
len(lines))
}
return lines[0], nil
}
Expand Down

0 comments on commit 9db5527

Please sign in to comment.