diff --git a/gbm-cli/bin/gbm b/gbm-cli/bin/gbm index abaa4cf..4a004d7 100755 Binary files a/gbm-cli/bin/gbm and b/gbm-cli/bin/gbm differ diff --git a/gbm-cli/cmd/release/prepare/all.go b/gbm-cli/cmd/release/prepare/all.go index f0b6494..f95d911 100644 --- a/gbm-cli/cmd/release/prepare/all.go +++ b/gbm-cli/cmd/release/prepare/all.go @@ -41,6 +41,14 @@ var allCmd = &cobra.Command{ }, } + isPatch := version.IsPatchRelease() + + if isPatch { + console.Info("Preparing a patch releases") + tagName := "rnmobile/" + version.PriorVersion().String() + setupPatchBuild(tagName, &build) + } + gbPr, err = release.CreateGbPR(build) exitIfError(err, 1) console.Info("Finished preparing Gutenberg PR") @@ -50,7 +58,16 @@ var allCmd = &cobra.Command{ build = release.Build{ Dir: gbmDir, Version: version, + Base: gh.Repo{ + Ref: "trunk", + }, + } + + if isPatch { + tagName := version.PriorVersion().Vstring() + setupPatchBuild(tagName, &build) } + pr, err := release.CreateGbmPR(build) exitIfError(err, 1) console.Info("Finished preparing Gutenberg Mobile PR") diff --git a/gbm-cli/cmd/release/prepare/gb.go b/gbm-cli/cmd/release/prepare/gb.go index 8dd5163..0a3c7da 100644 --- a/gbm-cli/cmd/release/prepare/gb.go +++ b/gbm-cli/cmd/release/prepare/gb.go @@ -19,6 +19,7 @@ var gbCmd = &cobra.Command{ Dir: tempDir, Version: version, UseTag: !noTag, + Repo: "gutenberg", Base: gh.Repo{ Ref: "trunk", }, @@ -26,7 +27,8 @@ var gbCmd = &cobra.Command{ if version.IsPatchRelease() { console.Info("Preparing a patch release") - setupPatchBuild(&build) + tagName := "rnmobile/" + version.PriorVersion().String() + setupPatchBuild(tagName, &build) } console.Info("Preparing Gutenberg for release %s", version) diff --git a/gbm-cli/cmd/release/prepare/gbm.go b/gbm-cli/cmd/release/prepare/gbm.go index 07a42e8..e8c54ae 100644 --- a/gbm-cli/cmd/release/prepare/gbm.go +++ b/gbm-cli/cmd/release/prepare/gbm.go @@ -23,6 +23,13 @@ var gbmCmd = &cobra.Command{ Base: gh.Repo{ Ref: "trunk", }, + Repo: "gutenberg-mobile", + } + + if version.IsPatchRelease() { + console.Info("Preparing a patch release") + tagName := version.PriorVersion().Vstring() + setupPatchBuild(tagName, &build) } pr, err := release.CreateGbmPR(build) diff --git a/gbm-cli/cmd/release/prepare/root.go b/gbm-cli/cmd/release/prepare/root.go index e019d3a..44421e9 100644 --- a/gbm-cli/cmd/release/prepare/root.go +++ b/gbm-cli/cmd/release/prepare/root.go @@ -68,20 +68,21 @@ func init() { PrepareCmd.PersistentFlags().StringSliceVar(&prs, "prs", []string{}, "prs to include in the release. Only used with patch releases") } -func setupPatchBuild(build *release.Build) { +func setupPatchBuild(tagName string, build *release.Build) { - // Get the ref to the prior release - priorVersion := version.PriorVersion() - - tag, err := gh.GetTag("gutenberg", "rnmobile/"+priorVersion.String()) + tag, err := gh.GetTag(build.Repo, tagName) exitIfError(err, 1) - build.Base = gh.Repo{Ref: "rnmobile/" + priorVersion.String()} - build.Prs = gh.GetPrs("gutenberg", prs) - build.Depth = "--shallow-since=" + tag.Date + build.Base = gh.Repo{Ref: tagName} + + // We don't usually pick prs from Gutenberg Mobile for patch releases + if len(prs) != 0 { + build.Prs = gh.GetPrs("gutenberg", prs) + build.Depth = "--shallow-since=" + tag.Date - if len(build.Prs) == 0 { - exitIfError(errors.New("no PRs found for patch release"), 1) - return + if len(build.Prs) == 0 { + exitIfError(errors.New("no PRs found for patch release"), 1) + return + } } } diff --git a/gbm-cli/pkg/gh/gh.go b/gbm-cli/pkg/gh/gh.go index dbdcfcb..cc6c37d 100644 --- a/gbm-cli/pkg/gh/gh.go +++ b/gbm-cli/pkg/gh/gh.go @@ -432,7 +432,7 @@ func labelRequest(rpo string, prNum int, labels []string) ([]Label, error) { return resp, nil } -func PreviewPr(rpo, dir string, pr PullRequest) { +func PreviewPr(rpo, dir, branchFrom string, pr PullRequest) { org := repo.GetOrg(rpo) row := console.Row @@ -441,11 +441,13 @@ func PreviewPr(rpo, dir string, pr PullRequest) { white := color.New(color.FgWhite).SprintFunc() console.Print(row, "Repo: %s/%s", white(org), white(rpo)) + console.Print(row, "Base: %s", white(pr.Base.Ref)) + console.Print(row, "Head: %s", white(pr.Head.Ref)) console.Print(row, "Title: %s", white(pr.Title)) console.Print(row, "Body:\n%s", white(pr.Body)) console.Print(row, "Commits:") git := shell.NewGitCmd(shell.CmdProps{Dir: dir, Verbose: true}) - git.Log(pr.Base.Ref+"...HEAD", "--oneline", "--no-merges", "-10") + git.Log(branchFrom+"...HEAD", "--oneline", "--no-merges", "-10") } diff --git a/gbm-cli/pkg/release/gb.go b/gbm-cli/pkg/release/gb.go index a41466e..af9df4c 100644 --- a/gbm-cli/pkg/release/gb.go +++ b/gbm-cli/pkg/release/gb.go @@ -55,49 +55,55 @@ func CreateGbPR(build Build) (gh.PullRequest, error) { } if isPatch { - console.Info("Cherry picking PRs") - err := git.Fetch("trunk", build.Depth) - if err != nil { - return pr, fmt.Errorf("error fetching the Gutenberg repository: %v", err) - } - - for _, pr := range build.Prs { - if pr.MergeCommit == "" { - return pr, fmt.Errorf("error cherry picking PR %d: no merge commit", pr.Number) + // We probably won't create a patch release with out PRS to cherry pick but + // for testing this is useful to allow and to skip. + if len(build.Prs) != 0 { + console.Info("Cherry picking PRs") + err := git.Fetch("trunk", build.Depth) + if err != nil { + return pr, fmt.Errorf("error fetching the Gutenberg repository: %v", err) } - console.Info("Cherry picking PR %d via commit %s", pr.Number, pr.MergeCommit) - if err := git.CherryPick(pr.MergeCommit); err != nil { - - console.Print(console.Highlight, "\nThere was an issue cherry picking PR #%d", pr.Number) - conflicts, err := git.StatConflicts() - if len(conflicts) == 0 { - return pr, fmt.Errorf("error cherry picking PR %d: %v", pr.Number, err) - } - console.Print(console.HeadingRow, "\nThe conflict can be resolved by inspecting the following files:") - - if err != nil { - return pr, fmt.Errorf("error getting the list of conflicting files: %v", err) - } - for _, file := range conflicts { - console.Print(console.Row, "• "+filepath.Join(dir, file)) + for _, pr := range build.Prs { + if pr.MergeCommit == "" { + return pr, fmt.Errorf("error cherry picking PR %d: no merge commit", pr.Number) } + console.Info("Cherry picking PR %d via commit %s", pr.Number, pr.MergeCommit) - if err := openInEditor(dir, conflicts); err != nil { - console.Warn("There was an issue opening the conflicting files in your editor: %v", err) - } + if err := git.CherryPick(pr.MergeCommit); err != nil { - fixed := console.Confirm("Continue after resolving the conflict?") + console.Print(console.Highlight, "\nThere was an issue cherry picking PR #%d", pr.Number) + conflicts, err := git.StatConflicts() + if len(conflicts) == 0 { + return pr, fmt.Errorf("error cherry picking PR %d: %v", pr.Number, err) + } + console.Print(console.HeadingRow, "\nThe conflict can be resolved by inspecting the following files:") - if fixed { - err := git.CherryPick("--continue") if err != nil { - return pr, fmt.Errorf("error continuing the cherry pick: %v", err) + return pr, fmt.Errorf("error getting the list of conflicting files: %v", err) + } + for _, file := range conflicts { + console.Print(console.Row, "• "+filepath.Join(dir, file)) + } + + if err := openInEditor(dir, conflicts); err != nil { + console.Warn("There was an issue opening the conflicting files in your editor: %v", err) + } + + fixed := console.Confirm("Continue after resolving the conflict?") + + if fixed { + err := git.CherryPick("--continue") + if err != nil { + return pr, fmt.Errorf("error continuing the cherry pick: %v", err) + } + } else { + return pr, fmt.Errorf("error cherry picking PR %d: %v", pr.Number, err) } - } else { - return pr, fmt.Errorf("error cherry picking PR %d: %v", pr.Number, err) } } + } else { + console.Warn("No PRs to cherry pick") } } @@ -194,7 +200,7 @@ func CreateGbPR(build Build) (gh.PullRequest, error) { }, } - previewPr("gutenberg", dir, build.Base.Ref, pr) + gh.PreviewPr("gutenberg", dir, build.Base.Ref, pr) prompt := fmt.Sprintf("\nReady to create the PR on %s/gutenberg?", org) cont := console.Confirm(prompt) diff --git a/gbm-cli/pkg/release/gbm.go b/gbm-cli/pkg/release/gbm.go index ba5f40a..717350d 100644 --- a/gbm-cli/pkg/release/gbm.go +++ b/gbm-cli/pkg/release/gbm.go @@ -42,15 +42,15 @@ func CreateGbmPR(build Build) (gh.PullRequest, error) { return pr, nil } else { console.Info("Cloning Gutenberg Mobile to %s", dir) - err := git.Clone(repo.GetRepoPath("gutenberg-mobile"), "--depth=1", "--recursive", ".") + err := git.Clone(repo.GetRepoPath("gutenberg-mobile"), "--branch", build.Base.Ref, "--depth=1", "--recursive", ".") if err != nil { return pr, fmt.Errorf("error cloning the Gutenberg Mobile repository: %v", err) } - console.Info("Checking out branch %s", branch) + console.Info("Setting up the branch %s", branch) err = git.Switch("-c", branch) if err != nil { - return pr, fmt.Errorf("error checking out the branch: %v", err) + return pr, fmt.Errorf("error switching to the branch: %v", err) } } @@ -92,14 +92,9 @@ func CreateGbmPR(build Build) (gh.PullRequest, error) { return pr, fmt.Errorf("error running npm run bundle: %v", err) } - // Commit the updated Gutenberg submodule ref - if git.IsPorcelain() { - console.Info("Nothing to commit after bundling") - } else { - // Commit the updated bundle output - if err := git.CommitAll("Release script: Update bundle for %s", version); err != nil { - return pr, fmt.Errorf("error committing the bundle update: %v", err) - } + // Commit the updated strings + if err := git.CommitAll("Release script: Update i18n files for %s", version); err != nil { + return pr, fmt.Errorf("error committing the bundle update: %v", err) } if err := updateXcFramework(version, dir, git); err != nil { @@ -112,6 +107,18 @@ func CreateGbmPR(build Build) (gh.PullRequest, error) { if err := UpdateReleaseNotes(version, chnPath); err != nil { return pr, fmt.Errorf("error updating the release notes: %v", err) } + // If this is a patch release we should prompt for the wrangler to manually update the release notes + if build.Version.IsPatchRelease() { + console.Print(console.Highlight, "\nSince this is a patch release manually update the release notes") + + if err := openInEditor(dir, []string{"RELEASE-NOTES.txt"}); err != nil { + console.Warn("There was an issue opening RELEASE-NOTES.txt in your editor: %v", err) + } + + if cont := console.Confirm("Do you wish to continue after updating RELEASE-NOTES.txt?"); !cont { + return pr, fmt.Errorf("exiting before creating PR, Stopping at RELEASE-NOTES.txt update") + } + } if err := git.CommitAll("Release script: Update release notes for version %s", version); err != nil { return pr, fmt.Errorf("error committing the release notes update: %v", err) @@ -135,7 +142,7 @@ func CreateGbmPR(build Build) (gh.PullRequest, error) { }} // Display PR preview - gh.PreviewPr("gutenberg-mobile", dir, pr) + gh.PreviewPr("gutenberg-mobile", dir, build.Base.Ref, pr) // Add prompt to confirm PR creation prompt := fmt.Sprintf("\nReady to create the PR on %s/gutenberg-mobile?", org) diff --git a/gbm-cli/pkg/release/integrate/integrate.go b/gbm-cli/pkg/release/integrate/integrate.go index b0f1ab6..2ae6d91 100644 --- a/gbm-cli/pkg/release/integrate/integrate.go +++ b/gbm-cli/pkg/release/integrate/integrate.go @@ -195,7 +195,7 @@ func (ri *ReleaseIntegration) createPR(dir string, gbmPr gh.PullRequest) (gh.Pul }} rpo := ri.Target.GetRepo() - gh.PreviewPr(rpo, dir, pr) + gh.PreviewPr(rpo, dir, ri.BaseBranch, pr) if err := gh.CreatePr(rpo, &pr); err != nil { return pr, err diff --git a/gbm-cli/pkg/release/main.go b/gbm-cli/pkg/release/main.go index c65a96e..dc75555 100644 --- a/gbm-cli/pkg/release/main.go +++ b/gbm-cli/pkg/release/main.go @@ -9,6 +9,7 @@ type Build struct { Version semver.SemVer Dir string UseTag bool + Repo string Prs []gh.PullRequest Base gh.Repo Depth string diff --git a/gbm-cli/pkg/release/utils.go b/gbm-cli/pkg/release/utils.go index b229cb4..85a18ee 100644 --- a/gbm-cli/pkg/release/utils.go +++ b/gbm-cli/pkg/release/utils.go @@ -10,11 +10,8 @@ import ( "strconv" "strings" - "github.com/fatih/color" "github.com/wordpress-mobile/release-toolkit-gutenberg-mobile/gbm-cli/pkg/console" "github.com/wordpress-mobile/release-toolkit-gutenberg-mobile/gbm-cli/pkg/gh" - "github.com/wordpress-mobile/release-toolkit-gutenberg-mobile/gbm-cli/pkg/repo" - "github.com/wordpress-mobile/release-toolkit-gutenberg-mobile/gbm-cli/pkg/shell" ) func CollectReleaseChanges(version string, changelog, relnotes []byte) ([]ReleaseChanges, error) { @@ -191,24 +188,6 @@ func readWriteNotes(version, path string, updater func(string, []byte) []byte) e return nil } -func previewPr(rpo, dir, branchFrom string, pr gh.PullRequest) { - org := repo.GetOrg(rpo) - row := console.Row - - console.Print(console.Heading, "\nPr Preview") - - white := color.New(color.FgWhite).SprintFunc() - - console.Print(row, "Repo: %s/%s", white(org), white(rpo)) - console.Print(row, "Title: %s", white(pr.Title)) - console.Print(row, "Body:\n%s", white(pr.Body)) - console.Print(row, "Commits:") - - git := shell.NewGitCmd(shell.CmdProps{Dir: dir, Verbose: true}) - - git.Log(branchFrom+"...HEAD", "--oneline", "--no-merges", "-10") -} - func openInEditor(dir string, files []string) error { editor := os.Getenv("EDITOR")