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

fixes to archiving and fpm

This commit is contained in:
Carlos Alexandro Becker 2017-07-01 12:58:48 -03:00
parent 3c68b894c5
commit 40fc46da92
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
2 changed files with 36 additions and 31 deletions

View File

@ -4,6 +4,7 @@
package archive package archive
import ( import (
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -11,7 +12,6 @@ import (
"github.com/apex/log" "github.com/apex/log"
"github.com/goreleaser/archive" "github.com/goreleaser/archive"
"github.com/goreleaser/goreleaser/context" "github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/internal/ext"
"github.com/mattn/go-zglob" "github.com/mattn/go-zglob"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
) )
@ -58,10 +58,13 @@ func create(ctx *context.Context, platform, name string) error {
return err return err
} }
} }
for _, build := range ctx.Config.Builds { var path = filepath.Join(ctx.Config.Dist, name)
var binary = build.Binary + ext.For(platform) binaries, err := ioutil.ReadDir(path)
var bin = filepath.Join(ctx.Config.Dist, name) if err != nil {
if err := archive.Add(binary, filepath.Join(bin, binary)); err != nil { return err
}
for _, binary := range binaries {
if err := archive.Add(binary.Name(), filepath.Join(path, binary.Name())); err != nil {
return err return err
} }
} }

View File

@ -4,19 +4,16 @@ package fpm
import ( import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strings"
"github.com/apex/log" "github.com/apex/log"
"github.com/goreleaser/goreleaser/context" "github.com/goreleaser/goreleaser/context"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
) )
var goarchToUnix = map[string]string{
"386": "i386",
"amd64": "x86_64",
}
// 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")
@ -41,30 +38,29 @@ func (Pipe) Run(ctx *context.Context) error {
var g errgroup.Group var g errgroup.Group
for _, format := range ctx.Config.FPM.Formats { for _, format := range ctx.Config.FPM.Formats {
for _, build := range ctx.Config.Builds { for key, folder := range ctx.Folders {
for _, goarch := range build.Goarch { folder := folder
var key = build.Binary + "linux" + goarch
// TODO: fix here
if ctx.Binaries[key] == "" {
continue
}
format := format format := format
// TODO: fix here arch := archFor(key)
archive := ctx.Binaries[key]
arch := goarchToUnix[goarch]
g.Go(func() error { g.Go(func() error {
return create(ctx, format, archive, arch) return create(ctx, format, folder, arch)
}) })
} }
} }
}
return g.Wait() return g.Wait()
} }
func create(ctx *context.Context, format, archive, arch string) error { func archFor(key string) string {
var path = filepath.Join(ctx.Config.Dist, archive) if strings.Contains(key, "386") {
return "i386"
}
return "x86_64"
}
func create(ctx *context.Context, format, folder, arch string) error {
var path = filepath.Join(ctx.Config.Dist, folder)
var file = path + "." + format var file = path + "." + format
log.WithField("file", file).Info("Creating") log.WithField("file", file).Info("creating fpm archive")
var options = []string{ var options = []string{
"--input-type", "dir", "--input-type", "dir",
@ -99,13 +95,19 @@ func create(ctx *context.Context, format, archive, arch string) error {
options = append(options, "--conflicts", conflict) options = append(options, "--conflicts", conflict)
} }
for _, build := range ctx.Config.Builds { files, err := ioutil.ReadDir(path)
if err != nil {
return err
}
for _, file := range files {
// XXX: skip non executable files here?
// This basically tells fpm to put the binary in the /usr/local/bin // This basically tells fpm to put the binary in the /usr/local/bin
// binary=/usr/local/bin/binary // binary=/usr/local/bin/binary
log.WithField("file", file.Name()).Debug("passed binary to fpm")
options = append(options, fmt.Sprintf( options = append(options, fmt.Sprintf(
"%s=%s", "%s=%s",
build.Binary, file.Name(),
filepath.Join("/usr/local/bin", build.Binary), filepath.Join("/usr/local/bin", file.Name()),
)) ))
} }