Skip to content

Commit

Permalink
[krel] changelog: Include CHANGELOG/README.md in master commit logic
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Augustus <saugustus@vmware.com>
  • Loading branch information
justaugustus committed Mar 2, 2020
1 parent 9b1fcf8 commit 7e4a3ce
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions cmd/krel/cmd/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ func htmlChangelogFilename(tag semver.Version) string {
return changelogFilename(tag, "html")
}

func markdownChangelogReadme() string {
return filepath.Join(repoChangelogDir, "README.md")
}

func markdownChangelogFilename(tag semver.Version) string {
return filepath.Join(repoChangelogDir, changelogFilename(tag, "md"))
}
Expand Down Expand Up @@ -398,15 +402,24 @@ func lookupRemoteReleaseNotes(branch string) (string, error) {

func commitChanges(repo *git.Repo, branch string, tag semver.Version) error {
// Master branch modifications
filename := markdownChangelogFilename(tag)
logrus.Infof("Adding %s to repository", filename)
if err := repo.Add(filename); err != nil {
return errors.Wrapf(err, "trying to add file %s to repository", filename)
releaseChangelog := markdownChangelogFilename(tag)
changelogReadme := markdownChangelogReadme()

changelogFiles := []string{
releaseChangelog,
changelogReadme,
}

for _, filename := range changelogFiles {
logrus.Infof("Adding %s to repository", filename)
if err := repo.Add(filename); err != nil {
return errors.Wrapf(err, "trying to add file %s to repository", filename)
}
}

logrus.Info("Committing changes to master branch in repository")
if err := repo.Commit(fmt.Sprintf(
"Add %s for %s", filename, util.SemverToTagString(tag),
"CHANGELOG: Update directory for %s release", util.SemverToTagString(tag),
)); err != nil {
return errors.Wrap(err, "committing changes into repository")
}
Expand All @@ -423,13 +436,13 @@ func commitChanges(repo *git.Repo, branch string, tag semver.Version) error {
}

logrus.Info("Checking out changelog from master branch")
if err := repo.Checkout(git.Master, filename); err != nil {
return errors.Wrap(err, "checking out master branch changelog")
if err := repo.Checkout(git.Master, releaseChangelog); err != nil {
return errors.Wrap(err, "unable to check out master branch changelog")
}

logrus.Info("Committing changes to release branch in repository")
if err := repo.Commit(fmt.Sprintf(
"Update %s for %s", filename, util.SemverToTagString(tag),
"Update %s for %s", releaseChangelog, util.SemverToTagString(tag),
)); err != nil {
return errors.Wrap(err, "committing changes into repository")
}
Expand Down

0 comments on commit 7e4a3ce

Please sign in to comment.