Skip to content

Commit

Permalink
Merge pull request #1143 from justaugustus/rebase-fix
Browse files Browse the repository at this point in the history
[krel] changelog: Include CHANGELOG/README.md in master commit logic
  • Loading branch information
k8s-ci-robot authored Mar 2, 2020
2 parents a81356f + 7e4a3ce commit 693165a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
12 changes: 12 additions & 0 deletions anago
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,8 @@ check_prerequisites () {
PROGSTEP[generate_release_notes]="GENERATE RELEASE NOTES"
generate_release_notes () {
local release_tars=$TREE_ROOT/_output-$RELEASE_VERSION_PRIME/release-tars
local git_status_output
local repo_state

logrun -v krel changelog \
--repo "$TREE_ROOT" \
Expand All @@ -414,6 +416,16 @@ generate_release_notes () {
--html-file "$RELEASE_NOTES_HTML" \
--bucket="$RELEASE_BUCKET" \
|| return 1

git_status_output=$(git status -s)
repo_state=$([[ -z $git_status_output ]] || echo "dirty")

if [[ $repo_state == "dirty" ]]; then
logecho "Repo state was dirty after generating release notes. Cannot continue."
logecho "'git status -s' output:"
logecho "$git_status_output"
return 1
fi
}

##############################################################################
Expand Down
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
6 changes: 4 additions & 2 deletions lib/gitlib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,12 @@ gitlib::push_master () {

logecho -n "Checkout master branch to push objects: "
logrun -s git checkout master || return 1
logrun -v git status -s || return 1
logrun -v git show || return 1

logecho -n "Rebase master branch: "
logrun git fetch origin || return 1
logrun -s git rebase origin/master || return 1
logrun -v git fetch origin || return 1
logrun -s -v git rebase origin/master || return 1
logecho -n "Pushing$dryrun_flag master branch: "
logrun -s git push$dryrun_flag origin master || return 1
}
Expand Down

0 comments on commit 693165a

Please sign in to comment.