1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-10-30 23:58:09 +02:00

fixes for multiple builds

This commit is contained in:
Carlos Alexandro Becker
2017-07-03 00:57:39 -03:00
parent 827adc83c3
commit 8915f8bbf6
4 changed files with 53 additions and 20 deletions

View File

@@ -43,8 +43,7 @@ var foldersLock sync.Mutex
func (ctx *Context) AddArtifact(file string) { func (ctx *Context) AddArtifact(file string) {
artifactsLock.Lock() artifactsLock.Lock()
defer artifactsLock.Unlock() defer artifactsLock.Unlock()
file = strings.TrimPrefix(file, ctx.Config.Dist) file = strings.TrimPrefix(file, ctx.Config.Dist+"/")
file = strings.Replace(file, "/", "", -1)
ctx.Artifacts = append(ctx.Artifacts, file) ctx.Artifacts = append(ctx.Artifacts, file)
log.WithField("artifact", file).Info("new artifact") log.WithField("artifact", file).Info("new artifact")
} }

View File

@@ -6,6 +6,7 @@ import (
"bytes" "bytes"
"text/template" "text/template"
"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context" "github.com/goreleaser/goreleaser/context"
) )
@@ -19,20 +20,40 @@ type nameData struct {
ProjectName string ProjectName string
} }
func ForBuild(ctx *context.Context, build config.Build, goos, goarch, goarm string) (string, error) {
return apply(
nameData{
Os: replace(ctx.Config.Archive.Replacements, goos),
Arch: replace(ctx.Config.Archive.Replacements, goarch),
Arm: replace(ctx.Config.Archive.Replacements, goarm),
Version: ctx.Version,
Tag: ctx.Git.CurrentTag,
Binary: build.Binary,
ProjectName: build.Binary,
},
ctx.Config.Archive.NameTemplate,
)
}
// For returns the name for the given context, goos, goarch and goarm. // For returns the name for the given context, goos, goarch and goarm.
func For(ctx *context.Context, goos, goarch, goarm string) (string, error) { func For(ctx *context.Context, goos, goarch, goarm string) (string, error) {
var data = nameData{ return apply(
Os: replace(ctx.Config.Archive.Replacements, goos), nameData{
Arch: replace(ctx.Config.Archive.Replacements, goarch), Os: replace(ctx.Config.Archive.Replacements, goos),
Arm: replace(ctx.Config.Archive.Replacements, goarm), Arch: replace(ctx.Config.Archive.Replacements, goarch),
Version: ctx.Version, Arm: replace(ctx.Config.Archive.Replacements, goarm),
Tag: ctx.Git.CurrentTag, Version: ctx.Version,
Binary: ctx.Config.ProjectName, Tag: ctx.Git.CurrentTag,
ProjectName: ctx.Config.ProjectName, Binary: ctx.Config.ProjectName,
} ProjectName: ctx.Config.ProjectName,
},
ctx.Config.Archive.NameTemplate,
)
}
func apply(data nameData, templateStr string) (string, error) {
var out bytes.Buffer var out bytes.Buffer
t, err := template.New(data.Binary).Parse(ctx.Config.Archive.NameTemplate) t, err := template.New(data.ProjectName).Parse(templateStr)
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@@ -12,7 +12,6 @@ import (
"github.com/goreleaser/archive" "github.com/goreleaser/archive"
"github.com/goreleaser/goreleaser/context" "github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/internal/archiveformat" "github.com/goreleaser/goreleaser/internal/archiveformat"
"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"
) )
@@ -33,9 +32,9 @@ func (Pipe) Run(ctx *context.Context) error {
platform := platform platform := platform
g.Go(func() error { g.Go(func() error {
if ctx.Config.Archive.Format == "binary" { if ctx.Config.Archive.Format == "binary" {
return skip(ctx, platform, archive) return skip(ctx, platform, folder)
} }
return create(ctx, platform, archive) return create(ctx, platform, folder)
}) })
} }
return g.Wait() return g.Wait()
@@ -77,10 +76,16 @@ func create(ctx *context.Context, platform, name string) error {
} }
func skip(ctx *context.Context, platform, name string) error { func skip(ctx *context.Context, platform, name string) error {
b := name + ext.For(platform) var path = filepath.Join(ctx.Config.Dist, name)
log.WithField("binary", b).Info("skip archiving") binaries, err := ioutil.ReadDir(path)
var binary = filepath.Join(ctx.Config.Dist, b) if err != nil {
ctx.AddArtifact(binary) return err
}
for _, binary := range binaries {
log.WithField("binary", binary.Name()).Info("skip archiving")
log.Infof("path: %v %v", path, binary.Name())
ctx.AddArtifact(filepath.Join(path+"/", binary.Name()))
}
return nil return nil
} }

View File

@@ -80,7 +80,15 @@ func doBuild(ctx *context.Context, build config.Build, target buildTarget) error
build.Binary+ext.For(target.goos), build.Binary+ext.For(target.goos),
) )
if ctx.Config.Archive.Format == "binary" { if ctx.Config.Archive.Format == "binary" {
binary = filepath.Join(ctx.Config.Dist, build.Binary+ext.For(target.goos)) bin, err := name.ForBuild(ctx, build, target.goos, target.goarch, target.goarm)
if err != nil {
return err
}
binary = filepath.Join(
ctx.Config.Dist,
folder,
bin+ext.For(target.goos),
)
} }
log.WithField("binary", binary).Info("building") log.WithField("binary", binary).Info("building")
cmd := []string{"go", "build"} cmd := []string{"go", "build"}