Repository: goreleaser/goreleaser
Pull request #1919 (2020-11-25 01:47:38)

fix: ensure Changelog ends on a newline
This ensures the Changelog ends with a trailing newline, regardless of a footer being set.

Also added tests to verify this behavior.

vercel[bot]: @muesli is attempting to deploy a commit to the **Goreleaser** Team on [Vercel](https://vercel.com).

A member of the Team first needs to [authorize it](https://vercel.com/git/authorize?team=Goreleaser&type=github&job=%7B%22headInfo%22%3A%7B%22sha%22%3A%22541d5f08a28871fb73fc9a830da3cef8a462688f%22%7D%2C%22id%22%3A%22QmUd7REQPM13pRupkYopnkRkuRDu8ZXYvm2FHSH8F9Zg2q%22%2C%22org%22%3A%22goreleaser%22%2C%22prId%22%3A1919%2C%22repo%22%3A%22goreleaser%22%7D).


codecov[bot]: # [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1919?src=pr&el=h1) Report
> Merging [#1919](https://codecov.io/gh/goreleaser/goreleaser/pull/1919?src=pr&el=desc) (541d5f0) into [master](https://codecov.io/gh/goreleaser/goreleaser/commit/56f34935d20b387f29d853bd10e210d233c3ba4a?el=desc) (56f3493) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/goreleaser/goreleaser/pull/1919/graphs/tree.svg?width=650&height=150&src=pr&token=3bJvv6b7hN)](https://codecov.io/gh/goreleaser/goreleaser/pull/1919?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master    #1919   +/-   ##
=======================================
  Coverage   81.72%   81.73%           
=======================================
  Files          73       73           
  Lines        3864     3866    +2     
=======================================
+ Hits         3158     3160    +2     
  Misses        580      580           
  Partials      126      126           
```


| [Impacted Files](https://codecov.io/gh/goreleaser/goreleaser/pull/1919?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [internal/pipe/changelog/changelog.go](https://codecov.io/gh/goreleaser/goreleaser/pull/1919/diff?src=pr&el=tree#diff-aW50ZXJuYWwvcGlwZS9jaGFuZ2Vsb2cvY2hhbmdlbG9nLmdv) | `92.85% <100.00%> (+0.12%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1919?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/goreleaser/goreleaser/pull/1919?src=pr&el=footer). Last update [56f3493...541d5f0](https://codecov.io/gh/goreleaser/goreleaser/pull/1919?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/internal/pipe/changelog/changelog.go b/internal/pipe/changelog/changelog.go
index eea669d7..f9d72d8d 100644
--- a/internal/pipe/changelog/changelog.go
+++ b/internal/pipe/changelog/changelog.go
@@ -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")


Test patch:
diff --git a/internal/pipe/changelog/changelog_test.go b/internal/pipe/changelog/changelog_test.go
index bda97bbc..a2f1394d 100644
--- a/internal/pipe/changelog/changelog_test.go
+++ b/internal/pipe/changelog/changelog_test.go
@@ -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) {
@@ -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')
 }