From 4c74b628ed673d5cb9a8e7dd22468e5952929739 Mon Sep 17 00:00:00 2001 From: Rail Aliiev Date: Thu, 14 Sep 2023 14:02:16 -0400 Subject: [PATCH] release: do not bump version if already bumped 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 --- pkg/cmd/release/git.go | 10 ++++++++++ pkg/cmd/release/update_versions.go | 26 +++++++++++++++++++------- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/pkg/cmd/release/git.go b/pkg/cmd/release/git.go index 464615b82e8e..2139b8742e3b 100644 --- a/pkg/cmd/release/git.go +++ b/pkg/cmd/release/git.go @@ -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 +} diff --git a/pkg/cmd/release/update_versions.go b/pkg/cmd/release/update_versions.go index 907c2299d85d..51257c561e76 100644 --- a/pkg/cmd/release/update_versions.go +++ b/pkg/cmd/release/update_versions.go @@ -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 @@ -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()) }, @@ -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.Original()), 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..") @@ -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.Original()), fn: func(gitDir string) error { return updateHelm(gitDir, releasedVersion.Original()) }, @@ -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()) }, @@ -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