Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: ensure changelog ends on a newline (#1919)
  • Loading branch information
muesli committed Nov 25, 2020
1 parent 56f3493 commit 761c56a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/pipe/changelog/changelog.go
Expand Up @@ -104,7 +104,11 @@ func (Pipe) Run(ctx *context.Context) error {
if len(ctx.ReleaseFooter) > 0 {
changelogElements = append(changelogElements, ctx.ReleaseFooter)
}

ctx.ReleaseNotes = strings.Join(changelogElements, "\n\n")
if !strings.HasSuffix(ctx.ReleaseNotes, "\n") {
ctx.ReleaseNotes += "\n"
}

var path = filepath.Join(ctx.Config.Dist, "CHANGELOG.md")
log.WithField("changelog", path).Info("writing")
Expand Down
27 changes: 27 additions & 0 deletions internal/pipe/changelog/changelog_test.go
Expand Up @@ -406,6 +406,7 @@ func TestChangeLogWithReleaseFooter(t *testing.T) {
require.NoError(t, Pipe{}.Run(ctx))
require.Contains(t, ctx.ReleaseNotes, "## Changelog")
require.Contains(t, ctx.ReleaseNotes, "test footer")
require.Equal(t, rune(ctx.ReleaseNotes[len(ctx.ReleaseNotes)-1]), '\n')
}

func TestChangeLogWithTemplatedReleaseFooter(t *testing.T) {
Expand All @@ -432,4 +433,30 @@ func TestChangeLogWithTemplatedReleaseFooter(t *testing.T) {
require.NoError(t, Pipe{}.Run(ctx))
require.Contains(t, ctx.ReleaseNotes, "## Changelog")
require.Contains(t, ctx.ReleaseNotes, "test footer with tag v0.0.1")
require.Equal(t, rune(ctx.ReleaseNotes[len(ctx.ReleaseNotes)-1]), '\n')
}

func TestChangeLogWithoutReleaseFooter(t *testing.T) {
current, err := os.Getwd()
require.NoError(t, err)
tmpdir, back := testlib.Mktmp(t)
defer back()
require.NoError(t, os.Symlink(current+"/testdata", tmpdir+"/testdata"))
testlib.GitInit(t)
var msgs = []string{
"initial commit",
"another one",
"one more",
"and finally this one",
}
for _, msg := range msgs {
testlib.GitCommit(t, msg)
}
testlib.GitTag(t, "v0.0.1")
testlib.GitCheckoutBranch(t, "v0.0.1")
var ctx = context.New(config.Project{})
ctx.Git.CurrentTag = "v0.0.1"
require.NoError(t, Pipe{}.Run(ctx))
require.Contains(t, ctx.ReleaseNotes, "## Changelog")
require.Equal(t, rune(ctx.ReleaseNotes[len(ctx.ReleaseNotes)-1]), '\n')
}

1 comment on commit 761c56a

@vercel
Copy link

@vercel vercel bot commented on 761c56a Nov 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.