diff --git a/config/config.go b/config/config.go index ee2922d3f..f37c4c1f8 100644 --- a/config/config.go +++ b/config/config.go @@ -116,9 +116,10 @@ type Archive struct { // Release config used for the GitHub release type Release struct { - GitHub Repo `yaml:",omitempty"` - Draft bool `yaml:",omitempty"` - Prerelease bool `yaml:",omitempty"` + GitHub Repo `yaml:",omitempty"` + Draft bool `yaml:",omitempty"` + Prerelease bool `yaml:",omitempty"` + NameTemplate string `yaml:",omitempty` // Capture all undefined fields and should be empty after loading XXX map[string]interface{} `yaml:",inline"` diff --git a/internal/name/name.go b/internal/name/name.go index ca5dbec12..e53a0a2be 100644 --- a/internal/name/name.go +++ b/internal/name/name.go @@ -67,6 +67,18 @@ func ForChecksums(ctx *context.Context) (string, error) { ) } +// ForTitle returns the release title based upon its template +func ForTitle(ctx *context.Context) (string, error) { + return apply{ + nameData{ + ProjectName: ctx.Config.ProjectName, + Tag: ctx.Git.CurrentTag, + Version: ctx.Version, + } + ctx.Config.Release.NameTemplate, + } +} + func apply(data nameData, templateStr string) (string, error) { var out bytes.Buffer t, err := template.New(data.ProjectName).Parse(templateStr) diff --git a/pipeline/defaults/defaults.go b/pipeline/defaults/defaults.go index e94ee24bb..9dbfce830 100644 --- a/pipeline/defaults/defaults.go +++ b/pipeline/defaults/defaults.go @@ -14,6 +14,9 @@ import ( // NameTemplate default name_template for the archive. const NameTemplate = "{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}" +// ReleaseNameTemplate is the default name for the release. +const ReleaseNameTemplate = "{{ .Version }}" + // SnapshotNameTemplate represents the default format for snapshot release names. const SnapshotNameTemplate = "SNAPSHOT-{{ .Commit }}" @@ -31,6 +34,9 @@ func (Pipe) Description() string { // Run the pipe func (Pipe) Run(ctx *context.Context) error { ctx.Config.Dist = "dist" + if ctx.Config.Release.NameTemplate == "" { + ctx.Config.Release.NameTemplate = ReleaseNameTemplate + } if ctx.Config.Snapshot.NameTemplate == "" { ctx.Config.Snapshot.NameTemplate = SnapshotNameTemplate }