mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-08 03:31:59 +02:00
Merge pull request #492 from goreleaser/gnutar
fix: use gnu-tar on macOS
This commit is contained in:
commit
9068d941d0
@ -4,8 +4,10 @@ package fpm
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -21,6 +23,9 @@ import (
|
|||||||
// ErrNoFPM is shown when fpm cannot be found in $PATH
|
// ErrNoFPM is shown when fpm cannot be found in $PATH
|
||||||
var ErrNoFPM = errors.New("fpm not present 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
|
// Pipe for fpm packaging
|
||||||
type Pipe struct{}
|
type Pipe struct{}
|
||||||
|
|
||||||
@ -114,8 +119,7 @@ func create(ctx *context.Context, format, arch string, binaries []artifact.Artif
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.WithField("args", options).Debug("creating fpm package")
|
log.WithField("args", options).Debug("creating fpm package")
|
||||||
/* #nosec */
|
if out, err := cmd(options).CombinedOutput(); err != nil {
|
||||||
if out, err := exec.Command("fpm", options...).CombinedOutput(); err != nil {
|
|
||||||
return errors.Wrap(err, string(out))
|
return errors.Wrap(err, string(out))
|
||||||
}
|
}
|
||||||
ctx.Artifacts.Add(artifact.Artifact{
|
ctx.Artifacts.Add(artifact.Artifact{
|
||||||
@ -129,6 +133,19 @@ func create(ctx *context.Context, format, arch string, binaries []artifact.Artif
|
|||||||
return nil
|
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 {
|
func basicOptions(ctx *context.Context, workdir, format, arch, file string) []string {
|
||||||
var options = []string{
|
var options = []string{
|
||||||
"--input-type", "dir",
|
"--input-type", "dir",
|
||||||
|
@ -122,6 +122,12 @@ func TestCreateFileDoesntExist(t *testing.T) {
|
|||||||
assert.Error(t, Pipe{}.Run(ctx))
|
assert.Error(t, Pipe{}.Run(ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
func TestDefault(t *testing.T) {
|
||||||
var ctx = &context.Context{
|
var ctx = &context.Context{
|
||||||
Config: config.Project{
|
Config: config.Project{
|
||||||
|
Loading…
Reference in New Issue
Block a user