Skip to content

Commit

Permalink
Merge pull request #1416 from cpanato/GH-1154
Browse files Browse the repository at this point in the history
changelog: remove changelog files from other releases when we cut the first official release
  • Loading branch information
k8s-ci-robot authored Jul 20, 2020
2 parents 4781b1b + 5917d8b commit 0870052
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
4 changes: 2 additions & 2 deletions cmd/krel/cmd/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
57 changes: 30 additions & 27 deletions cmd/krel/cmd/changelog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"),
)
Expand Down

0 comments on commit 0870052

Please sign in to comment.