1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00

fix: add the build artifact only if build succeeds

This commit is contained in:
Carlos Alexandro Becker 2017-12-18 21:04:25 -02:00
parent 306b84d040
commit b667490ce4
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
2 changed files with 23 additions and 14 deletions

View File

@ -109,6 +109,19 @@ func doBuild(ctx *context.Context, build config.Build, target buildtarget.Target
var ext = ext.For(target)
var binaryName = build.Binary + ext
var binary = filepath.Join(ctx.Config.Dist, target.String(), binaryName)
log.WithField("binary", binary).Info("building")
cmd := []string{"go", "build"}
if build.Flags != "" {
cmd = append(cmd, strings.Fields(build.Flags)...)
}
flags, err := ldflags(ctx, build)
if err != nil {
return err
}
cmd = append(cmd, "-ldflags="+flags, "-o", binary, build.Main)
if err := run(target, cmd, build.Env); err != nil {
return errors.Wrapf(err, "failed to build for %s", target)
}
ctx.Artifacts.Add(artifact.Artifact{
Type: artifact.Binary,
Path: binary,
@ -121,17 +134,7 @@ func doBuild(ctx *context.Context, build config.Build, target buildtarget.Target
"Ext": ext,
},
})
log.WithField("binary", binary).Info("building")
cmd := []string{"go", "build"}
if build.Flags != "" {
cmd = append(cmd, strings.Fields(build.Flags)...)
}
flags, err := ldflags(ctx, build)
if err != nil {
return err
}
cmd = append(cmd, "-ldflags="+flags, "-o", binary, build.Main)
return errors.Wrapf(run(target, cmd, build.Env), "failed to build for %s", target)
return nil
}
func run(target buildtarget.Target, command, env []string) error {

View File

@ -74,7 +74,9 @@ func TestRunFullPipe(t *testing.T) {
},
},
}
assert.NoError(t, Pipe{}.Run(context.New(config)))
var ctx = context.New(config)
assert.NoError(t, Pipe{}.Run(ctx))
assert.Len(t, ctx.Artifacts.List(), 1)
assert.True(t, exists(binary), binary)
assert.True(t, exists(pre), pre)
assert.True(t, exists(post), post)
@ -104,7 +106,9 @@ func TestRunPipeArmBuilds(t *testing.T) {
},
},
}
assert.NoError(t, Pipe{}.Run(context.New(config)))
var ctx = context.New(config)
assert.NoError(t, Pipe{}.Run(ctx))
assert.Len(t, ctx.Artifacts.List(), 2)
assert.True(t, exists(binary), binary)
}
@ -125,7 +129,9 @@ func TestBuildFailed(t *testing.T) {
},
},
}
assertContainsError(t, Pipe{}.Run(context.New(config)), `flag provided but not defined: -flag-that-dont-exists-to-force-failure`)
var ctx = context.New(config)
assertContainsError(t, Pipe{}.Run(ctx), `flag provided but not defined: -flag-that-dont-exists-to-force-failure`)
assert.Empty(t, ctx.Artifacts.List())
}
func TestRunPipeWithInvalidOS(t *testing.T) {