Skip to content

Commit

Permalink
feat: allow to template builds.gobinary (#4454)
Browse files Browse the repository at this point in the history
closes #4453

TODO: tests
  • Loading branch information
caarlos0 committed Dec 5, 2023
1 parent 7e48196 commit 22fa994
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
7 changes: 4 additions & 3 deletions internal/pipe/build/build.go
Expand Up @@ -195,12 +195,13 @@ func buildOptionsForTarget(ctx *context.Context, build config.Build, target stri
Goamd64: goamd64,
}

binary, err := tmpl.New(ctx).WithBuildOptions(buildOpts).Apply(build.Binary)
if err != nil {
if err := tmpl.New(ctx).WithBuildOptions(buildOpts).ApplyAll(
&build.Binary,
&build.GoBinary,
); err != nil {
return nil, err
}

build.Binary = binary
name := build.Binary + ext
dir := fmt.Sprintf("%s_%s", build.ID, target)
if build.NoUniqueDistDir {
Expand Down
18 changes: 18 additions & 0 deletions internal/pipe/build/build_test.go
Expand Up @@ -570,6 +570,24 @@ func TestPipeOnBuild_hooksRunPerTarget(t *testing.T) {
require.FileExists(t, filepath.Join(tmpDir, "post-hook-windows_amd64"))
}

func TestPipeOnBuild_invalidGoBinary(t *testing.T) {
build := config.Build{
Builder: "fake",
GoBinary: "testing.v{{.XYZ}}",
Targets: []string{
"linux_amd64",
},
}
ctx := testctx.NewWithCfg(config.Project{
Builds: []config.Build{
build,
},
})
g := semerrgroup.New(ctx.Parallelism)
runPipeOnBuild(ctx, g, build)
testlib.RequireTemplateError(t, g.Wait())
}

func TestPipeOnBuild_invalidBinaryTpl(t *testing.T) {
build := config.Build{
Builder: "fake",
Expand Down
1 change: 1 addition & 0 deletions www/docs/customization/builds.md
Expand Up @@ -169,6 +169,7 @@ builds:
# It is safe to ignore this option in most cases.
#
# Default is "go"
# Templates: allowed (since v1.23).
gobinary: "go1.13.4"

# Sets the command to run to build.
Expand Down

0 comments on commit 22fa994

Please sign in to comment.