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

fix: do not copy binary by default #2916

Merged
merged 2 commits into from
Feb 19, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/build.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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