Skip to content

Commit 06fed2a

Browse files
authored
Merge pull request #45 from vitessio/release-notes-on-main
Copy release notes to main branch
2 parents 5b0f823 + 21685d5 commit 06fed2a

File tree

5 files changed

+127
-3
lines changed

5 files changed

+127
-3
lines changed

go/interactive/release/release_notes_to_main.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 ReleaseNotesOnMainItem(ctx context.Context) *ui.MenuItem {
4445
type releaseNotesOnMainUrl string
4546

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

5058
func releaseNotesOnMainAct(mi *ui.MenuItem) (*ui.MenuItem, tea.Cmd) {
51-
return mi, nil
59+
pl, fn := release.ReleaseNotesOnMain(mi.State)
60+
return mi, tea.Batch(func() tea.Msg {
61+
return releaseNotesOnMainUrl(fn())
62+
}, ui.PushDialog(ui.NewProgressDialog("Release Notes on Main", pl)))
5263
}

go/releaser/git/git.go

+7
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,10 @@ func GetSHAForGitRef(ref string) string {
178178
}
179179
return strings.ReplaceAll(string(out), "\n", "")
180180
}
181+
182+
func CheckoutPath(remote, branch, path string) {
183+
out, err := exec.Command("git", "checkout", fmt.Sprintf("%s/%s", remote, branch), path).CombinedOutput()
184+
if err != nil {
185+
log.Fatalf("%s: %s", err, out)
186+
}
187+
}

go/releaser/pre_release/code_freeze.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func CodeFreeze(state *releaser.State) (*logging.ProgressLogging, func() string)
112112
pl.NewStepf("Commit and push to branch %s", newBranchName)
113113
if git.CommitAll(fmt.Sprintf("Code Freeze of %s", branchName)) {
114114
pl.TotalSteps = 9 // only 9 total steps in this situation
115-
pl.NewStepf("Nothing to commit, seems like code freeze is already done.", newBranchName)
115+
pl.NewStepf("Nothing to commit, seems like code freeze is already done.")
116116
done = true
117117
return ""
118118
}

go/releaser/pre_release/release_notes.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ The entire changelog for this release can be found [here]({{ .PathToChangeLogFil
116116
)
117117

118118
func GetReleaseNotesDirPath(version string) string {
119+
prefix, major, patch := getSegmentOfReleaseNotesDir(version)
120+
return path.Join(prefix, major, patch)
121+
}
122+
123+
func GetReleaseNotesDirPathForMajor(version string) string {
124+
prefix, major, _ := getSegmentOfReleaseNotesDir(version)
125+
return path.Join(prefix, major)
126+
}
127+
128+
func getSegmentOfReleaseNotesDir(version string) (prefix string, major string, patch string) {
119129
// There should be 4 sub-matches, input: "14.0.0", output: ["14.0.0", "14", "0", "0"].
120130
rx := regexp.MustCompile(`([0-9]+)\.([0-9]+)\.([0-9]+)`)
121131
versionMatch := rx.FindStringSubmatch(version)
@@ -125,7 +135,7 @@ func GetReleaseNotesDirPath(version string) string {
125135

126136
majorVersion := versionMatch[1] + "." + versionMatch[2]
127137
patchVersion := versionMatch[1] + "." + versionMatch[2] + "." + versionMatch[3]
128-
return path.Join(releaseNotesPathPrefix, majorVersion, patchVersion)
138+
return releaseNotesPathPrefix, majorVersion, patchVersion
129139
}
130140

131141
func generateReleaseNotes(state *releaser.State, version string) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
Copyright 2023 The Vitess Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package release
18+
19+
import (
20+
"fmt"
21+
22+
"vitess.io/vitess-releaser/go/releaser"
23+
"vitess.io/vitess-releaser/go/releaser/git"
24+
"vitess.io/vitess-releaser/go/releaser/github"
25+
"vitess.io/vitess-releaser/go/releaser/logging"
26+
"vitess.io/vitess-releaser/go/releaser/pre_release"
27+
)
28+
29+
func ReleaseNotesOnMain(state *releaser.State) (*logging.ProgressLogging, func() string) {
30+
pl := &logging.ProgressLogging{
31+
TotalSteps: 9,
32+
}
33+
34+
var done bool
35+
var url string
36+
return pl, func() string {
37+
defer func() {
38+
state.Issue.ReleaseNotesOnMain.Done = done
39+
state.Issue.ReleaseNotesOnMain.URL = url
40+
pl.NewStepf("Update Issue %s on GitHub", state.IssueLink)
41+
_, fn := state.UploadIssue()
42+
issueLink := fn()
43+
44+
pl.NewStepf("Issue updated, see: %s", issueLink)
45+
}()
46+
47+
git.CorrectCleanRepo(state.VitessRepo)
48+
nextRelease, branchName, _ := releaser.FindNextRelease(state.MajorRelease)
49+
50+
pl.NewStepf("Fetch from git remote")
51+
remote := git.FindRemoteName(state.VitessRepo)
52+
git.ResetHard(remote, branchName)
53+
54+
git.Checkout("main")
55+
git.ResetHard(remote, "main")
56+
57+
prName := fmt.Sprintf("Copy `v%s` release notes on `main`", nextRelease)
58+
59+
pl.NewStepf("Look for an existing Pull Request named '%s'", prName)
60+
if _, url = github.FindPR(state.VitessRepo, prName); url != "" {
61+
pl.TotalSteps = 5 // only 5 total steps in this situation
62+
pl.NewStepf("An opened Pull Request was found: %s", url)
63+
done = true
64+
return url
65+
}
66+
67+
pl.NewStepf("Create new branch based on %s/main", remote)
68+
newBranchName := git.FindNewGeneratedBranch(remote, "main", "release-notes-main")
69+
70+
pl.NewStepf("Copy release notes from %s/%s", remote, branchName)
71+
releaseNotesPath := pre_release.GetReleaseNotesDirPathForMajor(nextRelease)
72+
git.CheckoutPath(remote, branchName, releaseNotesPath)
73+
74+
pl.NewStepf("Commit and push to branch %s", newBranchName)
75+
if git.CommitAll(fmt.Sprintf("Copy release notes from %s into main", branchName)) {
76+
pl.TotalSteps = 8 // only 8 total steps in this situation
77+
pl.NewStepf("Nothing to commit, seems like the release notes have already been copied")
78+
done = true
79+
return ""
80+
}
81+
git.Push(remote, newBranchName)
82+
83+
pl.NewStepf("Create Pull Request")
84+
pr := github.PR{
85+
Title: prName,
86+
Body: fmt.Sprintf("This Pull Request copies the release notes found on `%s` to keep release notes up-to-date after the `v%s` release.", branchName, nextRelease),
87+
Branch: newBranchName,
88+
Base: "main",
89+
Labels: []github.Label{{Name: "Component: General"}, {Name: "Type: Release"}},
90+
}
91+
_, url = pr.Create(state.VitessRepo)
92+
pl.NewStepf("Pull Request created %s", url)
93+
done = true
94+
return url
95+
}
96+
}

0 commit comments

Comments
 (0)