Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: update_versions: continue on other repos if one repo attempt fails #130063

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 36 additions & 15 deletions pkg/cmd/release/update_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package main

import (
"encoding/json"
"errors"
"fmt"
"html/template"
"log"
Expand Down Expand Up @@ -102,6 +103,8 @@ type prRepo struct {
githubUsername string
prBranch string
fn func(gitDir string) error
// workOnRepoError is set to workOnRepo() result
workOnRepoError error
}

func (r prRepo) String() string {
Expand Down Expand Up @@ -282,27 +285,21 @@ func updateVersions(_ *cobra.Command, _ []string) error {
// This way we can fail early and avoid unnecessary work closing the PRs we were able to create.
log.Printf("repos to work on: %s\n", reposToWorkOn)
var prs []string
var workOnRepoErrors []error
for _, repo := range reposToWorkOn {
log.Printf("Cloning repo %s", repo.name())
if err := repo.clone(); err != nil {
return fmt.Errorf("cannot clone %s: %w", repo.name(), err)
}
log.Printf("Branching repo %s", repo.name())
if err := repo.checkout(); err != nil {
return fmt.Errorf("cannot create branch %s: %w", repo.name(), err)
}
log.Printf("Munging repo %s", repo.name())
if err := repo.apply(); err != nil {
return fmt.Errorf("cannot mutate repo %s: %w", repo.name(), err)
}
log.Printf("commiting changes to repo %s", repo.name())
if err := repo.commit(); err != nil {
return fmt.Errorf("cannot commit changes in repo %s: %w", repo.name(), err)
repo.workOnRepoError = workOnRepo(repo)
if repo.workOnRepoError != nil {
log.Printf("workOnRepo: error occurred while working on %s: %s", repo.name(), repo.workOnRepoError)
workOnRepoErrors = append(workOnRepoErrors, repo.workOnRepoError)
}
}

// Now that our local changes are staged, we can try and publish them.
for _, repo := range reposToWorkOn {
if repo.workOnRepoError != nil {
log.Printf("PR creation skipped due to previous errors while working on %s: %s", repo.name(), repo.workOnRepoError)
continue
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One other thought. What about noting in the email that the PR for this repo wasn't created?

Good idea - done! (logging that PR creation was skipped due to previous errors)

}
dest := path.Join(globalWorkDir, repo.checkoutDir())
// We avoid creating duplicated PRs to allow this command to be
// run multiple times.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this needs to be rerun, will it be safe for all the repos what had previously run successfully for the given version?

I believe so, based on the comment on line 307 (was 303):

	// We avoid creating duplicated PRs to allow this command to be
	// run multiple times.

Expand Down Expand Up @@ -330,6 +327,9 @@ func updateVersions(_ *cobra.Command, _ []string) error {
if err := sendPrReport(releasedVersion, prs, smtpPassword); err != nil {
return fmt.Errorf("cannot send email: %w", err)
}
if len(workOnRepoErrors) > 0 {
return errors.Join(workOnRepoErrors...)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this fails for one repo, will the job still show as failed? If not, then it's going to hide the fact that this failed for some of the repos.

Ah, good callout: I'd updated updateVersions() to return the workOnRepoErrors if any errors occurred during the workOnRepo for loop.

return nil
}

Expand Down Expand Up @@ -552,6 +552,27 @@ func generateRepoList(
return reposToWorkOn, nil
}

func workOnRepo(repo prRepo) error {
log.Printf("Cloning repo %s", repo.name())
if err := repo.clone(); err != nil {
return fmt.Errorf("cannot clone %s: %w", repo.name(), err)
}
log.Printf("Branching repo %s", repo.name())
if err := repo.checkout(); err != nil {
return fmt.Errorf("cannot create branch %s: %w", repo.name(), err)
}
log.Printf("Munging repo %s", repo.name())
if err := repo.apply(); err != nil {
return fmt.Errorf("cannot mutate repo %s: %w", repo.name(), err)
}
log.Printf("commiting changes to repo %s", repo.name())
if err := repo.commit(); err != nil {
return fmt.Errorf("cannot commit changes in repo %s: %w", repo.name(), err)
}

return nil
}

func isLatestStableBranch(version *semver.Version) (bool, error) {
// Here we ignore pre-releases (alphas and betas), because we still want to run these operations.
// This way we exclude greater pre-release versions from this decision.
Expand Down
Loading