mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-02-03 13:11:48 +02:00
improvements
This commit is contained in:
parent
86e39b6324
commit
69767ec798
@ -17,23 +17,22 @@ import (
|
||||
|
||||
// GitInfo includes tags and diffs used in some point
|
||||
type GitInfo struct {
|
||||
CurrentTag string
|
||||
PreviousTag string
|
||||
Commit string
|
||||
CurrentTag string
|
||||
Commit string
|
||||
}
|
||||
|
||||
// Context carries along some data through the pipes
|
||||
type Context struct {
|
||||
ctx.Context
|
||||
Config config.Project
|
||||
Token string
|
||||
Git GitInfo
|
||||
Archives map[string]string
|
||||
Artifacts []string
|
||||
Changelog string
|
||||
Version string
|
||||
Validate bool
|
||||
Publish bool
|
||||
Config config.Project
|
||||
Token string
|
||||
Git GitInfo
|
||||
Archives map[string]string
|
||||
Artifacts []string
|
||||
ReleaseNotes string
|
||||
Version string
|
||||
Validate bool
|
||||
Publish bool
|
||||
}
|
||||
|
||||
var lock sync.Mutex
|
||||
|
2
main.go
2
main.go
@ -55,7 +55,7 @@ func main() {
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "release-notes",
|
||||
Usage: "Define a file with custom release notes to be used instead of the git log between tags",
|
||||
Usage: "Path to a markdown file with custom release notes",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "skip-validate",
|
||||
|
@ -47,21 +47,20 @@ func (Pipe) Description() string {
|
||||
|
||||
// Run the pipe
|
||||
func (Pipe) Run(ctx *context.Context) (err error) {
|
||||
tag, prev, commit, err := getInfo()
|
||||
tag, commit, err := getInfo()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
ctx.Git = context.GitInfo{
|
||||
CurrentTag: tag,
|
||||
PreviousTag: prev,
|
||||
Commit: commit,
|
||||
CurrentTag: tag,
|
||||
Commit: commit,
|
||||
}
|
||||
if ctx.Changelog == "" {
|
||||
log, err := git("log", "--pretty=oneline", "--abbrev-commit", prev+".."+tag)
|
||||
if ctx.ReleaseNotes == "" {
|
||||
log, err := getChangelog(tag)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ctx.Changelog = log
|
||||
ctx.ReleaseNotes = fmt.Sprintf("## Changelog\n\n%v", log)
|
||||
}
|
||||
// removes usual `v` prefix
|
||||
ctx.Version = strings.TrimPrefix(tag, "v")
|
||||
@ -87,12 +86,16 @@ func validate(commit, tag, version string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func getInfo() (tag, prev, commit string, err error) {
|
||||
tag, err = cleanGit("describe", "--tags", "--abbrev=0", "--always")
|
||||
func getChangelog(tag string) (string, error) {
|
||||
prev, err := previous(tag)
|
||||
if err != nil {
|
||||
return
|
||||
return "", err
|
||||
}
|
||||
prev, err = previous(tag)
|
||||
return git("log", "--pretty=oneline", "--abbrev-commit", prev+".."+tag)
|
||||
}
|
||||
|
||||
func getInfo() (tag, commit string, err error) {
|
||||
tag, err = cleanGit("describe", "--tags", "--abbrev=0", "--always")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -8,9 +8,7 @@ import (
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
)
|
||||
|
||||
const bodyTemplate = `## Changelog
|
||||
|
||||
{{ .Changelog }}
|
||||
const bodyTemplate = `{{ .ReleaseNotes }}
|
||||
|
||||
---
|
||||
Automated with @goreleaser
|
||||
@ -25,10 +23,10 @@ func buildBody(ctx *context.Context) (bytes.Buffer, error) {
|
||||
}
|
||||
var template = template.Must(template.New("release").Parse(bodyTemplate))
|
||||
err = template.Execute(&out, struct {
|
||||
Changelog, GoVersion string
|
||||
ReleaseNotes, GoVersion string
|
||||
}{
|
||||
Changelog: ctx.Changelog,
|
||||
GoVersion: string(bts),
|
||||
ReleaseNotes: ctx.ReleaseNotes,
|
||||
GoVersion: string(bts),
|
||||
})
|
||||
return out, err
|
||||
}
|
||||
|
@ -12,11 +12,10 @@ func TestBody(t *testing.T) {
|
||||
var assert = assert.New(t)
|
||||
var changelog = "\nfeature1: description\nfeature2: other description"
|
||||
var ctx = &context.Context{
|
||||
Changelog: changelog,
|
||||
ReleaseNotes: changelog,
|
||||
}
|
||||
out, err := buildBody(ctx)
|
||||
assert.NoError(err)
|
||||
assert.Contains(out.String(), "## Changelog")
|
||||
assert.Contains(out.String(), changelog)
|
||||
assert.Contains(out.String(), "Automated with @goreleaser")
|
||||
assert.Contains(out.String(), "Built with go version go1.8")
|
||||
@ -30,7 +29,7 @@ func TestGoVersionFails(t *testing.T) {
|
||||
}()
|
||||
os.Setenv("PATH", "")
|
||||
var ctx = &context.Context{
|
||||
Changelog: "changelog",
|
||||
ReleaseNotes: "changelog",
|
||||
}
|
||||
_, err := buildBody(ctx)
|
||||
assert.Error(err)
|
||||
|
Loading…
x
Reference in New Issue
Block a user