You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-07-17 01:42:37 +02:00
feat: Add ability to specify release name
Signed-off-by: Matt Stratton <matt.stratton@gmail.com>
This commit is contained in:
@ -116,9 +116,10 @@ type Archive struct {
|
|||||||
|
|
||||||
// Release config used for the GitHub release
|
// Release config used for the GitHub release
|
||||||
type Release struct {
|
type Release struct {
|
||||||
GitHub Repo `yaml:",omitempty"`
|
GitHub Repo `yaml:",omitempty"`
|
||||||
Draft bool `yaml:",omitempty"`
|
Draft bool `yaml:",omitempty"`
|
||||||
Prerelease bool `yaml:",omitempty"`
|
Prerelease bool `yaml:",omitempty"`
|
||||||
|
NameTemplate string `yaml:"name_template,omitempty"`
|
||||||
|
|
||||||
// Capture all undefined fields and should be empty after loading
|
// Capture all undefined fields and should be empty after loading
|
||||||
XXX map[string]interface{} `yaml:",inline"`
|
XXX map[string]interface{} `yaml:",inline"`
|
||||||
|
@ -23,6 +23,10 @@ release:
|
|||||||
# If set to true, will mark the release as not ready for production.
|
# If set to true, will mark the release as not ready for production.
|
||||||
# Default is false.
|
# Default is false.
|
||||||
prerelease: true
|
prerelease: true
|
||||||
|
|
||||||
|
# Optional template to name the release
|
||||||
|
# Default is the version number
|
||||||
|
name_template: "{{.ProjectName}}-v{{.Version}}"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Custom release notes
|
## Custom release notes
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
"github.com/google/go-github/github"
|
"github.com/google/go-github/github"
|
||||||
"github.com/goreleaser/goreleaser/context"
|
"github.com/goreleaser/goreleaser/context"
|
||||||
|
"github.com/goreleaser/goreleaser/internal/name"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -83,8 +84,12 @@ func (c *githubClient) CreateFile(
|
|||||||
|
|
||||||
func (c *githubClient) CreateRelease(ctx *context.Context, body string) (releaseID int, err error) {
|
func (c *githubClient) CreateRelease(ctx *context.Context, body string) (releaseID int, err error) {
|
||||||
var release *github.RepositoryRelease
|
var release *github.RepositoryRelease
|
||||||
|
releaseTitle, err := name.ForTitle(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
var data = &github.RepositoryRelease{
|
var data = &github.RepositoryRelease{
|
||||||
Name: github.String(ctx.Git.CurrentTag),
|
Name: github.String(releaseTitle),
|
||||||
TagName: github.String(ctx.Git.CurrentTag),
|
TagName: github.String(ctx.Git.CurrentTag),
|
||||||
Body: github.String(body),
|
Body: github.String(body),
|
||||||
Draft: github.Bool(ctx.Config.Release.Draft),
|
Draft: github.Bool(ctx.Config.Release.Draft),
|
||||||
|
@ -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) {
|
func apply(data nameData, templateStr string) (string, error) {
|
||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
t, err := template.New(data.ProjectName).Parse(templateStr)
|
t, err := template.New(data.ProjectName).Parse(templateStr)
|
||||||
|
@ -120,3 +120,22 @@ func TestNameDefaultTemplate(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNameForTitle(t *testing.T) {
|
||||||
|
var ctx = &context.Context{
|
||||||
|
Config: config.Project{
|
||||||
|
Release: config.Release{
|
||||||
|
NameTemplate: "{{.ProjectName}}-v{{.Version}}",
|
||||||
|
},
|
||||||
|
ProjectName: "test",
|
||||||
|
},
|
||||||
|
Version: "1.2.3",
|
||||||
|
Git: context.GitInfo{
|
||||||
|
CurrentTag: "v1.2.3",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
name, err := ForTitle(ctx)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, "test-v1.2.3", name)
|
||||||
|
}
|
||||||
|
@ -14,6 +14,9 @@ import (
|
|||||||
// NameTemplate default name_template for the archive.
|
// NameTemplate default name_template for the archive.
|
||||||
const NameTemplate = "{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
|
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.
|
// SnapshotNameTemplate represents the default format for snapshot release names.
|
||||||
const SnapshotNameTemplate = "SNAPSHOT-{{ .Commit }}"
|
const SnapshotNameTemplate = "SNAPSHOT-{{ .Commit }}"
|
||||||
|
|
||||||
@ -31,6 +34,9 @@ func (Pipe) Description() string {
|
|||||||
// Run the pipe
|
// Run the pipe
|
||||||
func (Pipe) Run(ctx *context.Context) error {
|
func (Pipe) Run(ctx *context.Context) error {
|
||||||
ctx.Config.Dist = "dist"
|
ctx.Config.Dist = "dist"
|
||||||
|
if ctx.Config.Release.NameTemplate == "" {
|
||||||
|
ctx.Config.Release.NameTemplate = ReleaseNameTemplate
|
||||||
|
}
|
||||||
if ctx.Config.Snapshot.NameTemplate == "" {
|
if ctx.Config.Snapshot.NameTemplate == "" {
|
||||||
ctx.Config.Snapshot.NameTemplate = SnapshotNameTemplate
|
ctx.Config.Snapshot.NameTemplate = SnapshotNameTemplate
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user