1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-17 20:47:50 +02:00

feat: warn if loaded changelog is whitespace-only (#2885)

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
This commit is contained in:
Carlos Alexandro Becker 2022-02-06 14:24:47 -03:00 committed by GitHub
parent c42a2fdc76
commit 456f8aa2b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 4 deletions

View File

@ -316,17 +316,25 @@ func newSCMChangeloger(ctx *context.Context) (changeloger, error) {
func loadContent(ctx *context.Context, fileName, tmplName string) (string, error) {
if tmplName != "" {
log.Debugf("loading template %s", tmplName)
log.Debugf("loading template %q", tmplName)
content, err := loadFromFile(tmplName)
if err != nil {
return "", err
}
return tmpl.New(ctx).Apply(content)
content, err = tmpl.New(ctx).Apply(content)
if strings.TrimSpace(content) == "" && err == nil {
log.Warnf("loaded %q, but it evaluates to an empty string", tmplName)
}
return content, err
}
if fileName != "" {
log.Debugf("loading file %s", fileName)
return loadFromFile(fileName)
log.Debugf("loading file %q", fileName)
content, err := loadFromFile(fileName)
if strings.TrimSpace(content) == "" && err == nil {
log.Warnf("loaded %q, but it is empty", fileName)
}
return content, err
}
return "", nil

View File

@ -25,6 +25,13 @@ func TestChangelogProvidedViaFlag(t *testing.T) {
require.Equal(t, "c0ff33 coffeee\n", ctx.ReleaseNotes)
}
func TestChangelogProvidedViaFlagIsAnWhitespaceOnlyFile(t *testing.T) {
ctx := context.New(config.Project{})
ctx.ReleaseNotesFile = "testdata/changes-empty.md"
require.NoError(t, Pipe{}.Run(ctx))
require.Equal(t, "\n", ctx.ReleaseNotes)
}
func TestTemplatedChangelogProvidedViaFlag(t *testing.T) {
ctx := context.New(config.Project{})
ctx.ReleaseNotesFile = "testdata/changes.md"
@ -34,6 +41,14 @@ func TestTemplatedChangelogProvidedViaFlag(t *testing.T) {
require.Equal(t, "c0ff33 coffeee v0.0.1\n", ctx.ReleaseNotes)
}
func TestTemplatedChangelogProvidedViaFlagResultIsEmpty(t *testing.T) {
ctx := context.New(config.Project{})
ctx.ReleaseNotesTmpl = "testdata/changes-templated-empty.md"
ctx.Git.CurrentTag = "v0.0.1"
require.NoError(t, Pipe{}.Run(ctx))
require.Equal(t, "\n\n", ctx.ReleaseNotes)
}
func TestChangelogProvidedViaFlagDoesntExist(t *testing.T) {
ctx := context.New(config.Project{})
ctx.ReleaseNotesFile = "testdata/changes.nope"

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@
{{ print "\n" }}