1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-24 04:16:27 +02:00

refactor: fixed fpm pipe

This commit is contained in:
Carlos Alexandro Becker 2017-12-17 17:11:08 -02:00
parent 1982259c29
commit 906c8b08e3
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
4 changed files with 43 additions and 24 deletions

View File

@ -17,6 +17,8 @@ const (
UploadableBinary
// Binary is a binary (output of a gobuild)
Binary
// LinuxPackage is a linux package generated by fpm or snapcraft
LinuxPackage
// DockerImage is a docker image
DockerImage
// Checksum is a checksum file
@ -58,7 +60,7 @@ func (a Artifact) Platform() string {
}
// GroupByPlatform groups the artifacts by their platform
func (artifacts *Artifacts) GroupByPlatform() map[string][]Artifact {
func (artifacts Artifacts) GroupByPlatform() map[string][]Artifact {
var result = map[string][]Artifact{}
for _, a := range artifacts.items {
result[a.Platform()] = append(result[a.Platform()], a)

View File

@ -1,4 +1,4 @@
package archive
package nametemplate
import (
"bytes"
@ -8,7 +8,7 @@ import (
"github.com/goreleaser/goreleaser/internal/artifact"
)
func nameFor(ctx *context.Context, a artifact.Artifact) (string, error) {
func Apply(ctx *context.Context, a artifact.Artifact) (string, error) {
var out bytes.Buffer
t, err := template.New("archive_name").Parse(ctx.Config.Archive.NameTemplate)
if err != nil {

View File

@ -16,6 +16,8 @@ import (
"github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/internal/archiveformat"
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/nametemplate"
"github.com/goreleaser/goreleaser/internal/nametemplate"
)
// Pipe for archive
@ -66,7 +68,7 @@ func (Pipe) Default(ctx *context.Context) error {
func create(ctx *context.Context, artifacts []artifact.Artifact) error {
var format = archiveformat.For(ctx, artifacts[0].Platform())
folder, err := nameFor(ctx, artifacts[0])
folder, err := nametemplate.Apply(ctx, artifacts[0])
if err != nil {
return err
}

View File

@ -6,14 +6,16 @@ import (
"io/ioutil"
"os/exec"
"path/filepath"
"strings"
"github.com/apex/log"
"github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/internal/linux"
"github.com/goreleaser/goreleaser/pipeline"
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
"github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/linux"
"github.com/goreleaser/goreleaser/internal/nametemplate"
"github.com/goreleaser/goreleaser/pipeline"
)
// ErrNoFPM is shown when fpm cannot be found in $PATH
@ -50,28 +52,34 @@ func doRun(ctx *context.Context) error {
var g errgroup.Group
sem := make(chan bool, ctx.Parallelism)
for _, format := range ctx.Config.FPM.Formats {
for platform, groups := range ctx.Binaries {
if !strings.Contains(platform, "linux") {
log.WithField("platform", platform).Debug("skipped non-linux builds for fpm")
continue
}
for platform, artifacts := range ctx.Artifacts.Filter(
artifact.And(
artifact.ByType(artifact.Binary),
artifact.ByGoos("linux"),
),
).GroupByPlatform() {
sem <- true
format := format
arch := linux.Arch(platform)
for folder, binaries := range groups {
g.Go(func() error {
defer func() {
<-sem
}()
return create(ctx, format, folder, arch, binaries)
})
}
arch := linux.Arch(platform) // TODO: could probably pass artifact.Goarch here
artifacts := artifacts
g.Go(func() error {
defer func() {
<-sem
}()
return create(ctx, format, arch, artifacts)
})
}
}
return g.Wait()
}
func create(ctx *context.Context, format, folder, arch string, binaries []context.Binary) error {
func create(ctx *context.Context, format, arch string, binaries []artifact.Artifact) error {
// TODO: should add template support here probably... for now, let's use
// archive's template
folder, err := nametemplate.Apply(ctx, binaries[0])
if err != nil {
return err
}
var path = filepath.Join(ctx.Config.Dist, folder)
var file = path + "." + format
var log = log.WithField("format", format).WithField("arch", arch)
@ -111,7 +119,14 @@ func create(ctx *context.Context, format, folder, arch string, binaries []contex
if out, err := exec.Command("fpm", options...).CombinedOutput(); err != nil {
return errors.Wrap(err, string(out))
}
ctx.AddArtifact(file)
ctx.Artifacts.Add(artifact.Artifact{
Type: artifact.LinuxPackage,
Name: folder + "." + format,
Path: file,
Goos: binaries[0].Goos,
Goarch: binaries[0].Goarch,
Goarm: binaries[0].Goarm,
})
return nil
}