Skip to content

Commit

Permalink
feat: Add ability to specify release name
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Stratton <matt.stratton@gmail.com>
  • Loading branch information
mattstratton committed Oct 7, 2017
1 parent f8ced34 commit e2ee7c4
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 4 deletions.
7 changes: 4 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:"name_template,omitempty"`

// Capture all undefined fields and should be empty after loading
XXX map[string]interface{} `yaml:",inline"`
Expand Down
4 changes: 4 additions & 0 deletions docs/115-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ release:
# If set to true, will mark the release as not ready for production.
# Default is false.
prerelease: true

# Optional template to name the release
# Default is the version number
name_template: "{{.ProjectName}}-v{{.Version}}"
```
## Custom release notes
Expand Down
7 changes: 6 additions & 1 deletion internal/client/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/apex/log"
"github.com/google/go-github/github"
"github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/internal/name"
"golang.org/x/oauth2"
)

Expand Down Expand Up @@ -83,8 +84,12 @@ func (c *githubClient) CreateFile(

func (c *githubClient) CreateRelease(ctx *context.Context, body string) (releaseID int, err error) {
var release *github.RepositoryRelease
releaseTitle, err := name.ForTitle(ctx)
if err != nil {
return 0, err
}
var data = &github.RepositoryRelease{
Name: github.String(ctx.Git.CurrentTag),
Name: github.String(releaseTitle),
TagName: github.String(ctx.Git.CurrentTag),
Body: github.String(body),
Draft: github.Bool(ctx.Config.Release.Draft),
Expand Down
12 changes: 12 additions & 0 deletions internal/name/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions internal/name/name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
6 changes: 6 additions & 0 deletions pipeline/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"

Expand All @@ -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
}
Expand Down

0 comments on commit e2ee7c4

Please sign in to comment.