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)

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.
  • Loading branch information
AndersonQ authored Jan 22, 2024
1 parent 74ba4c4 commit bccb12e
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 bccb12e

Please sign in to comment.