2017-12-17 19:24:49 +02:00
|
|
|
package archive
|
2017-12-03 01:58:55 +02:00
|
|
|
|
|
|
|
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
|
2017-12-03 03:27:44 +02:00
|
|
|
t, err := template.New(name).Parse(ctx.Config.Archive.NameTemplate)
|
2017-12-03 01:58:55 +02:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
data := struct {
|
2017-12-03 02:43:46 +02:00
|
|
|
Os, Arch, Arm, Version, Tag, Binary, ProjectName string
|
2017-12-06 22:46:11 +02:00
|
|
|
Env map[string]string
|
2017-12-03 01:58:55 +02:00
|
|
|
}{
|
|
|
|
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,
|
2017-12-03 02:43:46 +02:00
|
|
|
Binary: name, // TODO: deprecated: remove this sometime
|
2017-12-03 01:58:55 +02:00
|
|
|
ProjectName: name,
|
2017-12-06 22:46:11 +02:00
|
|
|
Env: ctx.Env,
|
2017-12-03 01:58:55 +02:00
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|