1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-19 20:57:53 +02:00

Merge branch 'master' into template

This commit is contained in:
Carlos Alexandro Becker 2017-12-27 09:58:42 -02:00
commit fcbe6a46ed
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
2 changed files with 27 additions and 3 deletions

View File

@ -4,8 +4,10 @@ package fpm
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
"github.com/apex/log"
"github.com/pkg/errors"
@ -21,7 +23,11 @@ import (
// ErrNoFPM is shown when fpm cannot be found in $PATH
var ErrNoFPM = errors.New("fpm not present in $PATH")
const defaultNameTemplate = "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
const (
defaultNameTemplate = "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
// path to gnu-tar on macOS when installed with homebrew
gnuTarPath = "/usr/local/opt/gnu-tar/libexec/gnubin"
)
// Pipe for fpm packaging
type Pipe struct{}
@ -122,8 +128,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{
@ -137,6 +142,19 @@ 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"))}
for _, env := range os.Environ() {
if strings.HasPrefix(env, "PATH=") {
continue
}
cmd.Env = append(cmd.Env, env)
}
return cmd
}
func basicOptions(ctx *context.Context, workdir, format, arch, file string) []string {
var options = []string{
"--input-type", "dir",

View File

@ -140,6 +140,12 @@ func TestCreateFileDoesntExist(t *testing.T) {
assert.Contains(t, Pipe{}.Run(ctx).Error(), `dist/mybin/mybin', does it exist?`)
}
func TestCmd(t *testing.T) {
cmd := cmd([]string{"--help"})
assert.NotEmpty(t, cmd.Env)
assert.Contains(t, cmd.Env[0], gnuTarPath)
}
func TestDefault(t *testing.T) {
var ctx = &context.Context{
Config: config.Project{