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

Stream go build output #436

Merged
merged 1 commit into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
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
10 changes: 3 additions & 7 deletions go_build_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,17 @@ func (p GoBuildProcess) Execute(config GoBuildConfiguration) ([]string, error) {
}
p.logs.Subprocess("Running '%s'", strings.Join(printedArgs, " "))

buffer := bytes.NewBuffer(nil)
duration, err := p.clock.Measure(func() error {
return p.executable.Execute(pexec.Execution{
Args: args,
Dir: config.Workspace,
Env: env,
Stdout: buffer,
Stderr: buffer,
Stdout: p.logs.ActionWriter,
Stderr: p.logs.ActionWriter,
})
})
if err != nil {
p.logs.Action("Failed after %s", duration.Round(time.Millisecond))
p.logs.Detail(buffer.String())

return nil, fmt.Errorf("failed to execute 'go build': %w", err)
}

Expand All @@ -98,7 +95,7 @@ func (p GoBuildProcess) Execute(config GoBuildConfiguration) ([]string, error) {

var paths []string
for _, target := range config.Targets {
buffer = bytes.NewBuffer(nil)
buffer := bytes.NewBuffer(nil)
Copy link
Member Author

Choose a reason for hiding this comment

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

We weren't logging anything about the go list process before, so I opted out of streaming the logs from that command to avoid cluttering the output. @paketo-buildpacks/go-maintainers let me know if you want me to add that.

Copy link
Member

Choose a reason for hiding this comment

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

Can you give an example of what the go list output would be? Do we show it in the case of failure?

Copy link
Contributor

Choose a reason for hiding this comment

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

go list is what we use to determine the number of a name of binaries that we are going to compile when running go build it helps us assign a process type to every built. probably does not need to be streamed.

err := p.executable.Execute(pexec.Execution{
Args: []string{"list", "--json", target},
Dir: config.Workspace,
Expand All @@ -108,7 +105,6 @@ func (p GoBuildProcess) Execute(config GoBuildConfiguration) ([]string, error) {
})
if err != nil {
p.logs.Detail(buffer.String())

return nil, fmt.Errorf("failed to execute 'go list': %w", err)
}

Expand Down
6 changes: 4 additions & 2 deletions go_build_process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ func testGoBuildProcess(t *testing.T, context spec.G, it spec.S) {
Expect(err).To(MatchError("failed to execute 'go build': command failed"))

Expect(logs).To(ContainLines(
" build error stdout",
" build error stderr",
" Failed after 1s",
" build error stdout",
" build error stderr",
))
})
})
Expand Down Expand Up @@ -278,6 +278,8 @@ func testGoBuildProcess(t *testing.T, context spec.G, it spec.S) {
Expect(err).To(MatchError("failed to execute 'go list': command failed"))

Expect(logs).To(ContainLines(
" Completed in 1s",
"",
" build error stdout",
" build error stderr",
))
Expand Down