Skip to content

Commit

Permalink
fix(build): do not print 'go: downloading' bits of go build output (#…
Browse files Browse the repository at this point in the history
…4869)

this prevents printing `go: downloading` on go builds in case the mods
weren't previously downloaded...
  • Loading branch information
caarlos0 committed May 15, 2024
1 parent e466507 commit 9cf3bbb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
13 changes: 12 additions & 1 deletion internal/builders/golang/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,23 @@ func run(ctx *context.Context, command, env []string, dir string) error {
if err != nil {
return fmt.Errorf("%w: %s", err, string(out))
}
if s := strings.TrimSpace(string(out)); s != "" {
if s := buildOutput(out); s != "" {
log.Info(s)
}
return nil
}

func buildOutput(out []byte) string {
var lines []string
for _, line := range strings.Split(strings.TrimSpace(string(out)), "\n") {
if strings.HasPrefix(line, "go: downloading") {
continue
}
lines = append(lines, line)
}
return strings.Join(lines, "\n")
}

func checkMain(build config.Build) error {
if build.NoMainCheck {
return nil
Expand Down
19 changes: 19 additions & 0 deletions internal/builders/golang/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1433,6 +1433,25 @@ func TestInvalidGoBinaryTpl(t *testing.T) {
}))
}

func TestBuildOutput(t *testing.T) {
t.Run("empty", func(t *testing.T) {
require.Empty(t, buildOutput([]byte{}))
})
t.Run("downloading only", func(t *testing.T) {
require.Empty(t, buildOutput([]byte(`
go: downloading github.com/atotto/clipboard v0.1.4
go: downloading github.com/caarlos0/duration v0.0.0-20240108180406-5d492514f3c7
`)))
})
t.Run("mixed", func(t *testing.T) {
require.NotEmpty(t, buildOutput([]byte(`
go: downloading github.com/atotto/clipboard v0.1.4
go: downloading github.com/caarlos0/duration v0.0.0-20240108180406-5d492514f3c7
something something
`)))
})
}

//
// Helpers
//
Expand Down

0 comments on commit 9cf3bbb

Please sign in to comment.