diff --git a/internal/artifact/artifact.go b/internal/artifact/artifact.go index ff61f5ad6..90ec632d4 100644 --- a/internal/artifact/artifact.go +++ b/internal/artifact/artifact.go @@ -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 diff --git a/internal/ext/ext.go b/internal/ext/ext.go index 0d9ee6611..b7e377e82 100644 --- a/internal/ext/ext.go +++ b/internal/ext/ext.go @@ -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 "" } diff --git a/internal/nametemplate/name.go b/internal/nametemplate/name.go index cdf35a7b0..fbfb0a64c 100644 --- a/internal/nametemplate/name.go +++ b/internal/nametemplate/name.go @@ -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) diff --git a/pipeline/archive/archive.go b/pipeline/archive/archive.go index 6b2127c7c..31e2acaad 100644 --- a/pipeline/archive/archive.go +++ b/pipeline/archive/archive.go @@ -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 diff --git a/pipeline/build/build.go b/pipeline/build/build.go index b6985f518..94c67f3a8 100644 --- a/pipeline/build/build.go +++ b/pipeline/build/build.go @@ -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"} diff --git a/pipeline/docker/docker.go b/pipeline/docker/docker.go index 0bdb0dfb1..a73a79583 100644 --- a/pipeline/docker/docker.go +++ b/pipeline/docker/docker.go @@ -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) { diff --git a/pipeline/fpm/fpm.go b/pipeline/fpm/fpm.go index d548f0fea..7aefdd25d 100644 --- a/pipeline/fpm/fpm.go +++ b/pipeline/fpm/fpm.go @@ -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 } diff --git a/pipeline/snapcraft/snapcraft.go b/pipeline/snapcraft/snapcraft.go index b4663f7b6..f8750bdf9 100644 --- a/pipeline/snapcraft/snapcraft.go +++ b/pipeline/snapcraft/snapcraft.go @@ -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 }