Skip to content

Commit 4237ab0

Browse files
heschigopherbot
authored andcommitted
internal/task: clean up tagging commit selection logic
Clean up after the change to read the branch head later. Also fix a bug: in the version tasks, we want to know exactly what commit we're tagging, so we pass in the expected commit, and AwaitCL returns that if no CL was necessary. But here we want to tag the latest branch head if there's no CL necessary. So we need a different Await function. For golang/go#48523. Change-Id: I97f92b22d4f29edeb52d06c311fddaa6596da0c2 Reviewed-on: https://go-review.googlesource.com/c/build/+/444116 Reviewed-by: Dmitri Shuralyov <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Heschi Kreinick <[email protected]> Run-TryBot: Heschi Kreinick <[email protected]>
1 parent ecfc0ef commit 4237ab0

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

Diff for: internal/task/tagx.go

+22-9
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,15 @@ func (x *TagXReposTasks) planRepo(wd *wf.Definition, repo TagRepo, updated map[s
253253
wd = wd.Sub(repo.Name)
254254
repoName, branch := wf.Const(repo.Name), wf.Const("master")
255255

256-
head := wf.Task2(wd, "read branch head", x.Gerrit.ReadBranchHead, repoName, branch)
257-
tagCandidate := head
258-
if len(deps) != 0 {
259-
gomod := wf.Task3(wd, "generate updated go.mod", x.UpdateGoMod, wf.Const(repo), wf.Slice(deps...), head)
256+
var tagCommit wf.Value[string]
257+
if len(deps) == 0 {
258+
tagCommit = wf.Task2(wd, "read branch head", x.Gerrit.ReadBranchHead, repoName, branch)
259+
} else {
260+
gomod := wf.Task3(wd, "generate updated go.mod", x.UpdateGoMod, wf.Const(repo), wf.Slice(deps...), branch)
260261
cl := wf.Task2(wd, "mail updated go.mod", x.MailGoMod, repoName, gomod)
261-
versionTasks := &VersionTasks{Gerrit: x.Gerrit}
262-
tagCandidate = wf.Task2(wd, "wait for submit", versionTasks.AwaitCL, cl, wf.Const(""))
262+
tagCommit = wf.Task3(wd, "wait for submit", x.AwaitGoMod, cl, repoName, branch)
263263
}
264-
greenCommit := wf.Task2(wd, "wait for green post-submit", x.AwaitGreen, wf.Const(repo), tagCandidate)
264+
greenCommit := wf.Task2(wd, "wait for green post-submit", x.AwaitGreen, wf.Const(repo), tagCommit)
265265
tagged := wf.Task2(wd, "tag if appropriate", x.MaybeTag, wf.Const(repo), greenCommit)
266266
return tagged, true
267267
}
@@ -270,8 +270,8 @@ type UpdatedModSum struct {
270270
Mod, Sum string
271271
}
272272

273-
func (x *TagXReposTasks) UpdateGoMod(ctx *wf.TaskContext, repo TagRepo, deps []TagRepo, _ string) (UpdatedModSum, error) {
274-
commit, err := x.Gerrit.ReadBranchHead(ctx, repo.Name, "master")
273+
func (x *TagXReposTasks) UpdateGoMod(ctx *wf.TaskContext, repo TagRepo, deps []TagRepo, branch string) (UpdatedModSum, error) {
274+
commit, err := x.Gerrit.ReadBranchHead(ctx, repo.Name, branch)
275275
if err != nil {
276276
return UpdatedModSum{}, err
277277
}
@@ -391,6 +391,19 @@ will be tagged with its next minor version.
391391
"go.sum": gomod.Sum,
392392
})
393393
}
394+
395+
func (x *TagXReposTasks) AwaitGoMod(ctx *wf.TaskContext, changeID, repo, branch string) (string, error) {
396+
if changeID == "" {
397+
ctx.Printf("No CL was necessary")
398+
return x.Gerrit.ReadBranchHead(ctx, repo, branch)
399+
}
400+
401+
ctx.Printf("Awaiting review/submit of %v", ChangeLink(changeID))
402+
return AwaitCondition(ctx, 10*time.Second, func() (string, bool, error) {
403+
return x.Gerrit.Submitted(ctx, changeID, "")
404+
})
405+
}
406+
394407
func (x *TagXReposTasks) AwaitGreen(ctx *wf.TaskContext, repo TagRepo, commit string) (string, error) {
395408
return AwaitCondition(ctx, time.Minute, func() (string, bool, error) {
396409
return x.findGreen(ctx, repo, commit, false)

0 commit comments

Comments
 (0)