Skip to content

Commit

Permalink
Disable Go Workspaces when executing 'go list' in packaging process (e…
Browse files Browse the repository at this point in the history
…lastic#37579)

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 and Scholar-Li committed Feb 5, 2024
1 parent 91b1660 commit f43bb61
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions dev-tools/mage/gotool/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,19 @@ 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 workspace 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 f43bb61

Please sign in to comment.