Skip to content

Commit

Permalink
release: do not bump version if already bumped
Browse files Browse the repository at this point in the history
Previously, if the version was bumped manually, the automation would
try to bump, write the same content to the file and fail committing
changes.

This PR skips version bump in case it was already bumped. Additionally,
some of the commit messages were adjusted.

Fixes: RE-468
Release note: None
  • Loading branch information
rail committed Sep 15, 2023
1 parent 36b61a8 commit 0aa3602
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
10 changes: 10 additions & 0 deletions pkg/cmd/release/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,13 @@ func fileExistsInGit(branch string, f string) (bool, error) {
}
return true, nil
}

// fileContent uses `git cat-file -p ref:file` to get to the file contents without `git checkout`.
func fileContent(ref string, f string) (string, error) {
cmd := exec.Command("git", "cat-file", "-p", ref+":"+f)
out, err := cmd.Output()
if err != nil {
return "", fmt.Errorf("git cat-file: %w", err)
}
return string(out), nil
}
26 changes: 19 additions & 7 deletions pkg/cmd/release/update_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
// first %s is the released version. Second is an optional message
// about the next released version for releases that include the
// version.txt file.
const commitTemplate = `release: released CockroachDB version %s%s
const commitTemplate = `%s: released CockroachDB version %s%s
Release note: None
Epic: None
Expand Down Expand Up @@ -403,14 +403,26 @@ func generateRepoList(
log.Printf("skipping version bump on the %s branch, because %s does not exist on that branch", branch, versionFile)
continue
}
curVersion, err := fileContent(branch, versionFile)
if err != nil {
return []prRepo{}, fmt.Errorf("reading git file content: %w", err)
}
if strings.TrimSpace(curVersion) == nextVersion.Original() {
log.Printf("skipping version bump on the %s branch, because the versions are the same", branch)
continue
}
prBranch := fmt.Sprintf("update-versions-%s-%s-%s", branch, releasedVersion.Original(), randomString(4))
commitMessagePrefix := "release"
if branch != "master" {
commitMessagePrefix = branch
}
repo := prRepo{
owner: owner,
repo: prefix + "cockroach",
branch: branch,
prBranch: prBranch,
githubUsername: "cockroach-teamcity",
commitMessage: generateCommitMessage(releasedVersion, nextVersion),
commitMessage: generateCommitMessage(commitMessagePrefix, releasedVersion, nextVersion),
fn: func(gitDir string) error {
return updateVersionFile(path.Join(gitDir, versionFile), nextVersion.Original())
},
Expand All @@ -426,7 +438,7 @@ func generateRepoList(
branch: "master",
githubUsername: "cockroach-teamcity",
prBranch: fmt.Sprintf("update-versions-%s-%s", releasedVersion.Original(), randomString(4)),
commitMessage: generateCommitMessage(releasedVersion, nextVersion),
commitMessage: fmt.Sprintf("release: advance to %s", releasedVersion),
fn: func(gitDir string) error {
if dryRun {
log.Printf("brew fetches and verifies the binaries, so it's likely it'll fail in dry-run mode. Skipping..")
Expand All @@ -444,7 +456,7 @@ func generateRepoList(
branch: "master",
githubUsername: "cockroach-teamcity",
prBranch: fmt.Sprintf("update-versions-%s-%s", releasedVersion.Original(), randomString(4)),
commitMessage: generateCommitMessage(releasedVersion, nextVersion),
commitMessage: fmt.Sprintf("release: advance to %s", releasedVersion),
fn: func(gitDir string) error {
return updateHelm(gitDir, releasedVersion.Original())
},
Expand All @@ -458,7 +470,7 @@ func generateRepoList(
branch: "master",
githubUsername: "cockroach-teamcity",
prBranch: fmt.Sprintf("update-orchestration-versions-%s-%s", releasedVersion.Original(), randomString(4)),
commitMessage: generateCommitMessage(releasedVersion, nextVersion),
commitMessage: generateCommitMessage("release", releasedVersion, nextVersion),
fn: func(gitDir string) error {
return updateOrchestration(gitDir, releasedVersion.Original())
},
Expand Down Expand Up @@ -501,12 +513,12 @@ func hasVersionTxt(version *semver.Version) bool {
return version.Major() >= 23
}

func generateCommitMessage(released, next *semver.Version) string {
func generateCommitMessage(prefix string, released, next *semver.Version) string {
var nextVersionMsg string
if hasVersionTxt(released) {
nextVersionMsg = ". Next version: " + next.String()
}
return fmt.Sprintf(commitTemplate, released, nextVersionMsg)
return fmt.Sprintf(commitTemplate, prefix, released, nextVersionMsg)
}

// nextReleaseSeries parses the version and returns the next release series assuming we have 2 releases yearly
Expand Down

0 comments on commit 0aa3602

Please sign in to comment.