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

Implement back to dev mode #46

Merged
merged 5 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
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
15 changes: 13 additions & 2 deletions go/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,20 @@ func Execute() {
s.MajorRelease = releaseVersion

git.CorrectCleanRepo(s.VitessRepo)
nextRelease, _, _ := releaser.FindNextRelease(s.MajorRelease)

s.IssueNbGH, s.IssueLink = github.GetReleaseIssueInfo(s.VitessRepo, nextRelease)
remote := git.FindRemoteName(s.VitessRepo)
release, releaseBranch, isLatestRelease := releaser.FindNextRelease(remote, s.MajorRelease)
issueNb, issueLink, releaseFromIssue := github.GetReleaseIssueInfo(s.VitessRepo, s.MajorRelease)

s.Remote = remote
s.ReleaseBranch = releaseBranch
s.IsLatestRelease = isLatestRelease
s.IssueNbGH = issueNb
s.IssueLink = issueLink
s.Release = releaseFromIssue
if releaseFromIssue == "" {
s.Release = release
}

// We only require the release date if the release issue does not exist on GH
// If the issue already exist we ignore the flag, the value will be loaded from the Issue
Expand Down
13 changes: 12 additions & 1 deletion go/interactive/release/back_to_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
tea "github.com/charmbracelet/bubbletea"
"vitess.io/vitess-releaser/go/interactive/ui"
"vitess.io/vitess-releaser/go/releaser"
"vitess.io/vitess-releaser/go/releaser/release"
"vitess.io/vitess-releaser/go/releaser/steps"
)

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

func backToDevModeUpdate(mi *ui.MenuItem, msg tea.Msg) (*ui.MenuItem, tea.Cmd) {
_, ok := msg.(backToDevModeUrl)
if !ok {
return mi, nil
}

mi.Info = mi.State.Issue.BackToDevMode.URL
mi.IsDone = mi.State.Issue.BackToDevMode.Done
return mi, nil
}

func backToDevModeAct(mi *ui.MenuItem) (*ui.MenuItem, tea.Cmd) {
return mi, nil
pl, back := release.BackToDevMode(mi.State)
return mi, tea.Batch(func() tea.Msg {
return backToDevModeUrl(back())
}, ui.PushDialog(ui.NewProgressDialog("Back To Dev Mode", pl)))
}
16 changes: 11 additions & 5 deletions go/releaser/ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ func WrapState(ctx context.Context, s *State) context.Context {
}

type State struct {
VitessRepo string
MajorRelease string
IssueNbGH int
IssueLink string
Issue Issue
VitessRepo string
Remote string
ReleaseBranch string

MajorRelease string
Release string
IsLatestRelease bool

Issue Issue
IssueLink string
IssueNbGH int
}
18 changes: 9 additions & 9 deletions go/releaser/github/issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func GetIssueBody(repo string, nb int) string {
return i.Body
}

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

for _, issue := range issues {
title := issue["title"]
if strings.HasPrefix(title, fmt.Sprintf("Release of v%s", release)) {
return issue["url"]
prefix := "Release of v"
if strings.HasPrefix(title, fmt.Sprintf("%s%s", prefix, release)) {
return issue["url"], title[len(prefix):]
}
}

return ""
return "", ""
}

func GetReleaseIssueInfo(repo, release string) (nb int, url string) {
url = GetReleaseIssue(repo, release)
func GetReleaseIssueInfo(repo, majorRelease string) (nb int, url string, release string) {
url, release = GetReleaseIssue(repo, majorRelease)
if url == "" {
// no issue found
return 0, ""
return 0, "", ""
}
nb = URLToNb(url)
return nb, url
return
}

func URLToNb(url string) int {
Expand Down
5 changes: 1 addition & 4 deletions go/releaser/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,9 @@ func CreateReleaseIssue(state *State) (*logging.ProgressLogging, func() (int, st
}

return pl, func() (int, string) {
CorrectCleanRepo(state.VitessRepo)
newRelease, _, _ := FindNextRelease(state.MajorRelease)

pl.NewStepf("Create Release Issue on GitHub")
newIssue := github.Issue{
Title: fmt.Sprintf("Release of v%s", newRelease),
Title: fmt.Sprintf("Release of v%s", state.Release),
Body: state.Issue.toString(),
Labels: []github.Label{{Name: "Component: General"}, {Name: "Type: Release"}},
Assignee: "@me",
Expand Down
9 changes: 3 additions & 6 deletions go/releaser/milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ import (
"strings"
)

func FindVersionAfterNextRelease(ctx *State) string {
CorrectCleanRepo(ctx.VitessRepo)
nextRelease, _, _ := FindNextRelease(ctx.MajorRelease)

if strings.Contains(nextRelease, "rc") {
func FindVersionAfterNextRelease(state *State) string {
if strings.Contains(state.Release, "rc") {
panic("RC releases not supported for now")
}

segments := strings.Split(nextRelease, ".")
segments := strings.Split(state.Release, ".")
if len(segments) != 3 {
return ""
}
Expand Down
25 changes: 11 additions & 14 deletions go/releaser/pre_release/code_freeze.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,11 @@ func CodeFreeze(state *releaser.State) (*logging.ProgressLogging, func() string)
pl.NewStepf("Issue updated, see: %s", issueLink)
}()

git.CorrectCleanRepo(state.VitessRepo)
nextRelease, branchName, _ := releaser.FindNextRelease(state.MajorRelease)

pl.NewStepf("Fetch from git remote")
remote := git.FindRemoteName(state.VitessRepo)
git.ResetHard(remote, branchName)
git.CorrectCleanRepo(state.VitessRepo)
git.ResetHard(state.Remote, state.ReleaseBranch)

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

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

// check if the branch is already frozen or not
pl.NewStepf("Check if branch %s is already frozen", branchName)
pl.NewStepf("Check if branch %s is already frozen", state.ReleaseBranch)
if isCurrentBranchFrozen() {
pl.TotalSteps = 6 // only 6 total steps in this situation
pl.NewStepf("Branch %s is already frozen, no action needed.", branchName)
pl.NewStepf("Branch %s is already frozen, no action needed.", state.ReleaseBranch)
done = true
return ""
}

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

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

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

pl.NewStepf("Create Pull Request")
pr := github.PR{
Title: codeFreezePRName,
Body: fmt.Sprintf("This Pull Request freezes the branch `%s` for `v%s`", branchName, nextRelease),
Body: fmt.Sprintf("This Pull Request freezes the branch `%s` for `v%s`", state.ReleaseBranch, state.Release),
Branch: newBranchName,
Base: branchName,
Base: state.ReleaseBranch,
Labels: []github.Label{{Name: "Component: General"}, {Name: "Type: Release"}},
}
nb, url = pr.Create(state.VitessRepo)
Expand Down
47 changes: 22 additions & 25 deletions go/releaser/pre_release/create_release_pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,13 @@ func CreateReleasePR(state *releaser.State) (*logging.ProgressLogging, func() st
}()

// setup
git.CorrectCleanRepo(state.VitessRepo)
nextRelease, branchName, _ := releaser.FindNextRelease(state.MajorRelease)

pl.NewStepf("Fetch from git remote")
remote := git.FindRemoteName(state.VitessRepo)
git.ResetHard(remote, branchName)
git.CorrectCleanRepo(state.VitessRepo)
git.ResetHard(state.Remote, state.ReleaseBranch)

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

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

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

// deactivate code freeze
pl.NewStepf("Deactivate code freeze on %s", branchName)
pl.NewStepf("Deactivate code freeze on %s", state.ReleaseBranch)
deactivateCodeFreeze()

pl.NewStepf("Commit unfreezing the branch %s", branchName)
if !git.CommitAll(fmt.Sprintf("Unfreeze branch %s", branchName)) {
pl.NewStepf("Commit unfreezing the branch %s", state.ReleaseBranch)
if !git.CommitAll(fmt.Sprintf("Unfreeze branch %s", state.ReleaseBranch)) {
commitCount++
git.Push(remote, newBranchName)
git.Push(state.Remote, newBranchName)
}

pl.NewStepf("Generate the release notes")
generateReleaseNotes(state, nextRelease)
generateReleaseNotes(state, state.Release)

pl.NewStepf("Commit the release notes")
if !git.CommitAll("Addition of release notes") {
commitCount++
git.Push(remote, newBranchName)
git.Push(state.Remote, newBranchName)
}

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

pl.NewStepf("Update version.go")
updateVersionGoFile(nextRelease)
UpdateVersionGoFile(state.Release)

pl.NewStepf("Update the Java directory")
updateJavaDir(nextRelease)
UpdateJavaDir(state.Release)

pl.NewStepf("Commit the update to the codebase for the v%s release", nextRelease)
if !git.CommitAll(fmt.Sprintf("Update codebase for the v%s release", nextRelease)) {
pl.NewStepf("Commit the update to the codebase for the v%s release", state.Release)
if !git.CommitAll(fmt.Sprintf("Update codebase for the v%s release", state.Release)) {
commitCount++
git.Push(remote, newBranchName)
git.Push(state.Remote, newBranchName)
}

if commitCount == 0 {
Expand All @@ -149,9 +146,9 @@ func CreateReleasePR(state *releaser.State) (*logging.ProgressLogging, func() st
pl.NewStepf("Create Pull Request")
pr := github.PR{
Title: releasePRName,
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),
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),
Branch: newBranchName,
Base: branchName,
Base: state.ReleaseBranch,
Labels: []github.Label{{Name: "Component: General"}, {Name: "Type: Release"}, {Name: "Do Not Merge"}},
}
_, url = pr.Create(state.VitessRepo)
Expand Down Expand Up @@ -231,14 +228,14 @@ func updateExamples(newVersion, vtopNewVersion string) {
}
}

func updateVersionGoFile(newVersion string) {
func UpdateVersionGoFile(newVersion string) {
err := os.WriteFile(versionGoFile, []byte(fmt.Sprintf(versionGo, time.Now().Year(), newVersion)), os.ModePerm)
if err != nil {
log.Fatal(err)
}
}

func updateJavaDir(newVersion string) {
func UpdateJavaDir(newVersion string) {
// cd $ROOT/java || exit 1
// mvn versions:set -DnewVersion=$1
cmd := exec.Command("mvn", "versions:set", fmt.Sprintf("-DnewVersion=%s", newVersion))
Expand Down
3 changes: 1 addition & 2 deletions go/releaser/prerequisite/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ import (
)

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