From a7a290fb63b57e280b1622d908c0dbf02614177f Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Tue, 26 Dec 2017 22:13:58 -0200 Subject: [PATCH 1/3] fix: use gnu-tar on macOS closes #409 --- pipeline/fpm/fpm.go | 14 ++++++++++++-- pipeline/fpm/fpm_test.go | 5 +++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pipeline/fpm/fpm.go b/pipeline/fpm/fpm.go index 2e7618442..846538c65 100644 --- a/pipeline/fpm/fpm.go +++ b/pipeline/fpm/fpm.go @@ -4,6 +4,7 @@ package fpm import ( "fmt" "io/ioutil" + "os" "os/exec" "path/filepath" @@ -21,6 +22,9 @@ import ( // ErrNoFPM is shown when fpm cannot be found in $PATH var ErrNoFPM = errors.New("fpm not present in $PATH") +// path to gnu-tar on macOS when installed with homebrew +const gnuTarPath = "/usr/local/opt/gnu-tar/libexec/gnubin" + // Pipe for fpm packaging type Pipe struct{} @@ -114,8 +118,7 @@ func create(ctx *context.Context, format, arch string, binaries []artifact.Artif } log.WithField("args", options).Debug("creating fpm package") - /* #nosec */ - if out, err := exec.Command("fpm", options...).CombinedOutput(); err != nil { + if out, err := cmd(options).CombinedOutput(); err != nil { return errors.Wrap(err, string(out)) } ctx.Artifacts.Add(artifact.Artifact{ @@ -129,6 +132,13 @@ func create(ctx *context.Context, format, arch string, binaries []artifact.Artif return nil } +func cmd(options []string) *exec.Cmd { + /* #nosec */ + var cmd = exec.Command("fpm", options...) + cmd.Env = []string{fmt.Sprintf("PATH=%s:%s", gnuTarPath, os.Getenv("PATH"))} + return cmd +} + func basicOptions(ctx *context.Context, workdir, format, arch, file string) []string { var options = []string{ "--input-type", "dir", diff --git a/pipeline/fpm/fpm_test.go b/pipeline/fpm/fpm_test.go index 8d1e35654..3357c6cde 100644 --- a/pipeline/fpm/fpm_test.go +++ b/pipeline/fpm/fpm_test.go @@ -122,6 +122,11 @@ func TestCreateFileDoesntExist(t *testing.T) { assert.Error(t, Pipe{}.Run(ctx)) } +func TestCmd(t *testing.T) { + cmd := cmd([]string{"--help"}) + assert.NotEmpty(t, cmd.Env) +} + func TestDefault(t *testing.T) { var ctx = &context.Context{ Config: config.Project{ From 3d93a2dfce02ddd337164abadcb45094dd6525bb Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Tue, 26 Dec 2017 22:18:01 -0200 Subject: [PATCH 2/3] test: improved fpm test --- pipeline/fpm/fpm_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pipeline/fpm/fpm_test.go b/pipeline/fpm/fpm_test.go index 3357c6cde..bc4479917 100644 --- a/pipeline/fpm/fpm_test.go +++ b/pipeline/fpm/fpm_test.go @@ -124,7 +124,8 @@ func TestCreateFileDoesntExist(t *testing.T) { func TestCmd(t *testing.T) { cmd := cmd([]string{"--help"}) - assert.NotEmpty(t, cmd.Env) + assert.Len(t, cmd.Env, 1) + assert.Contains(t, cmd.Env[0], gnuTarPath) } func TestDefault(t *testing.T) { From ba68011b55ccd04284e4b835e224b6806f65a84e Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 27 Dec 2017 09:32:24 -0200 Subject: [PATCH 3/3] fix: env --- pipeline/fpm/fpm.go | 7 +++++++ pipeline/fpm/fpm_test.go | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pipeline/fpm/fpm.go b/pipeline/fpm/fpm.go index 846538c65..31415850a 100644 --- a/pipeline/fpm/fpm.go +++ b/pipeline/fpm/fpm.go @@ -7,6 +7,7 @@ import ( "os" "os/exec" "path/filepath" + "strings" "github.com/apex/log" "github.com/pkg/errors" @@ -136,6 +137,12 @@ func cmd(options []string) *exec.Cmd { /* #nosec */ var cmd = exec.Command("fpm", options...) cmd.Env = []string{fmt.Sprintf("PATH=%s:%s", gnuTarPath, os.Getenv("PATH"))} + for _, env := range os.Environ() { + if strings.HasPrefix(env, "PATH=") { + continue + } + cmd.Env = append(cmd.Env, env) + } return cmd } diff --git a/pipeline/fpm/fpm_test.go b/pipeline/fpm/fpm_test.go index bc4479917..23cb51daa 100644 --- a/pipeline/fpm/fpm_test.go +++ b/pipeline/fpm/fpm_test.go @@ -124,7 +124,7 @@ func TestCreateFileDoesntExist(t *testing.T) { func TestCmd(t *testing.T) { cmd := cmd([]string{"--help"}) - assert.Len(t, cmd.Env, 1) + assert.NotEmpty(t, cmd.Env) assert.Contains(t, cmd.Env[0], gnuTarPath) }