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

refactor: small fixes here and there

This commit is contained in:
Carlos Alexandro Becker 2017-12-17 18:01:58 -02:00
parent 24f186a63c
commit 32fbebcc58
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
8 changed files with 36 additions and 12 deletions

View File

@ -35,6 +35,7 @@ type Artifact struct {
Goarch string
Goarm string
Type Type
Extra map[string]string
}
// Artifacts is a list of artifacts
@ -74,6 +75,9 @@ func (artifacts Artifacts) GroupByPlatform() map[string][]Artifact {
func (artifacts *Artifacts) Add(a Artifact) {
artifacts.lock.Lock()
defer artifacts.lock.Unlock()
log.WithFields(log.Fields{
"artifact": a,
}).Info("added new artifact")
artifacts.items = append(artifacts.items, a)
}
@ -141,8 +145,7 @@ func (artifacts *Artifacts) Filter(filter Filter) Artifacts {
var result = New()
for _, a := range artifacts.items {
if filter(a) {
log.Infof("adding %v", a)
result.Add(a)
result.items = append(result.items, a)
}
}
return result

View File

@ -4,8 +4,12 @@ import "github.com/goreleaser/goreleaser/internal/buildtarget"
// For returns the binary extension for the given platform
func For(target buildtarget.Target) (ext string) {
if target.OS == "windows" {
ext = ".exe"
}
return
return ForOS(target.OS)
}
func ForOS(os string) string {
if os == "windows" {
return ".exe"
}
return ""
}

View File

@ -8,7 +8,7 @@ import (
"github.com/goreleaser/goreleaser/internal/artifact"
)
func Apply(ctx *context.Context, a artifact.Artifact) (string, error) {
func Apply(ctx *context.Context, a artifact.Artifact, name string) (string, error) {
var out bytes.Buffer
t, err := template.New("archive_name").Parse(ctx.Config.Archive.NameTemplate)
if err != nil {
@ -23,7 +23,7 @@ func Apply(ctx *context.Context, a artifact.Artifact) (string, error) {
Arm: replace(ctx.Config.Archive.Replacements, a.Goarm),
Version: ctx.Version,
Tag: ctx.Git.CurrentTag,
ProjectName: ctx.Config.ProjectName,
ProjectName: name,
Env: ctx.Env,
}
err = t.Execute(&out, data)

View File

@ -7,6 +7,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/apex/log"
"github.com/mattn/go-zglob"
@ -16,6 +17,7 @@ import (
"github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/internal/archiveformat"
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/internal/ext"
"github.com/goreleaser/goreleaser/internal/nametemplate"
)
@ -67,7 +69,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 := nametemplate.Apply(ctx, artifacts[0])
folder, err := nametemplate.Apply(ctx, artifacts[0], ctx.Config.ProjectName)
if err != nil {
return err
}
@ -117,7 +119,14 @@ func create(ctx *context.Context, artifacts []artifact.Artifact) error {
func skip(ctx *context.Context, artifacts []artifact.Artifact) error {
for _, a := range artifacts {
log.WithField("binary", a.Name).Info("skip archiving")
// TODO: this should not happen here, maybe add another extra field
// for the extension and/or name without extension?
name, err := nametemplate.Apply(ctx, a, strings.TrimSuffix(a.Name, ".exe"))
if err != nil {
return err
}
a.Type = artifact.UploadableBinary
a.Name = name + ext.ForOS(a.Goos)
ctx.Artifacts.Add(a)
}
return nil

View File

@ -115,6 +115,9 @@ func doBuild(ctx *context.Context, build config.Build, target buildtarget.Target
Goos: target.OS,
Goarch: target.Arch,
Goarm: target.Arm,
Extra: map[string]string{
"Binary": build.Binary,
},
})
log.WithField("binary", binary).Info("building")
cmd := []string{"go", "build"}

View File

@ -68,17 +68,22 @@ func (Pipe) Run(ctx *context.Context) error {
}
func doRun(ctx *context.Context) error {
// TODO: could be done in parallel.
for _, docker := range ctx.Config.Dockers {
var binaries = ctx.Artifacts.Filter(
artifact.And(
artifact.ByGoos(docker.Goos),
artifact.ByGoarch(docker.Goarch),
artifact.ByGoarm(docker.Goarm),
// artifact.ByType(artifact.Binary),
func(a artifact.Artifact) bool {
return a.Name == docker.Binary
return a.Extra["Binary"] == docker.Binary
},
),
).List()
if len(binaries) == 0 {
log.Warn("no binaries found")
}
for _, binary := range binaries {
var err = process(ctx, docker, binary)
if err != nil && !pipeline.IsSkip(err) {

View File

@ -76,7 +76,7 @@ func doRun(ctx *context.Context) 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])
folder, err := nametemplate.Apply(ctx, binaries[0], ctx.Config.ProjectName)
if err != nil {
return err
}

View File

@ -92,7 +92,7 @@ func create(ctx *context.Context, arch string, binaries []artifact.Artifact) err
var log = log.WithField("arch", arch)
// TODO: should add template support here probably... for now, let's use
// archive's template
folder, err := nametemplate.Apply(ctx, binaries[0])
folder, err := nametemplate.Apply(ctx, binaries[0], ctx.Config.ProjectName)
if err != nil {
return err
}