1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/pipeline/archive/name.go

41 lines
1.1 KiB
Go
Raw Normal View History

2017-12-17 19:24:49 +02:00
package archive
import (
"bytes"
"text/template"
"github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/internal/buildtarget"
)
func nameFor(ctx *context.Context, target buildtarget.Target, name string) (string, error) {
var out bytes.Buffer
t, err := template.New(name).Parse(ctx.Config.Archive.NameTemplate)
if err != nil {
return "", err
}
data := struct {
Os, Arch, Arm, Version, Tag, Binary, ProjectName string
Env map[string]string
}{
Os: replace(ctx.Config.Archive.Replacements, target.OS),
Arch: replace(ctx.Config.Archive.Replacements, target.Arch),
Arm: replace(ctx.Config.Archive.Replacements, target.Arm),
Version: ctx.Version,
Tag: ctx.Git.CurrentTag,
Binary: name, // TODO: deprecated: remove this sometime
ProjectName: name,
Env: ctx.Env,
}
err = t.Execute(&out, data)
return out.String(), err
}
func replace(replacements map[string]string, original string) string {
result := replacements[original]
if result == "" {
return original
}
return result
}