Skip to content

Commit 7566446

Browse files
heschigopherbot
authored andcommitted
internal/relui,internal/task: add .0 to major versions
Updates most of relui to put .0 at the end of major version numbers. Notably excluded is the GitHub milestone. For golang/go#57631 Change-Id: Ieca2afaf4a5af4e90321e0dd68ac750a0077753a Reviewed-on: https://go-review.googlesource.com/c/build/+/478577 Reviewed-by: Carlos Amedee <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Heschi Kreinick <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Run-TryBot: Heschi Kreinick <[email protected]>
1 parent 16fdd0f commit 7566446

File tree

11 files changed

+135
-152
lines changed

11 files changed

+135
-152
lines changed

internal/relui/buildrelease_test.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,24 @@ import (
3737
"golang.org/x/build/internal/workflow"
3838
)
3939

40+
func TestNonDistpack(t *testing.T) {
41+
t.Run("minor", func(t *testing.T) {
42+
testRelease(t, "go1.20", 20, "go1.20.1", task.KindCurrentMinor)
43+
})
44+
}
45+
4046
func TestRelease(t *testing.T) {
4147
t.Run("beta", func(t *testing.T) {
42-
testRelease(t, "go1.17", 18, "go1.18beta1", task.KindBeta)
48+
testRelease(t, "go1.20", 21, "go1.21beta1", task.KindBeta)
4349
})
4450
t.Run("rc", func(t *testing.T) {
45-
testRelease(t, "go1.17", 18, "go1.18rc1", task.KindRC)
51+
testRelease(t, "go1.20", 21, "go1.21rc1", task.KindRC)
4652
})
4753
t.Run("major", func(t *testing.T) {
48-
testRelease(t, "go1.17", 18, "go1.18", task.KindMajor)
54+
testRelease(t, "go1.20", 21, "go1.21.0", task.KindMajor)
4955
})
5056
}
5157

52-
func TestDistpack(t *testing.T) {
53-
testRelease(t, "go1.20", 21, "go1.21", task.KindMajor)
54-
}
55-
5658
func TestSecurity(t *testing.T) {
5759
t.Run("success", func(t *testing.T) {
5860
testSecurity(t, true)

internal/relui/workflows.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ func registerProdReleaseWorkflows(ctx context.Context, h *DefinitionHolder, buil
304304
securitySummary = wf.Param(wd, securitySummaryParameter)
305305
securityFixes = wf.Param(wd, securityFixesParameter)
306306
}
307-
addCommTasks(wd, build, comm, wf.Slice(versionPublished), securitySummary, securityFixes, coordinators)
307+
addCommTasks(wd, build, comm, r.kind, wf.Slice(versionPublished), securitySummary, securityFixes, coordinators)
308308

309309
h.RegisterDefinition(fmt.Sprintf("Go 1.%d %s", r.major, r.suffix), wd)
310310
}
@@ -348,19 +348,19 @@ func createMinorReleaseWorkflow(build *BuildReleaseTasks, milestone *task.Milest
348348

349349
securitySummary := wf.Param(wd, securitySummaryParameter)
350350
securityFixes := wf.Param(wd, securityFixesParameter)
351-
addCommTasks(wd, build, comm, wf.Slice(v1Published, v2Published), securitySummary, securityFixes, coordinators)
351+
addCommTasks(wd, build, comm, task.KindCurrentMinor, wf.Slice(v1Published, v2Published), securitySummary, securityFixes, coordinators)
352352

353353
return wd, nil
354354
}
355355

356356
func addCommTasks(
357357
wd *wf.Definition, build *BuildReleaseTasks, comm task.CommunicationTasks,
358-
versions wf.Value[[]string], securitySummary wf.Value[string], securityFixes, coordinators wf.Value[[]string],
358+
kind task.ReleaseKind, versions wf.Value[[]string], securitySummary wf.Value[string], securityFixes, coordinators wf.Value[[]string],
359359
) {
360360
okayToAnnounceAndTweet := wf.Action0(wd, "Wait to Announce", build.ApproveAction, wf.After(versions))
361361

362362
// Announce that a new Go release has been published.
363-
sentMail := wf.Task3(wd, "mail-announcement", comm.AnnounceRelease, versions, securityFixes, coordinators, wf.After(okayToAnnounceAndTweet))
363+
sentMail := wf.Task4(wd, "mail-announcement", comm.AnnounceRelease, wf.Const(kind), versions, securityFixes, coordinators, wf.After(okayToAnnounceAndTweet))
364364
announcementURL := wf.Task1(wd, "await-announcement", comm.AwaitAnnounceMail, sentMail)
365365
tweetURL := wf.Task3(wd, "post-tweet", comm.TweetRelease, versions, securitySummary, announcementURL, wf.After(okayToAnnounceAndTweet))
366366

@@ -404,7 +404,7 @@ func addSingleReleaseWorkflow(
404404
signedAndTestedArtifacts, modules := build.addBuildTasks(wd, major, nextVersion, timestamp, source)
405405
okayToTagAndPublish := wf.Action0(wd, "Wait for Release Coordinator Approval", build.ApproveAction, wf.After(signedAndTestedArtifacts))
406406

407-
dlcl := wf.Task3(wd, "Mail DL CL", version.MailDLCL, wf.Slice(nextVersion), coordinators, wf.Const(false), wf.After(okayToTagAndPublish))
407+
dlcl := wf.Task5(wd, "Mail DL CL", version.MailDLCL, wf.Const(major), kindVal, nextVersion, coordinators, wf.Const(false), wf.After(okayToTagAndPublish))
408408
dlclCommit := wf.Task2(wd, "Wait for DL CL submission", version.AwaitCL, dlcl, wf.Const(""))
409409
wf.Output(wd, "Download CL submitted", dlclCommit)
410410

internal/task/announce.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@ import (
3333
)
3434

3535
type releaseAnnouncement struct {
36+
// Kind is the kind of release being announced.
37+
Kind ReleaseKind
38+
3639
// Version is the Go version that has been released.
3740
//
3841
// The version string must use the same format as Go tags. For example:
3942
// • "go1.17.2" for a minor Go release
40-
// • "go1.18" for a major Go release
41-
// • "go1.18beta1" or "go1.18rc1" for a pre-release
43+
// • "go1.21.0" for a major Go release
44+
// • "go1.21beta1" or "go1.21rc1" for a pre-release
4245
Version string
4346
// SecondaryVersion is an older Go version that was also released.
4447
// This only applies to minor releases when two releases are made.
@@ -129,7 +132,7 @@ type SentMail struct {
129132
}
130133

131134
// AnnounceRelease sends an email announcing a Go release to Google Groups.
132-
func (t AnnounceMailTasks) AnnounceRelease(ctx *workflow.TaskContext, versions []string, security []string, users []string) (SentMail, error) {
135+
func (t AnnounceMailTasks) AnnounceRelease(ctx *workflow.TaskContext, kind ReleaseKind, versions []string, security []string, users []string) (SentMail, error) {
133136
if deadline, ok := ctx.Deadline(); ok && time.Until(deadline) < time.Minute {
134137
return SentMail{}, fmt.Errorf("insufficient time for announce release task; a minimum of a minute left on context is required")
135138
}
@@ -142,6 +145,7 @@ func (t AnnounceMailTasks) AnnounceRelease(ctx *workflow.TaskContext, versions [
142145
}
143146

144147
r := releaseAnnouncement{
148+
Kind: kind,
145149
Version: versions[0],
146150
Security: security,
147151
Names: names,
@@ -307,18 +311,18 @@ func announcementMail(data any) (MailContent, error) {
307311
var name string
308312
switch r := data.(type) {
309313
case releaseAnnouncement:
310-
if i := strings.Index(r.Version, "beta"); i != -1 { // A beta release.
314+
switch r.Kind {
315+
case KindBeta:
311316
name = "announce-beta.md"
312-
} else if i := strings.Index(r.Version, "rc"); i != -1 { // Release Candidate.
317+
case KindRC:
313318
name = "announce-rc.md"
314-
} else if strings.Count(r.Version, ".") == 1 { // Major release like "go1.X".
319+
case KindMajor:
315320
name = "announce-major.md"
316-
} else if strings.Count(r.Version, ".") == 2 { // Minor release like "go1.X.Y".
321+
case KindCurrentMinor, KindPrevMinor:
317322
name = "announce-minor.md"
318-
} else {
319-
return MailContent{}, fmt.Errorf("unknown version format: %q", r.Version)
323+
default:
324+
return MailContent{}, fmt.Errorf("unknown release kind: %v", r.Kind)
320325
}
321-
322326
if len(r.Security) > 0 && name != "announce-minor.md" {
323327
// The Security field isn't supported in templates other than minor,
324328
// so report an error instead of silently dropping it.

internal/task/announce_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
func TestAnnounceReleaseShortContext(t *testing.T) {
2424
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
2525
defer cancel()
26-
_, err := (AnnounceMailTasks{}).AnnounceRelease(&workflow.TaskContext{Context: ctx}, []string{"go1.18.1", "go1.17.8"}, nil, nil)
26+
_, err := (AnnounceMailTasks{}).AnnounceRelease(&workflow.TaskContext{Context: ctx}, KindCurrentMinor, []string{"go1.18.1", "go1.17.8"}, nil, nil)
2727
if err == nil {
2828
t.Errorf("want non-nil error")
2929
} else if !strings.HasPrefix(err.Error(), "insufficient time") {
@@ -40,6 +40,7 @@ func TestAnnouncementMail(t *testing.T) {
4040
{
4141
name: "announce-minor",
4242
in: releaseAnnouncement{
43+
Kind: KindCurrentMinor,
4344
Version: "go1.18.1",
4445
SecondaryVersion: "go1.17.9",
4546
Names: []string{"Alice", "Bob", "Charlie"},
@@ -49,6 +50,7 @@ func TestAnnouncementMail(t *testing.T) {
4950
{
5051
name: "announce-minor-with-security",
5152
in: releaseAnnouncement{
53+
Kind: KindCurrentMinor,
5254
Version: "go1.18.1",
5355
SecondaryVersion: "go1.17.9",
5456
Security: []string{
@@ -82,6 +84,7 @@ This is CVE-2022-27536 and https://go.dev/issue/51759.`,
8284
{
8385
name: "announce-minor-solo",
8486
in: releaseAnnouncement{
87+
Kind: KindCurrentMinor,
8588
Version: "go1.11.1",
8689
Security: []string{"abc: security fix 1", "xyz: security fix 2"},
8790
Names: []string{"Alice"},
@@ -91,23 +94,26 @@ This is CVE-2022-27536 and https://go.dev/issue/51759.`,
9194
{
9295
name: "announce-beta",
9396
in: releaseAnnouncement{
97+
Kind: KindBeta,
9498
Version: "go1.19beta5",
9599
},
96100
wantSubject: "Go 1.19 Beta 5 is released",
97101
},
98102
{
99103
name: "announce-rc",
100104
in: releaseAnnouncement{
105+
Kind: KindRC,
101106
Version: "go1.19rc6",
102107
},
103108
wantSubject: "Go 1.19 Release Candidate 6 is released",
104109
},
105110
{
106111
name: "announce-major",
107112
in: releaseAnnouncement{
108-
Version: "go1.19",
113+
Kind: KindMajor,
114+
Version: "go1.21.0",
109115
},
110-
wantSubject: "Go 1.19 is released",
116+
wantSubject: "Go 1.21.0 is released",
111117
},
112118

113119
{
@@ -187,6 +193,7 @@ func TestAnnounceRelease(t *testing.T) {
187193

188194
tests := [...]struct {
189195
name string
196+
kind ReleaseKind
190197
versions []string
191198
security []string
192199
coordinators []string
@@ -195,6 +202,7 @@ func TestAnnounceRelease(t *testing.T) {
195202
}{
196203
{
197204
name: "minor",
205+
kind: KindCurrentMinor,
198206
versions: []string{"go1.18.1", "go1.17.8"}, // Intentionally not 1.17.9 so the real email doesn't get in the way.
199207
coordinators: []string{"heschi", "dmitshur"},
200208
want: SentMail{Subject: "Go 1.18.1 and Go 1.17.8 are released"},
@@ -255,7 +263,7 @@ Heschi and Dmitri for the Go team` + "\n",
255263
}
256264
var buf bytes.Buffer
257265
ctx := &workflow.TaskContext{Context: context.Background(), Logger: fmtWriter{&buf}}
258-
sentMail, err := tasks.AnnounceRelease(ctx, tc.versions, tc.security, tc.coordinators)
266+
sentMail, err := tasks.AnnounceRelease(ctx, tc.kind, tc.versions, tc.security, tc.coordinators)
259267
if err != nil {
260268
t.Fatal("task function returned non-nil error:", err)
261269
}

internal/task/dlcl.go

Lines changed: 32 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"fmt"
1010
"go/format"
1111
"path"
12-
"regexp"
1312
"strings"
1413
"text/template"
1514
"time"
@@ -19,58 +18,46 @@ import (
1918
)
2019

2120
// MailDLCL mails a golang.org/dl CL that adds commands for the
22-
// specified Go versions. It accepts one or two versions only.
21+
// specified Go version.
2322
//
24-
// The versions must use the same format as Go tags. For example:
23+
// The version must use the same format as Go tags. For example:
2524
// - "go1.17.2" and "go1.16.9" for a minor Go release
26-
// - "go1.18" for a major Go release
25+
// - "go1.21.0" for a major Go release
2726
// - "go1.18beta1" or "go1.18rc1" for a pre-release
2827
//
2928
// On success, the ID of the change is returned, like "dl~1234".
30-
func (t *VersionTasks) MailDLCL(ctx *workflow.TaskContext, versions []string, reviewers []string, dryRun bool) (changeID string, _ error) {
31-
if err := oneOrTwoGoVersions(versions); err != nil {
32-
return "", err
33-
}
34-
29+
func (t *VersionTasks) MailDLCL(ctx *workflow.TaskContext, major int, kind ReleaseKind, version string, reviewers []string, dryRun bool) (changeID string, _ error) {
3530
var files = make(map[string]string) // Map key is relative path, and map value is file content.
3631

3732
// Generate main.go files for versions from the template.
38-
for _, ver := range versions {
39-
var buf bytes.Buffer
40-
versionNoPatch, err := versionNoPatch(ver)
41-
if err != nil {
42-
return "", err
43-
}
44-
if err := dlTmpl.Execute(&buf, struct {
45-
Year int
46-
Version string // "go1.5.3rc2"
47-
VersionNoPatch string // "go1.5"
48-
CapitalSpaceVersion string // "Go 1.5"
49-
DocHost string // "go.dev" or "tip.golang.org" for rc/beta
50-
}{
51-
Year: time.Now().UTC().Year(),
52-
Version: ver,
53-
VersionNoPatch: versionNoPatch,
54-
DocHost: docHost(ver),
55-
CapitalSpaceVersion: strings.Replace(ver, "go", "Go ", 1),
56-
}); err != nil {
57-
return "", fmt.Errorf("dlTmpl.Execute: %v", err)
58-
}
59-
gofmted, err := format.Source(buf.Bytes())
60-
if err != nil {
61-
return "", fmt.Errorf("could not gofmt: %v", err)
62-
}
63-
files[path.Join(ver, "main.go")] = string(gofmted)
64-
ctx.Printf("file %q (command %q):\n%s", path.Join(ver, "main.go"), "golang.org/dl/"+ver, gofmted)
33+
var buf bytes.Buffer
34+
if err := dlTmpl.Execute(&buf, struct {
35+
Year int
36+
Version string // "go1.5.3rc2"
37+
DocLink string // "https://go.dev/doc/go1.5"
38+
CapitalSpaceVersion string // "Go 1.5.0"
39+
}{
40+
Year: time.Now().UTC().Year(),
41+
Version: version,
42+
DocLink: docLink(major, kind, version),
43+
CapitalSpaceVersion: strings.Replace(version, "go", "Go ", 1),
44+
}); err != nil {
45+
return "", fmt.Errorf("dlTmpl.Execute: %v", err)
46+
}
47+
gofmted, err := format.Source(buf.Bytes())
48+
if err != nil {
49+
return "", fmt.Errorf("could not gofmt: %v", err)
6550
}
51+
files[path.Join(version, "main.go")] = string(gofmted)
52+
ctx.Printf("file %q (command %q):\n%s", path.Join(version, "main.go"), "golang.org/dl/"+version, gofmted)
6653

6754
// Create a Gerrit CL using the Gerrit API.
6855
if dryRun {
6956
return "(dry-run)", nil
7057
}
7158
changeInput := gerrit.ChangeInput{
7259
Project: "dl",
73-
Subject: "dl: add " + strings.Join(versions, " and "),
60+
Subject: "dl: add " + version,
7461
Branch: "master",
7562
}
7663
return t.Gerrit.CreateAutoSubmitChange(ctx, changeInput, reviewers, files)
@@ -94,23 +81,16 @@ func oneOrTwoGoVersions(versions []string) error {
9481
return nil
9582
}
9683

97-
func docHost(ver string) string {
98-
if strings.Contains(ver, "rc") || strings.Contains(ver, "beta") {
99-
return "tip.golang.org"
84+
func docLink(major int, kind ReleaseKind, ver string) string {
85+
if kind == KindCurrentMinor || kind == KindPrevMinor {
86+
return fmt.Sprintf("https://go.dev/doc/devel/release#%v", ver)
10087
}
101-
return "go.dev"
102-
}
10388

104-
func versionNoPatch(ver string) (string, error) {
105-
rx := regexp.MustCompile(`^(go\d+\.\d+)($|[\.]?\d*)($|rc|beta|\.)`)
106-
m := rx.FindStringSubmatch(ver)
107-
if m == nil {
108-
return "", fmt.Errorf("unrecognized version %q", ver)
109-
}
110-
if m[2] != "" {
111-
return "devel/release#" + m[1] + ".minor", nil
89+
host := "go.dev"
90+
if kind == KindBeta || kind == KindRC {
91+
host = "tip.golang.org"
11292
}
113-
return m[1], nil
93+
return fmt.Sprintf("https://%v/doc/go1.%d", host, major)
11494
}
11595

11696
var dlTmpl = template.Must(template.New("").Parse(`// Copyright {{.Year}} The Go Authors. All rights reserved.
@@ -127,7 +107,7 @@ var dlTmpl = template.Must(template.New("").Parse(`// Copyright {{.Year}} The Go
127107
// And then use the {{.Version}} command as if it were your normal go
128108
// command.
129109
//
130-
// See the release notes at https://{{.DocHost}}/doc/{{.VersionNoPatch}}.
110+
// See the release notes at {{.DocLink}}.
131111
//
132112
// File bugs at https://go.dev/issue/new.
133113
package main

0 commit comments

Comments
 (0)