cmd/relui: fix up goimports regeneration task, add one-off workflow

CL 442157 added a task at the end of the major Go release workflow to
mail a CL to x/tools. There were 3 new fields added to VersionTasks,
but cmd/relui only set one of them, which caused the task not to work
during the Go 1.20 release (go.dev/issue/58227). Due to an unrelated
issue in cmd/relui (go.dev/issue/58228), we didn't get the opportunity
to fix up the task and restart it, so it was skipped.

Set the 2 missing fields in cmd/relui, and add a temporary workflow to
trigger (and test out) the new functionality after the Go 1.20 release.

Also apply a few minor refinements to CreateUpdateStdlibIndexCL. Remove
the unused branch parameter, and avoid GetCurrentMajor to determine the
current major version. GetCurrentMajor will change its report from N to
N+1 sometime during the major Go release, after the tags are published.
We already know the major version in the workflow.

Fixes golang/go#58227.
For golang/go#54377.

Change-Id: I6377cdf051e4ea8628a88ac3f7eaf70651b34f72
Reviewed-on: https://go-review.googlesource.com/c/build/+/464815
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
diff --git a/cmd/relui/main.go b/cmd/relui/main.go
index 3f03f00..b60ce25 100644
--- a/cmd/relui/main.go
+++ b/cmd/relui/main.go
@@ -193,9 +193,11 @@
 		ApproveAction: relui.ApproveActionDep(dbPool),
 	}
 	versionTasks := &task.VersionTasks{
-		Gerrit:         gerritClient,
-		GoProject:      "go",
-		CreateBuildlet: coordinator.CreateBuildlet,
+		Gerrit:           gerritClient,
+		GerritURL:        "https://go.googlesource.com",
+		GoProject:        "go",
+		CreateBuildlet:   coordinator.CreateBuildlet,
+		LatestGoBinaries: task.LatestGoBinaries,
 	}
 	if err := relui.RegisterReleaseWorkflows(ctx, dh, buildTasks, milestoneTasks, versionTasks, commTasks); err != nil {
 		log.Fatalf("RegisterReleaseWorkflows: %v", err)
diff --git a/internal/relui/workflows.go b/internal/relui/workflows.go
index f96b4d2..cd5f954 100644
--- a/internal/relui/workflows.go
+++ b/internal/relui/workflows.go
@@ -256,6 +256,18 @@
 		h.RegisterDefinition("pre-announce "+r.name, wd)
 	}
 
+	// Register a one-off "update stdlib index CL"-only workflow for Go 1.20.
+	// See go.dev/issue/58227 and go.dev/issue/58228 for context on why this is needed.
+	{
+		wd := wf.New()
+
+		coordinators := wf.Param(wd, releaseCoordinators)
+		updateStdlibIndexCL := wf.Task2(wd, "Mail update stdlib index CL for 1.20", version.CreateUpdateStdlibIndexCL, coordinators, wf.Const("go1.20"))
+		wf.Output(wd, "Stdlib regeneration CL", updateStdlibIndexCL)
+
+		h.RegisterDefinition("Mail CL to regenerate x/tools/internal/imports after 1.20 release", wd)
+	}
+
 	// Register dry-run release workflows.
 	registerBuildTestSignOnlyWorkflow(h, version, build, currentMajor+1, task.KindBeta)
 
@@ -395,7 +407,7 @@
 	pushed := wf.Action3(wd, "Push issues", milestone.PushIssues, milestones, nextVersion, kindVal, wf.After(tagged))
 	versionPublished = wf.Task2(wd, "Publish to website", build.publishArtifacts, nextVersion, signedAndTestedArtifacts, wf.After(uploaded, pushed))
 	if kind == task.KindMajor {
-		updateStdlibIndexCL := wf.Task3(wd, fmt.Sprintf("Mail update stdlib index CL for 1.%d", major), version.CreateUpdateStdlibIndexCL, wf.Const("master"), coordinators, versionPublished)
+		updateStdlibIndexCL := wf.Task2(wd, fmt.Sprintf("Mail update stdlib index CL for 1.%d", major), version.CreateUpdateStdlibIndexCL, coordinators, versionPublished)
 		wf.Output(wd, "Stdlib regeneration CL", updateStdlibIndexCL)
 	}
 	wf.Output(wd, "Released version", versionPublished)
diff --git a/internal/task/tagx.go b/internal/task/tagx.go
index 7f594b2..f32d9c9 100644
--- a/internal/task/tagx.go
+++ b/internal/task/tagx.go
@@ -441,6 +441,8 @@
 	return result, nil
 }
 
+// LatestGoBinaries returns a URL to the latest linux/amd64
+// Go distribution archive using the go.dev/dl/ JSON API.
 func LatestGoBinaries(ctx context.Context) (string, error) {
 	resp, err := ctxhttp.Get(ctx, http.DefaultClient, "https://go.dev/dl/?mode=json")
 	if err != nil {
diff --git a/internal/task/version.go b/internal/task/version.go
index c3b9a78..36e3542 100644
--- a/internal/task/version.go
+++ b/internal/task/version.go
@@ -143,7 +143,7 @@
 	return t.Gerrit.Tag(ctx, t.GoProject, version, commit)
 }
 
-func (t *VersionTasks) CreateUpdateStdlibIndexCL(ctx *workflow.TaskContext, branch string, reviewers []string, version string) (string, error) {
+func (t *VersionTasks) CreateUpdateStdlibIndexCL(ctx *workflow.TaskContext, reviewers []string, version string) (string, error) {
 	var files = make(map[string]string) // Map key is relative path, and map value is file content.
 
 	binaries, err := t.LatestGoBinaries(ctx)
@@ -186,13 +186,9 @@
 	}
 	files["internal/imports/zstdlib.go"] = tools["zstdlib.go"]
 
-	major, err := t.GetCurrentMajor(ctx)
-	if err != nil {
-		return "", err
-	}
 	changeInput := gerrit.ChangeInput{
 		Project: "tools",
-		Subject: fmt.Sprintf("internal/imports: update stdlib index for %v", major),
+		Subject: fmt.Sprintf("internal/imports: update stdlib index for %s\n\nFor golang/go#38706.", strings.Replace(version, "go", "Go ", 1)),
 		Branch:  "master",
 	}
 	return t.Gerrit.CreateAutoSubmitChange(ctx, changeInput, reviewers, files)