Skip to content

Commit

Permalink
Merge #122196
Browse files Browse the repository at this point in the history
122196: release: pick SHA should work for baking and extraordinary releases r=celiala a=rail

Previously, we used only one branch to find potential release SHAs. Extraordinary and baking releases use different branch patterns, so the automation ignored them.

This PR adds the missing branch patterns into the logic.

Fixes: RE-609
Release note: None

Co-authored-by: Rail Aliiev <rail@iqchoice.com>
  • Loading branch information
craig[bot] and rail committed Apr 11, 2024
2 parents c6c9461 + e8961cf commit 25d6013
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions pkg/cmd/release/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func findNextRelease(releaseSeries string) (releaseInfo, error) {
if err != nil {
return releaseInfo{}, fmt.Errorf("cannot bump version: %w", err)
}
candidateCommits, err := findCandidateCommits(prevReleaseVersion, releaseSeries)
candidateCommits, err := findCandidateCommits(prevReleaseVersion, nextReleaseVersion)
if err != nil {
return releaseInfo{}, fmt.Errorf("cannot find candidate commits: %w", err)
}
Expand Down Expand Up @@ -219,10 +219,44 @@ func getCommonBaseRef(fromRef, toRef string) (string, error) {
return strings.TrimSpace(string(out)), nil
}

// findReleaseBranch finds the release branch for a version based on a list of branch patterns.
func findReleaseBranch(version string) (string, error) {
semVersion, err := parseVersion(version)
if err != nil {
return "", fmt.Errorf("cannot parse version %s: %w", version, err)
}
// List of potential release branches by their priority. The first found will be used as the release branch.
maybeReleaseBranches := []string{
// staging-vx.y.z is usually used by extraordinary releases. Top priority.
fmt.Sprintf("staging-v%d.%d.%d", semVersion.Major(), semVersion.Minor(), semVersion.Patch()),
// release-x.y.z-rc us used by baking releases.
fmt.Sprintf("release-%d.%d.%d-rc", semVersion.Major(), semVersion.Minor(), semVersion.Patch()),
fmt.Sprintf("release-%d.%d", semVersion.Major(), semVersion.Minor()),
// TODO: add master for alphas
}
for _, branch := range maybeReleaseBranches {
remoteBranches, err := listRemoteBranches(branch)
if err != nil {
return "", fmt.Errorf("listing release branch %s: %w", branch, err)
}
if len(remoteBranches) > 1 {
return "", fmt.Errorf("found more than one release branches for %s: %s", branch, strings.Join(remoteBranches, ", "))
}
if len(remoteBranches) > 0 {
return remoteBranches[0], nil
}
}
return "", fmt.Errorf("cannot find release branch for %s", version)
}

// findCandidateCommits finds all potential merge commits that can be used for the current release.
// It includes all merge commits since previous release.
func findCandidateCommits(prevRelease string, releaseSeries string) ([]string, error) {
releaseBranch := fmt.Sprintf("%s/release-%s", remoteOrigin, releaseSeries)
func findCandidateCommits(prevRelease string, version string) ([]string, error) {
releaseBranch, err := findReleaseBranch(version)
if err != nil {
return []string{}, fmt.Errorf("cannot find release branch for %s", version)
}
releaseBranch = fmt.Sprintf("%s/%s", remoteOrigin, releaseBranch)
commonBaseRef, err := getCommonBaseRef(prevRelease, releaseBranch)
if err != nil {
return []string{}, fmt.Errorf("cannot find common base ref: %w", err)
Expand Down Expand Up @@ -276,7 +310,6 @@ func listRemoteBranches(pattern string) ([]string, error) {
remoteBranches = append(remoteBranches, strings.TrimPrefix(fields[1], "refs/heads/"))
}
return remoteBranches, nil

}

// fileExistsInGit checks if a file exists in a local repository, assuming the remote name is `origin`.
Expand Down

0 comments on commit 25d6013

Please sign in to comment.