Skip to content

Commit

Permalink
fix: handle configs with no explicit targets on --single-target
Browse files Browse the repository at this point in the history
closes #4411
  • Loading branch information
caarlos0 committed Nov 7, 2023
1 parent 17393af commit c0b2be3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cmd/build.go
Expand Up @@ -260,8 +260,9 @@ func shouldBuild(build config.Build, goos, goarch string) bool {
return strings.HasPrefix(e, fmt.Sprintf("%s_%s", goos, goarch))
})
}
return slices.Contains(build.Goos, goos) &&
slices.Contains(build.Goarch, goarch)
return (len(build.Goos) == 0 && len(build.Goarch) == 0) ||
(slices.Contains(build.Goos, goos) &&
slices.Contains(build.Goarch, goarch))
}

func setupBuildID(ctx *context.Context, ids []string) error {
Expand Down
10 changes: 10 additions & 0 deletions cmd/build_test.go
Expand Up @@ -201,6 +201,16 @@ func TestBuildFlags(t *testing.T) {
require.Equal(t, []string{runtime.GOARCH}, result.Config.Builds[0].Goarch)
})

t.Run("default config", func(t *testing.T) {
ctx := testctx.NewWithCfg(config.Project{
Builds: []config.Build{{}},
})
require.NoError(t, setupBuildContext(ctx, opts))
require.Len(t, ctx.Config.Builds, 1)
require.Equal(t, []string{runtime.GOOS}, ctx.Config.Builds[0].Goos)
require.Equal(t, []string{runtime.GOARCH}, ctx.Config.Builds[0].Goarch)
})

t.Run("from env", func(t *testing.T) {
t.Setenv("GOOS", "linux")
t.Setenv("GOARCH", "arm64")
Expand Down

0 comments on commit c0b2be3

Please sign in to comment.