-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ package main | |
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"html/template" | ||
"log" | ||
|
@@ -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 { | ||
|
@@ -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 | ||
} | ||
dest := path.Join(globalWorkDir, repo.checkoutDir()) | ||
// We avoid creating duplicated PRs to allow this command to be | ||
// run multiple times. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I believe so, based on the comment on line 307 (was 303):
|
||
|
@@ -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...) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ah, good callout: I'd updated |
||
return nil | ||
} | ||
|
||
|
@@ -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. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea - done! (logging that PR creation was skipped due to previous errors)