Skip to content

Commit 86f9529

Browse files
authored
Merge pull request #46 from vitessio/back-to-dev-mode
Implement back to dev mode
2 parents 06fed2a + fc40abb commit 86f9529

File tree

14 files changed

+205
-109
lines changed

14 files changed

+205
-109
lines changed

go/cmd/cmd.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,20 @@ func Execute() {
8484
s.MajorRelease = releaseVersion
8585

8686
git.CorrectCleanRepo(s.VitessRepo)
87-
nextRelease, _, _ := releaser.FindNextRelease(s.MajorRelease)
8887

89-
s.IssueNbGH, s.IssueLink = github.GetReleaseIssueInfo(s.VitessRepo, nextRelease)
88+
remote := git.FindRemoteName(s.VitessRepo)
89+
release, releaseBranch, isLatestRelease := releaser.FindNextRelease(remote, s.MajorRelease)
90+
issueNb, issueLink, releaseFromIssue := github.GetReleaseIssueInfo(s.VitessRepo, s.MajorRelease)
91+
92+
s.Remote = remote
93+
s.ReleaseBranch = releaseBranch
94+
s.IsLatestRelease = isLatestRelease
95+
s.IssueNbGH = issueNb
96+
s.IssueLink = issueLink
97+
s.Release = releaseFromIssue
98+
if releaseFromIssue == "" {
99+
s.Release = release
100+
}
90101

91102
// We only require the release date if the release issue does not exist on GH
92103
// If the issue already exist we ignore the flag, the value will be loaded from the Issue

go/interactive/release/back_to_dev.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
tea "github.com/charmbracelet/bubbletea"
2323
"vitess.io/vitess-releaser/go/interactive/ui"
2424
"vitess.io/vitess-releaser/go/releaser"
25+
"vitess.io/vitess-releaser/go/releaser/release"
2526
"vitess.io/vitess-releaser/go/releaser/steps"
2627
)
2728

@@ -44,9 +45,19 @@ func BackToDevModeItem(ctx context.Context) *ui.MenuItem {
4445
type backToDevModeUrl string
4546

4647
func backToDevModeUpdate(mi *ui.MenuItem, msg tea.Msg) (*ui.MenuItem, tea.Cmd) {
48+
_, ok := msg.(backToDevModeUrl)
49+
if !ok {
50+
return mi, nil
51+
}
52+
53+
mi.Info = mi.State.Issue.BackToDevMode.URL
54+
mi.IsDone = mi.State.Issue.BackToDevMode.Done
4755
return mi, nil
4856
}
4957

5058
func backToDevModeAct(mi *ui.MenuItem) (*ui.MenuItem, tea.Cmd) {
51-
return mi, nil
59+
pl, back := release.BackToDevMode(mi.State)
60+
return mi, tea.Batch(func() tea.Msg {
61+
return backToDevModeUrl(back())
62+
}, ui.PushDialog(ui.NewProgressDialog("Back To Dev Mode", pl)))
5263
}

go/releaser/ctx.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,15 @@ func WrapState(ctx context.Context, s *State) context.Context {
3333
}
3434

3535
type State struct {
36-
VitessRepo string
37-
MajorRelease string
38-
IssueNbGH int
39-
IssueLink string
40-
Issue Issue
36+
VitessRepo string
37+
Remote string
38+
ReleaseBranch string
39+
40+
MajorRelease string
41+
Release string
42+
IsLatestRelease bool
43+
44+
Issue Issue
45+
IssueLink string
46+
IssueNbGH int
4147
}

go/releaser/github/issues.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func GetIssueBody(repo string, nb int) string {
8888
return i.Body
8989
}
9090

91-
func GetReleaseIssue(repo, release string) string {
91+
func GetReleaseIssue(repo, release string) (string, string) {
9292
res, _, err := gh.Exec(
9393
"issue", "list",
9494
"-l", "Type: Release",
@@ -107,22 +107,22 @@ func GetReleaseIssue(repo, release string) string {
107107

108108
for _, issue := range issues {
109109
title := issue["title"]
110-
if strings.HasPrefix(title, fmt.Sprintf("Release of v%s", release)) {
111-
return issue["url"]
110+
prefix := "Release of v"
111+
if strings.HasPrefix(title, fmt.Sprintf("%s%s", prefix, release)) {
112+
return issue["url"], title[len(prefix):]
112113
}
113114
}
114-
115-
return ""
115+
return "", ""
116116
}
117117

118-
func GetReleaseIssueInfo(repo, release string) (nb int, url string) {
119-
url = GetReleaseIssue(repo, release)
118+
func GetReleaseIssueInfo(repo, majorRelease string) (nb int, url string, release string) {
119+
url, release = GetReleaseIssue(repo, majorRelease)
120120
if url == "" {
121121
// no issue found
122-
return 0, ""
122+
return 0, "", ""
123123
}
124124
nb = URLToNb(url)
125-
return nb, url
125+
return
126126
}
127127

128128
func URLToNb(url string) int {

go/releaser/issue.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,9 @@ func CreateReleaseIssue(state *State) (*logging.ProgressLogging, func() (int, st
386386
}
387387

388388
return pl, func() (int, string) {
389-
CorrectCleanRepo(state.VitessRepo)
390-
newRelease, _, _ := FindNextRelease(state.MajorRelease)
391-
392389
pl.NewStepf("Create Release Issue on GitHub")
393390
newIssue := github.Issue{
394-
Title: fmt.Sprintf("Release of v%s", newRelease),
391+
Title: fmt.Sprintf("Release of v%s", state.Release),
395392
Body: state.Issue.toString(),
396393
Labels: []github.Label{{Name: "Component: General"}, {Name: "Type: Release"}},
397394
Assignee: "@me",

go/releaser/milestone.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,12 @@ import (
2323
"strings"
2424
)
2525

26-
func FindVersionAfterNextRelease(ctx *State) string {
27-
CorrectCleanRepo(ctx.VitessRepo)
28-
nextRelease, _, _ := FindNextRelease(ctx.MajorRelease)
29-
30-
if strings.Contains(nextRelease, "rc") {
26+
func FindVersionAfterNextRelease(state *State) string {
27+
if strings.Contains(state.Release, "rc") {
3128
panic("RC releases not supported for now")
3229
}
3330

34-
segments := strings.Split(nextRelease, ".")
31+
segments := strings.Split(state.Release, ".")
3532
if len(segments) != 3 {
3633
return ""
3734
}

go/releaser/pre_release/code_freeze.go

+11-14
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,11 @@ func CodeFreeze(state *releaser.State) (*logging.ProgressLogging, func() string)
7575
pl.NewStepf("Issue updated, see: %s", issueLink)
7676
}()
7777

78-
git.CorrectCleanRepo(state.VitessRepo)
79-
nextRelease, branchName, _ := releaser.FindNextRelease(state.MajorRelease)
80-
8178
pl.NewStepf("Fetch from git remote")
82-
remote := git.FindRemoteName(state.VitessRepo)
83-
git.ResetHard(remote, branchName)
79+
git.CorrectCleanRepo(state.VitessRepo)
80+
git.ResetHard(state.Remote, state.ReleaseBranch)
8481

85-
codeFreezePRName := fmt.Sprintf("[%s] Code Freeze for `v%s`", branchName, nextRelease)
82+
codeFreezePRName := fmt.Sprintf("[%s] Code Freeze for `v%s`", state.ReleaseBranch, state.Release)
8683

8784
// look for existing code freeze PRs
8885
pl.NewStepf("Look for an existing Code Freeze Pull Request named '%s'", codeFreezePRName)
@@ -95,35 +92,35 @@ func CodeFreeze(state *releaser.State) (*logging.ProgressLogging, func() string)
9592
}
9693

9794
// check if the branch is already frozen or not
98-
pl.NewStepf("Check if branch %s is already frozen", branchName)
95+
pl.NewStepf("Check if branch %s is already frozen", state.ReleaseBranch)
9996
if isCurrentBranchFrozen() {
10097
pl.TotalSteps = 6 // only 6 total steps in this situation
101-
pl.NewStepf("Branch %s is already frozen, no action needed.", branchName)
98+
pl.NewStepf("Branch %s is already frozen, no action needed.", state.ReleaseBranch)
10299
done = true
103100
return ""
104101
}
105102

106-
pl.NewStepf("Create new branch based on %s/%s", remote, branchName)
107-
newBranchName := git.FindNewGeneratedBranch(remote, branchName, "code-freeze")
103+
pl.NewStepf("Create new branch based on %s/%s", state.Remote, state.ReleaseBranch)
104+
newBranchName := git.FindNewGeneratedBranch(state.Remote, state.ReleaseBranch, "code-freeze")
108105

109106
pl.NewStepf("Turn on code freeze on branch %s", newBranchName)
110107
activateCodeFreeze()
111108

112109
pl.NewStepf("Commit and push to branch %s", newBranchName)
113-
if git.CommitAll(fmt.Sprintf("Code Freeze of %s", branchName)) {
110+
if git.CommitAll(fmt.Sprintf("Code Freeze of %s", state.ReleaseBranch)) {
114111
pl.TotalSteps = 9 // only 9 total steps in this situation
115112
pl.NewStepf("Nothing to commit, seems like code freeze is already done.")
116113
done = true
117114
return ""
118115
}
119-
git.Push(remote, newBranchName)
116+
git.Push(state.Remote, newBranchName)
120117

121118
pl.NewStepf("Create Pull Request")
122119
pr := github.PR{
123120
Title: codeFreezePRName,
124-
Body: fmt.Sprintf("This Pull Request freezes the branch `%s` for `v%s`", branchName, nextRelease),
121+
Body: fmt.Sprintf("This Pull Request freezes the branch `%s` for `v%s`", state.ReleaseBranch, state.Release),
125122
Branch: newBranchName,
126-
Base: branchName,
123+
Base: state.ReleaseBranch,
127124
Labels: []github.Label{{Name: "Component: General"}, {Name: "Type: Release"}},
128125
}
129126
nb, url = pr.Create(state.VitessRepo)

go/releaser/pre_release/create_release_pr.go

+22-25
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,13 @@ func CreateReleasePR(state *releaser.State) (*logging.ProgressLogging, func() st
8383
}()
8484

8585
// setup
86-
git.CorrectCleanRepo(state.VitessRepo)
87-
nextRelease, branchName, _ := releaser.FindNextRelease(state.MajorRelease)
88-
8986
pl.NewStepf("Fetch from git remote")
90-
remote := git.FindRemoteName(state.VitessRepo)
91-
git.ResetHard(remote, branchName)
87+
git.CorrectCleanRepo(state.VitessRepo)
88+
git.ResetHard(state.Remote, state.ReleaseBranch)
9289

93-
releasePRName := fmt.Sprintf("[%s] Release of `v%s`", branchName, nextRelease)
90+
releasePRName := fmt.Sprintf("[%s] Release of `v%s`", state.ReleaseBranch, state.Release)
9491

95-
// look for existing code freeze PRs
92+
// look for existing PRs
9693
pl.NewStepf("Look for an existing Release Pull Request named '%s'", releasePRName)
9794
if _, url = github.FindPR(state.VitessRepo, releasePRName); url != "" {
9895
pl.TotalSteps = 5 // only 5 total steps in this situation
@@ -102,41 +99,41 @@ func CreateReleasePR(state *releaser.State) (*logging.ProgressLogging, func() st
10299
}
103100

104101
// find new branch to create the release
105-
pl.NewStepf("Create temporary branch from %s", branchName)
106-
newBranchName := git.FindNewGeneratedBranch(remote, branchName, "create-release")
102+
pl.NewStepf("Create temporary branch from %s", state.ReleaseBranch)
103+
newBranchName := git.FindNewGeneratedBranch(state.Remote, state.ReleaseBranch, "create-release")
107104

108105
// deactivate code freeze
109-
pl.NewStepf("Deactivate code freeze on %s", branchName)
106+
pl.NewStepf("Deactivate code freeze on %s", state.ReleaseBranch)
110107
deactivateCodeFreeze()
111108

112-
pl.NewStepf("Commit unfreezing the branch %s", branchName)
113-
if !git.CommitAll(fmt.Sprintf("Unfreeze branch %s", branchName)) {
109+
pl.NewStepf("Commit unfreezing the branch %s", state.ReleaseBranch)
110+
if !git.CommitAll(fmt.Sprintf("Unfreeze branch %s", state.ReleaseBranch)) {
114111
commitCount++
115-
git.Push(remote, newBranchName)
112+
git.Push(state.Remote, newBranchName)
116113
}
117114

118115
pl.NewStepf("Generate the release notes")
119-
generateReleaseNotes(state, nextRelease)
116+
generateReleaseNotes(state, state.Release)
120117

121118
pl.NewStepf("Commit the release notes")
122119
if !git.CommitAll("Addition of release notes") {
123120
commitCount++
124-
git.Push(remote, newBranchName)
121+
git.Push(state.Remote, newBranchName)
125122
}
126123

127124
pl.NewStepf("Update the code examples")
128-
updateExamples(nextRelease, "") // TODO: vitess-operator version not implemented
125+
updateExamples(state.Release, "") // TODO: vitess-operator version not implemented
129126

130127
pl.NewStepf("Update version.go")
131-
updateVersionGoFile(nextRelease)
128+
UpdateVersionGoFile(state.Release)
132129

133130
pl.NewStepf("Update the Java directory")
134-
updateJavaDir(nextRelease)
131+
UpdateJavaDir(state.Release)
135132

136-
pl.NewStepf("Commit the update to the codebase for the v%s release", nextRelease)
137-
if !git.CommitAll(fmt.Sprintf("Update codebase for the v%s release", nextRelease)) {
133+
pl.NewStepf("Commit the update to the codebase for the v%s release", state.Release)
134+
if !git.CommitAll(fmt.Sprintf("Update codebase for the v%s release", state.Release)) {
138135
commitCount++
139-
git.Push(remote, newBranchName)
136+
git.Push(state.Remote, newBranchName)
140137
}
141138

142139
if commitCount == 0 {
@@ -149,9 +146,9 @@ func CreateReleasePR(state *releaser.State) (*logging.ProgressLogging, func() st
149146
pl.NewStepf("Create Pull Request")
150147
pr := github.PR{
151148
Title: releasePRName,
152-
Body: fmt.Sprintf("Includes the release notes and release commit for the `v%s` release. Once this PR is merged, we will be able to tag `v%s` on the merge commit.", nextRelease, nextRelease),
149+
Body: fmt.Sprintf("Includes the release notes and release commit for the `v%s` release. Once this PR is merged, we will be able to tag `v%s` on the merge commit.", state.Release, state.Release),
153150
Branch: newBranchName,
154-
Base: branchName,
151+
Base: state.ReleaseBranch,
155152
Labels: []github.Label{{Name: "Component: General"}, {Name: "Type: Release"}, {Name: "Do Not Merge"}},
156153
}
157154
_, url = pr.Create(state.VitessRepo)
@@ -231,14 +228,14 @@ func updateExamples(newVersion, vtopNewVersion string) {
231228
}
232229
}
233230

234-
func updateVersionGoFile(newVersion string) {
231+
func UpdateVersionGoFile(newVersion string) {
235232
err := os.WriteFile(versionGoFile, []byte(fmt.Sprintf(versionGo, time.Now().Year(), newVersion)), os.ModePerm)
236233
if err != nil {
237234
log.Fatal(err)
238235
}
239236
}
240237

241-
func updateJavaDir(newVersion string) {
238+
func UpdateJavaDir(newVersion string) {
242239
// cd $ROOT/java || exit 1
243240
// mvn versions:set -DnewVersion=$1
244241
cmd := exec.Command("mvn", "versions:set", fmt.Sprintf("-DnewVersion=%s", newVersion))

go/releaser/prerequisite/summary.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ import (
2323
)
2424

2525
func CheckSummary(state *releaser.State) []string {
26-
r, _, _ := releaser.FindNextRelease(state.MajorRelease)
2726
return []string{
2827
"If the release does not contain significant changes (i.e. a small patch release) then this step can be skipped",
29-
fmt.Sprintf("The summary file is located in: ./changelog/%s.0/%s/summary.md.", state.MajorRelease, r),
28+
fmt.Sprintf("The summary file is located in: ./changelog/%s.0/%s/summary.md.", state.MajorRelease, state.Release),
3029
"The summary file for a release candidate is the same as the one for the GA release.",
3130
}
3231
}

0 commit comments

Comments
 (0)