From da9be86ff9552122ddfc21542abd30d8695e1ccd Mon Sep 17 00:00:00 2001 From: Renato Costa Date: Fri, 3 Mar 2023 17:32:08 -0500 Subject: [PATCH] release: `update-versions` bug fixes This fixes two issues found in the `update-versions` automation found while attempting to run it in the process of releasing 22.2.6. * the `isLatestStableBranch` function would only consider the current released version to be the latest if it is greater than the last known release. However, this automation is run after the release is published and the corresponding tag created, so the comparison should actually be that the released version be greater than or equal to the latest release. * the `set-cockroach-version` part of the update should only run if we are releasing something v23 or newer. This updates the logic to ignore `version.txt` related updates otherwise. Epic: none Release note: None --- pkg/cmd/release/update_versions.go | 47 +++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/pkg/cmd/release/update_versions.go b/pkg/cmd/release/update_versions.go index fa912b63d801..3d01221ea12a 100644 --- a/pkg/cmd/release/update_versions.go +++ b/pkg/cmd/release/update_versions.go @@ -27,7 +27,10 @@ import ( "github.com/spf13/cobra" ) -const commitTemplate = `release: released CockroachDB version %s; next version: %s +// 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 Release note: None ` @@ -292,7 +295,7 @@ func createPullRequest(repo prRepo, dest string) (string, error) { // `prRepo`) already exists. Returns a description of the PR when it // exists and any errors found in the process. func prExists(repo prRepo, dest string, released, next *semver.Version) (string, error) { - title := strings.Split(fmt.Sprintf(commitTemplate, released, next), "\n")[0] + title := strings.Split(updateCommitMessage(released, next), "\n")[0] fmt.Printf("checking if PR %q already exists\n", title) query := fmt.Sprintf("in:title %q", title) args := []string{ @@ -361,7 +364,6 @@ func randomString(n int) string { } func productionRepos(released, next *semver.Version) ([]prRepo, error) { - defaultCommitMessage := fmt.Sprintf(commitTemplate, released, next) // Add a random 4-letter string to the end of the branch name to make it unique. // This simplifies recovery in case something goes wrong with pushes or PR creation. defaultPrBranch := fmt.Sprintf("update-versions-%s-%s", released, randomString(4)) @@ -385,9 +387,10 @@ func productionRepos(released, next *semver.Version) ([]prRepo, error) { branch: branch, prBranch: defaultPrBranch, githubUsername: "cockroach-teamcity", - commitMessage: defaultCommitMessage, + commitMessage: updateCommitMessage(released, next), } } + // The roachtest predecessor file changed locations after a // refactoring that took place in the 23.1 cycle, so we account for // that difference here. @@ -411,10 +414,18 @@ func productionRepos(released, next *semver.Version) ([]prRepo, error) { // for other versions it is the next release version's branch. The following logic combines all // changes in a single PR. updateVersionPr := newCrdbRepo(nextBranch) - updateVersionPr.commands = []*exec.Cmd{ - updateRoachtestPred(nextBranch), - exec.Command(self, "set-cockroach-version", "--version", next.Original()), + updateVersionPr.commands = []*exec.Cmd{updateRoachtestPred(nextBranch)} + // Releases 23.{minor} and above include the version.txt file that + // needs to be bumped when a release is published. + // TODO(renato): remove this logic once we stop releasing anything + // older than v23. + if hasVersionTxt(released) { + updateVersionPr.commands = append( + updateVersionPr.commands, + exec.Command(self, "set-cockroach-version", "--version", next.Original()), + ) } + if latest { updateVersionPr.commands = append(updateVersionPr.commands, exec.Command(self, "set-orchestration-version", "--template-dir", "./cloud/kubernetes/templates", @@ -439,7 +450,7 @@ func productionRepos(released, next *semver.Version) ([]prRepo, error) { branch: "master", githubUsername: "cockroach-teamcity", prBranch: defaultPrBranch, - commitMessage: defaultCommitMessage, + commitMessage: updateCommitMessage(released, next), commands: []*exec.Cmd{ exec.Command("make", fmt.Sprintf("VERSION=%s", released), "PRODUCT=cockroach"), }, @@ -450,7 +461,7 @@ func productionRepos(released, next *semver.Version) ([]prRepo, error) { branch: "master", githubUsername: "cockroach-teamcity", prBranch: defaultPrBranch, - commitMessage: defaultCommitMessage, + commitMessage: updateCommitMessage(released, next), commands: []*exec.Cmd{ exec.Command("bazel", "build", "//build"), exec.Command("sh", "-c", fmt.Sprintf("$(bazel info bazel-bin)/build/build_/build %s", released.Original())), @@ -472,7 +483,9 @@ func isLatestStableBranch(version *semver.Version) (bool, error) { if err != nil { return false, fmt.Errorf("cannot parse latest version: %w", err) } - return version.GreaterThan(latestVersion), nil + // Check if the version we processing here is greater than or equal + // to the latest known released version. + return version.Compare(latestVersion) >= 0, nil } func nextReleaseBranch(version *semver.Version) (string, error) { @@ -496,3 +509,17 @@ func parseVersion(versionStr string) (*semver.Version, error) { return version, nil } + +// hasVersionTxt returns whether a given version uses the version.txt +// file to determine binary version. +func hasVersionTxt(version *semver.Version) bool { + return version.Major() >= 23 +} + +func updateCommitMessage(released, next *semver.Version) string { + var nextVersionMsg string + if hasVersionTxt(released) { + nextVersionMsg = ". Next version: %s" + next.String() + } + return fmt.Sprintf(commitTemplate, released, nextVersionMsg) +}