From 5f30f3606a3c0acfa909811175cfd4777fd26855 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Sun, 6 Feb 2022 22:09:46 -0300 Subject: [PATCH] fix: make --release-notes flags more deterministic (#2888) * fix: make --release-notes flags more deterministic Signed-off-by: Carlos A Becker * chore: fmt Signed-off-by: Carlos A Becker --- internal/pipe/changelog/changelog.go | 2 +- internal/pipe/changelog/changelog_test.go | 16 +++++++++++++++- .../changelog/testdata/changes-really-empty.md | 0 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 internal/pipe/changelog/testdata/changes-really-empty.md diff --git a/internal/pipe/changelog/changelog.go b/internal/pipe/changelog/changelog.go index 47eccd7e4ae..def2ad60db0 100644 --- a/internal/pipe/changelog/changelog.go +++ b/internal/pipe/changelog/changelog.go @@ -49,7 +49,7 @@ func (Pipe) Run(ctx *context.Context) error { } ctx.ReleaseNotes = notes - if ctx.ReleaseNotes != "" { + if ctx.ReleaseNotesFile != "" || ctx.ReleaseNotesTmpl != "" { return nil } diff --git a/internal/pipe/changelog/changelog_test.go b/internal/pipe/changelog/changelog_test.go index 4cc090e7159..886b9fa23bf 100644 --- a/internal/pipe/changelog/changelog_test.go +++ b/internal/pipe/changelog/changelog_test.go @@ -25,13 +25,27 @@ func TestChangelogProvidedViaFlag(t *testing.T) { require.Equal(t, "c0ff33 coffeee\n", ctx.ReleaseNotes) } -func TestChangelogProvidedViaFlagIsAnWhitespaceOnlyFile(t *testing.T) { +func TestChangelogProvidedViaFlagIsAWhitespaceOnlyFile(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 TestChangelogProvidedViaFlagIsReallyEmpty(t *testing.T) { + ctx := context.New(config.Project{}) + ctx.ReleaseNotesFile = "testdata/changes-really-empty.md" + require.NoError(t, Pipe{}.Run(ctx)) + require.Equal(t, "", ctx.ReleaseNotes) +} + +func TestChangelogTmplProvidedViaFlagIsReallyEmpty(t *testing.T) { + ctx := context.New(config.Project{}) + ctx.ReleaseNotesTmpl = "testdata/changes-really-empty.md" + require.NoError(t, Pipe{}.Run(ctx)) + require.Equal(t, "", ctx.ReleaseNotes) +} + func TestTemplatedChangelogProvidedViaFlag(t *testing.T) { ctx := context.New(config.Project{}) ctx.ReleaseNotesFile = "testdata/changes.md" diff --git a/internal/pipe/changelog/testdata/changes-really-empty.md b/internal/pipe/changelog/testdata/changes-really-empty.md new file mode 100644 index 00000000000..e69de29bb2d