Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0ac8a98

Browse files
dmitshurgopherbot
authored andcommitted
internal/task: build internal security branch for next RC too
In the second half of the go.dev/s/release cycle, after entering the release freeze and before releasing the first pre-release (RC 1), a release branch for the next major Go release is cut. Security fixes for minors may apply to that upcoming major Go release too, so include said branch in the 'Prepare internal security release branches' workflow whenever it exists. This way there won't be a need to create it manually. For golang/go#59717. Change-Id: Ic54e0c43b7b3fd4a81f1ba83e227851a693da1a0 Reviewed-on: https://go-review.googlesource.com/c/build/+/685516 Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent dd1452c commit 0ac8a98

File tree

2 files changed

+96
-27
lines changed

2 files changed

+96
-27
lines changed

internal/task/security_release_coalesce.go

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
// 3. Moves all patches from master onto the new branch
3131
// 4. Submits the rebased patches
3232
// 5. Create internal release branches
33-
// 6. Creates cherry-picks of the submitted patches onto the two release branches,
33+
// 6. Creates cherry-picks of the submitted patches onto the release branches,
3434
// setting Commit-Queue+1
3535
type SecurityReleaseCoalesceTask struct {
3636
PrivateGerrit GerritClient
@@ -94,14 +94,33 @@ func (x *SecurityReleaseCoalesceTask) GetBranchNames(ctx *wf.TaskContext) (branc
9494
if err != nil {
9595
return branchInfo{}, err
9696
}
97-
98-
return branchInfo{
99-
CheckpointName: fmt.Sprintf("%s-and-%s-checkpoint", nextMinors[0], nextMinors[1]),
100-
PublicReleaseBranches: []string{
101-
fmt.Sprintf("release-branch.%s", nextMinors[0]),
102-
fmt.Sprintf("release-branch.%s", nextMinors[1]),
103-
},
104-
}, nil
97+
switch _, err := x.Version.Gerrit.ReadBranchHead(ctx, "go", fmt.Sprintf("release-branch.go1.%d", currentMajor+1)); {
98+
case errors.Is(err, gerrit.ErrResourceNotExist):
99+
// The next release branch hasn't been cut yet. Include release branches for minors only.
100+
return branchInfo{
101+
CheckpointName: fmt.Sprintf("%s-%s-checkpoint", nextMinors[0], nextMinors[1]),
102+
PublicReleaseBranches: []string{
103+
fmt.Sprintf("release-branch.%s", nextMinors[0]),
104+
fmt.Sprintf("release-branch.%s", nextMinors[1]),
105+
},
106+
}, nil
107+
case err == nil:
108+
// Include release branches for the minors and the next release candidate.
109+
nextRC, err := x.Version.GetNextVersion(ctx, currentMajor+1, KindRC)
110+
if err != nil {
111+
return branchInfo{}, err
112+
}
113+
return branchInfo{
114+
CheckpointName: fmt.Sprintf("%s-%s-%s-checkpoint", nextRC, nextMinors[0], nextMinors[1]),
115+
PublicReleaseBranches: []string{
116+
fmt.Sprintf("release-branch.%s", nextRC),
117+
fmt.Sprintf("release-branch.%s", nextMinors[0]),
118+
fmt.Sprintf("release-branch.%s", nextMinors[1]),
119+
},
120+
}, nil
121+
default:
122+
return branchInfo{}, err
123+
}
105124
}
106125

107126
func (x *SecurityReleaseCoalesceTask) CheckChanges(ctx *wf.TaskContext, clNums []string) ([]*gerrit.ChangeInfo, error) {
@@ -202,9 +221,8 @@ func (x *SecurityReleaseCoalesceTask) WaitAndSubmit(ctx *wf.TaskContext, cls []*
202221
return cls, nil
203222
}
204223

205-
// majorFromMinor converts a release branch name from it's minor version form to
206-
// it's major version form (i.e. release-branch.go1.2.3 to
207-
// release-branch.go1.2).
224+
// majorFromMinor converts a release branch name from its minor version form to
225+
// its major version form (i.e., release-branch.go1.2.3 to release-branch.go1.2).
208226
func majorFromMinor(branch string) string {
209227
stripped := strings.TrimPrefix(branch, "release-branch.")
210228
major := goversion.Lang(stripped)
@@ -215,12 +233,12 @@ var internalReleaseBranchPrefix = "internal-"
215233

216234
func (x *SecurityReleaseCoalesceTask) CreateInternalReleaseBranches(ctx *wf.TaskContext, bi branchInfo) ([]string, error) {
217235
var internalBranches []string
218-
for _, nextMinor := range bi.PublicReleaseBranches {
219-
publicHead, err := x.PrivateGerrit.ReadBranchHead(ctx, "go", majorFromMinor(nextMinor))
236+
for _, next := range bi.PublicReleaseBranches {
237+
publicHead, err := x.PrivateGerrit.ReadBranchHead(ctx, "go", majorFromMinor(next))
220238
if err != nil {
221239
return nil, err
222240
}
223-
internalReleaseBranch := internalReleaseBranchPrefix + nextMinor
241+
internalReleaseBranch := internalReleaseBranchPrefix + next
224242
if _, err := x.PrivateGerrit.CreateBranch(ctx, "go", internalReleaseBranch, gerrit.BranchInput{Revision: publicHead}); err != nil {
225243
return nil, err
226244
}
@@ -230,7 +248,7 @@ func (x *SecurityReleaseCoalesceTask) CreateInternalReleaseBranches(ctx *wf.Task
230248
}
231249

232250
func (x *SecurityReleaseCoalesceTask) CreateCherryPicks(ctx *wf.TaskContext, releaseBranches []string, cls []*gerrit.ChangeInfo) (map[string][]string, error) {
233-
// TODO: this currently assumes we want to cherry-pick everything to both
251+
// TODO: this currently assumes we want to cherry-pick everything to all
234252
// branches, which is _normally_ the case, but sometimes is not accurate. We
235253
// can manually just abandon cherry-picks we don't care about, but probably
236254
// we should have a way to indicate which branches we want each patch

internal/task/security_release_coalesce_test.go

Lines changed: 62 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,31 +91,59 @@ func (g *fakeCoalesceGerrit) GetCommitMessage(ctx context.Context, changeID stri
9191

9292
type securityVersionClient struct {
9393
GerritClient
94-
tags []string
94+
tags, branches []string
9595
}
9696

97-
func (c *securityVersionClient) ListTags(ctx context.Context, project string) ([]string, error) {
97+
func (c *securityVersionClient) ListTags(_ context.Context, project string) ([]string, error) {
98+
if project != "go" {
99+
return nil, nil
100+
}
98101
return c.tags, nil
99102
}
100103

101-
func (c *securityVersionClient) GetTag(ctx context.Context, project, tag string) (gerrit.TagInfo, error) {
104+
func (c *securityVersionClient) GetTag(_ context.Context, project, tag string) (gerrit.TagInfo, error) {
105+
if project != "go" {
106+
return gerrit.TagInfo{}, gerrit.ErrResourceNotExist
107+
}
102108
for _, t := range c.tags {
103109
if tag == t {
104110
return gerrit.TagInfo{Created: gerrit.TimeStamp(time.Now())}, nil
105111
}
106112
}
107-
return gerrit.TagInfo{}, errors.New("not found")
113+
return gerrit.TagInfo{}, gerrit.ErrResourceNotExist
114+
}
115+
116+
func (c *securityVersionClient) ReadBranchHead(_ context.Context, project, branch string) (string, error) {
117+
if project != "go" {
118+
return "", gerrit.ErrResourceNotExist
119+
}
120+
if !slices.Contains(c.branches, branch) {
121+
return "", gerrit.ErrResourceNotExist
122+
}
123+
return branch + "-head", nil
108124
}
109125

110126
func TestSecurityReleaseCoalesceTask(t *testing.T) {
127+
t.Run("minors only", func(t *testing.T) {
128+
testSecurityReleaseCoalesceTask(t, false)
129+
})
130+
t.Run("minors with RC", func(t *testing.T) {
131+
testSecurityReleaseCoalesceTask(t, true)
132+
})
133+
}
134+
135+
func testSecurityReleaseCoalesceTask(t *testing.T, withNextReleaseBranch bool) {
136+
publicTags := []string{"go1.3", "go1.3.1", "go1.4", "go1.4.1"}
137+
publicBranches := []string{"release-branch.go1.3", "release-branch.go1.4"}
138+
if withNextReleaseBranch {
139+
publicBranches = append(publicBranches, "release-branch.go1.5")
140+
}
111141
privRepo := NewFakeRepo(t, "go")
112142
privGerrit := &fakeCoalesceGerrit{FakeGerrit: NewFakeGerrit(t, privRepo), cherryPicks: map[string][]cherryPickedCommit{}, commitMessages: map[string]string{}}
113143
task := &SecurityReleaseCoalesceTask{
114144
PrivateGerrit: privGerrit,
115145
Version: &VersionTasks{
116-
Gerrit: &securityVersionClient{
117-
tags: []string{"go1.3", "go1.3.1", "go1.4", "go1.4.1"},
118-
},
146+
Gerrit: &securityVersionClient{tags: publicTags, branches: publicBranches},
119147
GoProject: "go",
120148
},
121149
}
@@ -152,9 +180,12 @@ other body`,
152180
privRepo.Branch("public", head)
153181
privRepo.Branch("release-branch.go1.3", head)
154182
privRepo.Branch("release-branch.go1.4", head)
183+
if withNextReleaseBranch {
184+
privRepo.Branch("release-branch.go1.5", head)
185+
}
155186

156187
wd := task.NewDefinition()
157-
w, err := wf.Start(wd, map[string]interface{}{
188+
w, err := wf.Start(wd, map[string]any{
158189
"Security Patch CL Numbers": []string{"1234", "5678"},
159190
})
160191
if err != nil {
@@ -168,14 +199,18 @@ other body`,
168199
}
169200

170201
// Check checkpoint branch has the expected number of submitted changes
171-
commits := len(strings.Split(string(privRepo.runGit("log", "go1.4.2-and-go1.3.2-checkpoint", "--format=%H")), "\n")) - 1
202+
checkpointBranch := "go1.4.2-go1.3.2-checkpoint"
203+
if withNextReleaseBranch {
204+
checkpointBranch = "go1.5rc1-go1.4.2-go1.3.2-checkpoint"
205+
}
206+
commits := len(strings.Split(string(privRepo.runGit("log", checkpointBranch, "--format=%H")), "\n")) - 1
172207
if commits != 3 {
173208
t.Errorf("unexpected number of commits on checkpoint branch: got %d, want 3", commits)
174209
}
175210

176211
// Check each internal release branch has the expected cherry-picks
177212
expected := map[string][]cherryPickedCommit{
178-
"internal-release-branch.go1.4.2": []cherryPickedCommit{
213+
"internal-release-branch.go1.4.2": {
179214
{
180215
changeID: "1234",
181216
message: `[release-branch.go1.4] subject: 1234
@@ -189,7 +224,7 @@ body`,
189224
other body`,
190225
},
191226
},
192-
"internal-release-branch.go1.3.2": []cherryPickedCommit{
227+
"internal-release-branch.go1.3.2": {
193228
{
194229
changeID: "1234",
195230
message: `[release-branch.go1.3] subject: 1234
@@ -204,6 +239,22 @@ other body`,
204239
},
205240
},
206241
}
242+
if withNextReleaseBranch {
243+
expected["internal-release-branch.go1.5rc1"] = []cherryPickedCommit{
244+
{
245+
changeID: "1234",
246+
message: `[release-branch.go1.5] subject: 1234
247+
248+
body`,
249+
},
250+
{
251+
changeID: "5678",
252+
message: `[release-branch.go1.5] subject: 5678
253+
254+
other body`,
255+
},
256+
}
257+
}
207258

208259
for branch, commits := range privGerrit.cherryPicks {
209260
if !slices.Equal(commits, expected[branch]) {

0 commit comments

Comments
 (0)