Skip to content

Commit

Permalink
fix: do not copy binary by default (#2916)
Browse files Browse the repository at this point in the history
* fix: do not copy binary by default

closes #2913

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* chore: ref

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Feb 19, 2022
1 parent 9954786 commit d6813ce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
6 changes: 3 additions & 3 deletions cmd/build.go
Expand Up @@ -94,7 +94,7 @@ defaulting to the current's machine target if not set.
cmd.Flags().BoolVar(&root.opts.singleTarget, "single-target", false, "Builds only for current GOOS and GOARCH")
cmd.Flags().StringVar(&root.opts.id, "id", "", "Builds only the specified build id")
cmd.Flags().BoolVar(&root.opts.deprecated, "deprecated", false, "Force print the deprecation message - tests only")
cmd.Flags().StringVarP(&root.opts.output, "output", "o", "", "Path to the binary, defaults to the distribution folder according to configs. Only taked into account when using --single-target and a single id (either with --id or if config only has one build)")
cmd.Flags().StringVarP(&root.opts.output, "output", "o", "", "Copy the binary to thie path after the build. Only taked into account when using --single-target and a single id (either with --id or if config only has one build)")
_ = cmd.Flags().MarkHidden("deprecated")

root.cmd = cmd
Expand Down Expand Up @@ -129,7 +129,7 @@ func buildProject(options buildOpts) (*context.Context, error) {
}

func setupPipeline(ctx *context.Context, options buildOpts) []pipeline.Piper {
if options.singleTarget && (options.id != "" || len(ctx.Config.Builds) == 1) {
if options.output != "" && options.singleTarget && (options.id != "" || len(ctx.Config.Builds) == 1) {
return append(pipeline.BuildCmdPipeline, withOutputPipe{options.output})
}
return pipeline.BuildCmdPipeline
Expand Down Expand Up @@ -216,7 +216,7 @@ func (w withOutputPipe) String() string {
func (w withOutputPipe) Run(ctx *context.Context) error {
path := ctx.Artifacts.Filter(artifact.ByType(artifact.Binary)).List()[0].Path
out := w.output
if out == "" {
if out == "." {
out = filepath.Base(path)
}
return gio.Copy(path, out)
Expand Down
16 changes: 14 additions & 2 deletions cmd/build_test.go
Expand Up @@ -63,18 +63,30 @@ func TestSetupPipeline(t *testing.T) {
t.Run("single-target and id", func(t *testing.T) {
require.Equal(
t,
append(pipeline.BuildCmdPipeline, withOutputPipe{""}),
pipeline.BuildCmdPipeline,
setupPipeline(context.New(config.Project{}), buildOpts{
singleTarget: true,
id: "foo",
}),
)
})

t.Run("single-target and id, given output", func(t *testing.T) {
require.Equal(
t,
append(pipeline.BuildCmdPipeline, withOutputPipe{"foobar"}),
setupPipeline(context.New(config.Project{}), buildOpts{
singleTarget: true,
id: "foo",
output: ".",
}),
)
})

t.Run("single-target and single build on config", func(t *testing.T) {
require.Equal(
t,
append(pipeline.BuildCmdPipeline, withOutputPipe{""}),
pipeline.BuildCmdPipeline,
setupPipeline(
context.New(config.Project{
Builds: []config.Build{{}},
Expand Down

0 comments on commit d6813ce

Please sign in to comment.