You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-07-03 00:57:43 +02:00
refactor: small fixes here and there
This commit is contained in:
@ -35,6 +35,7 @@ type Artifact struct {
|
|||||||
Goarch string
|
Goarch string
|
||||||
Goarm string
|
Goarm string
|
||||||
Type Type
|
Type Type
|
||||||
|
Extra map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Artifacts is a list of artifacts
|
// Artifacts is a list of artifacts
|
||||||
@ -74,6 +75,9 @@ func (artifacts Artifacts) GroupByPlatform() map[string][]Artifact {
|
|||||||
func (artifacts *Artifacts) Add(a Artifact) {
|
func (artifacts *Artifacts) Add(a Artifact) {
|
||||||
artifacts.lock.Lock()
|
artifacts.lock.Lock()
|
||||||
defer artifacts.lock.Unlock()
|
defer artifacts.lock.Unlock()
|
||||||
|
log.WithFields(log.Fields{
|
||||||
|
"artifact": a,
|
||||||
|
}).Info("added new artifact")
|
||||||
artifacts.items = append(artifacts.items, a)
|
artifacts.items = append(artifacts.items, a)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,8 +145,7 @@ func (artifacts *Artifacts) Filter(filter Filter) Artifacts {
|
|||||||
var result = New()
|
var result = New()
|
||||||
for _, a := range artifacts.items {
|
for _, a := range artifacts.items {
|
||||||
if filter(a) {
|
if filter(a) {
|
||||||
log.Infof("adding %v", a)
|
result.items = append(result.items, a)
|
||||||
result.Add(a)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
@ -4,8 +4,12 @@ import "github.com/goreleaser/goreleaser/internal/buildtarget"
|
|||||||
|
|
||||||
// For returns the binary extension for the given platform
|
// For returns the binary extension for the given platform
|
||||||
func For(target buildtarget.Target) (ext string) {
|
func For(target buildtarget.Target) (ext string) {
|
||||||
if target.OS == "windows" {
|
return ForOS(target.OS)
|
||||||
ext = ".exe"
|
}
|
||||||
}
|
|
||||||
return
|
func ForOS(os string) string {
|
||||||
|
if os == "windows" {
|
||||||
|
return ".exe"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
"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
|
var out bytes.Buffer
|
||||||
t, err := template.New("archive_name").Parse(ctx.Config.Archive.NameTemplate)
|
t, err := template.New("archive_name").Parse(ctx.Config.Archive.NameTemplate)
|
||||||
if err != nil {
|
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),
|
Arm: replace(ctx.Config.Archive.Replacements, a.Goarm),
|
||||||
Version: ctx.Version,
|
Version: ctx.Version,
|
||||||
Tag: ctx.Git.CurrentTag,
|
Tag: ctx.Git.CurrentTag,
|
||||||
ProjectName: ctx.Config.ProjectName,
|
ProjectName: name,
|
||||||
Env: ctx.Env,
|
Env: ctx.Env,
|
||||||
}
|
}
|
||||||
err = t.Execute(&out, data)
|
err = t.Execute(&out, data)
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
"github.com/mattn/go-zglob"
|
"github.com/mattn/go-zglob"
|
||||||
@ -16,6 +17,7 @@ import (
|
|||||||
"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/artifact"
|
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||||
|
"github.com/goreleaser/goreleaser/internal/ext"
|
||||||
"github.com/goreleaser/goreleaser/internal/nametemplate"
|
"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 {
|
func create(ctx *context.Context, artifacts []artifact.Artifact) error {
|
||||||
var format = archiveformat.For(ctx, artifacts[0].Platform())
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -117,7 +119,14 @@ func create(ctx *context.Context, artifacts []artifact.Artifact) error {
|
|||||||
func skip(ctx *context.Context, artifacts []artifact.Artifact) error {
|
func skip(ctx *context.Context, artifacts []artifact.Artifact) error {
|
||||||
for _, a := range artifacts {
|
for _, a := range artifacts {
|
||||||
log.WithField("binary", a.Name).Info("skip archiving")
|
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.Type = artifact.UploadableBinary
|
||||||
|
a.Name = name + ext.ForOS(a.Goos)
|
||||||
ctx.Artifacts.Add(a)
|
ctx.Artifacts.Add(a)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -115,6 +115,9 @@ func doBuild(ctx *context.Context, build config.Build, target buildtarget.Target
|
|||||||
Goos: target.OS,
|
Goos: target.OS,
|
||||||
Goarch: target.Arch,
|
Goarch: target.Arch,
|
||||||
Goarm: target.Arm,
|
Goarm: target.Arm,
|
||||||
|
Extra: map[string]string{
|
||||||
|
"Binary": build.Binary,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
log.WithField("binary", binary).Info("building")
|
log.WithField("binary", binary).Info("building")
|
||||||
cmd := []string{"go", "build"}
|
cmd := []string{"go", "build"}
|
||||||
|
@ -68,17 +68,22 @@ func (Pipe) Run(ctx *context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func doRun(ctx *context.Context) error {
|
func doRun(ctx *context.Context) error {
|
||||||
|
// TODO: could be done in parallel.
|
||||||
for _, docker := range ctx.Config.Dockers {
|
for _, docker := range ctx.Config.Dockers {
|
||||||
var binaries = ctx.Artifacts.Filter(
|
var binaries = ctx.Artifacts.Filter(
|
||||||
artifact.And(
|
artifact.And(
|
||||||
artifact.ByGoos(docker.Goos),
|
artifact.ByGoos(docker.Goos),
|
||||||
artifact.ByGoarch(docker.Goarch),
|
artifact.ByGoarch(docker.Goarch),
|
||||||
artifact.ByGoarm(docker.Goarm),
|
artifact.ByGoarm(docker.Goarm),
|
||||||
|
// artifact.ByType(artifact.Binary),
|
||||||
func(a artifact.Artifact) bool {
|
func(a artifact.Artifact) bool {
|
||||||
return a.Name == docker.Binary
|
return a.Extra["Binary"] == docker.Binary
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
).List()
|
).List()
|
||||||
|
if len(binaries) == 0 {
|
||||||
|
log.Warn("no binaries found")
|
||||||
|
}
|
||||||
for _, binary := range binaries {
|
for _, binary := range binaries {
|
||||||
var err = process(ctx, docker, binary)
|
var err = process(ctx, docker, binary)
|
||||||
if err != nil && !pipeline.IsSkip(err) {
|
if err != nil && !pipeline.IsSkip(err) {
|
||||||
|
@ -76,7 +76,7 @@ func doRun(ctx *context.Context) error {
|
|||||||
func create(ctx *context.Context, format, arch string, binaries []artifact.Artifact) 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
|
// TODO: should add template support here probably... for now, let's use
|
||||||
// archive's template
|
// archive's template
|
||||||
folder, err := nametemplate.Apply(ctx, binaries[0])
|
folder, err := nametemplate.Apply(ctx, binaries[0], ctx.Config.ProjectName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ func create(ctx *context.Context, arch string, binaries []artifact.Artifact) err
|
|||||||
var log = log.WithField("arch", arch)
|
var log = log.WithField("arch", arch)
|
||||||
// TODO: should add template support here probably... for now, let's use
|
// TODO: should add template support here probably... for now, let's use
|
||||||
// archive's template
|
// archive's template
|
||||||
folder, err := nametemplate.Apply(ctx, binaries[0])
|
folder, err := nametemplate.Apply(ctx, binaries[0], ctx.Config.ProjectName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user