Skip to content

Commit 9db5527

Browse files
Disable Go Workspaces when executing 'go list' in agent packaging process (#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 <anderson.queiroz@elastic.co>
1 parent 84d27d9 commit 9db5527

File tree

1 file changed

+8
-2
lines changed
  • dev-tools/mage/gotool

1 file changed

+8
-2
lines changed

dev-tools/mage/gotool/go.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,18 @@ var Test goTest = runGoTest
4545

4646
// GetModuleName returns the name of the module.
4747
func GetModuleName() (string, error) {
48-
lines, err := getLines(callGo(nil, "list", "-m"))
48+
lines, err := getLines(callGo(
49+
// Disabling the Go workspaces prevents 'go list' from listing all
50+
// modules within the workspace.
51+
map[string]string{"GOWORK": "off"},
52+
"list",
53+
"-m"))
4954
if err != nil {
5055
return "", err
5156
}
5257
if len(lines) != 1 {
53-
return "", fmt.Errorf("unexpected number of lines")
58+
return "", fmt.Errorf("expected 'go list -m' to return 1 line, got %d",
59+
len(lines))
5460
}
5561
return lines[0], nil
5662
}

0 commit comments

Comments
 (0)