diff --git a/cmd/krel/cmd/changelog.go b/cmd/krel/cmd/changelog.go index 82f94c9faf1..e81a19e2460 100644 --- a/cmd/krel/cmd/changelog.go +++ b/cmd/krel/cmd/changelog.go @@ -524,8 +524,8 @@ func commitChanges(repo *git.Repo, branch string, tag semver.Version) error { return errors.Wrapf(err, "checking out release branch %s", branch) } - // Remove all other changelog files if we’re on the first RC - if len(tag.Pre) > 1 && tag.Pre[0].String() == "rc" && tag.Pre[1].String() == "1" { + // Remove all other changelog files if we’re on the the first official release + if tag.Patch == 0 && len(tag.Pre) == 0 { pattern := filepath.Join(repoChangelogDir, "CHANGELOG-*.md") logrus.Infof("Removing unnecessary %s files", pattern) if err := repo.Rm(true, pattern); err != nil { diff --git a/cmd/krel/cmd/changelog_test.go b/cmd/krel/cmd/changelog_test.go index 962897599d0..cc36ba968fc 100644 --- a/cmd/krel/cmd/changelog_test.go +++ b/cmd/krel/cmd/changelog_test.go @@ -144,11 +144,40 @@ func TestNewMinorRelease(t *testing.T) { // nolint: dupl co := s.getChangelogOptions("v1.17.0") co.branch = releaseBranch + // Prepare repo + changelogIter := func(callback func(string)) { + for i := 0; i < 6; i++ { + callback(filepath.Join( + repoChangelogDir, fmt.Sprintf("CHANGELOG-1.1%d.md", i), + )) + } + } + + require.Nil(t, s.repo.Checkout(releaseBranch)) + changelogIter(func(filename string) { + require.Nil(t, + ioutil.WriteFile( + filepath.Join(s.repo.Dir(), filename), + []byte("Some content"), + 0644, + ), + ) + require.Nil(t, s.repo.Add(filename)) + }) + require.Nil(t, s.repo.Commit("Adding other changelog files")) + require.Nil(t, s.repo.Checkout(git.Master)) + // When require.Nil(t, newChangelog().run(co, ro)) // Then // Verify local results + require.Nil(t, s.repo.Checkout(releaseBranch)) + changelogIter(func(filename string) { + _, err := os.Stat(filename) + require.True(t, os.IsNotExist(err)) + }) + fileContains(t, "CHANGELOG-1.17.html", minorReleaseExpectedHTML) require.Nil(t, os.RemoveAll("CHANGELOG-1.17.html")) for _, x := range []struct { @@ -188,39 +217,13 @@ func TestNewRCRelease(t *testing.T) { co := s.getChangelogOptions("v1.16.0-rc.1") co.branch = releaseBranch - // Prepare repo - changelogIter := func(callback func(string)) { - for i := 0; i < 6; i++ { - callback(filepath.Join( - repoChangelogDir, fmt.Sprintf("CHANGELOG-1.1%d.md", i), - )) - } - } - - require.Nil(t, s.repo.Checkout(releaseBranch)) - changelogIter(func(filename string) { - require.Nil(t, - ioutil.WriteFile( - filepath.Join(s.repo.Dir(), filename), - []byte("Some content"), - 0644, - ), - ) - require.Nil(t, s.repo.Add(filename)) - }) - require.Nil(t, s.repo.Commit("Adding other changelog files")) - require.Nil(t, s.repo.Checkout(git.Master)) - // When require.Nil(t, newChangelog().run(co, ro)) // Then // Verify local results require.Nil(t, s.repo.Checkout(releaseBranch)) - changelogIter(func(filename string) { - _, err := os.Stat(filename) - require.True(t, os.IsNotExist(err)) - }) + changelog, err := ioutil.ReadFile( filepath.Join(s.repo.Dir(), repoChangelogDir, "CHANGELOG-1.16.md"), )