Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[systemtest] Get repo root correctly with go workspaces #13355

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion systemtest/apmservertest/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,18 @@ func getRepoRoot() (string, error) {
if err != nil {
return "", err
}
repoRoot = filepath.Clean(strings.TrimSpace(string(output)))
// When go workspaces is enabled then go list lists all the module paths in
Copy link
Member

Choose a reason for hiding this comment

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

Would go list -f '{{.Module.Dir}}' . work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't use this because, IIANM, this will only work if we run the command in the same directory as the go.mod file and I assumed that would not be desirable as in that case we could have used something like os.Getwd

Copy link
Member

Choose a reason for hiding this comment

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

OK. Maybe we could use https://pkg.go.dev/runtime#Caller to locate the source code, and then the repo root relative to that. Not very robust to code changes/moving around, but I don't think that should happen often if at all.

// the go workspace. This is hack to ensure we take what we required.
// TODO (lahsivjar): Better way to find repo root?
allPaths := strings.Split(strings.TrimSpace(string(output)), "\n")
var targetPath string
for _, path := range allPaths {
if strings.HasSuffix(path, "systemtest/..") {
targetPath = path
break
}
}
repoRoot = filepath.Clean(targetPath)
return repoRoot, nil
}

Expand Down