Skip to content

Commit 7128fa9

Browse files
dmitshurgopherbot
authored andcommitted
internal/task: add ".0" to major release tweets
There's one more place to update for the upcoming go1.21.0 version name, the tweet announcing major releases. Increase the consistency between the templates and other similar code in the announcing, tweeting and mail-dl-cl tasks, to make them easier to maintain. The next CL will apply a few more simplifications. For golang/go#57631. Change-Id: I21957b05d14834f8d2d64a09a6f93bfb66ec228a Reviewed-on: https://go-review.googlesource.com/c/build/+/504521 Reviewed-by: Heschi Kreinick <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Dmitri Shuralyov <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]>
1 parent b17664c commit 7128fa9

File tree

6 files changed

+74
-50
lines changed

6 files changed

+74
-50
lines changed

internal/relui/workflows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ func addCommTasks(
362362
// Announce that a new Go release has been published.
363363
sentMail := wf.Task4(wd, "mail-announcement", comm.AnnounceRelease, wf.Const(kind), published, securityFixes, coordinators, wf.After(okayToAnnounceAndTweet))
364364
announcementURL := wf.Task1(wd, "await-announcement", comm.AwaitAnnounceMail, sentMail)
365-
tweetURL := wf.Task3(wd, "post-tweet", comm.TweetRelease, published, securitySummary, announcementURL, wf.After(okayToAnnounceAndTweet))
365+
tweetURL := wf.Task4(wd, "post-tweet", comm.TweetRelease, wf.Const(kind), published, securitySummary, announcementURL, wf.After(okayToAnnounceAndTweet))
366366

367367
wf.Output(wd, "Announcement URL", announcementURL)
368368
wf.Output(wd, "Tweet URL", tweetURL)

internal/task/announce.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ type releaseAnnouncement struct {
3939
// Version is the Go version that has been released.
4040
//
4141
// The version string must use the same format as Go tags. For example:
42-
// "go1.17.2" for a minor Go release
43-
// "go1.21.0" for a major Go release
44-
// • "go1.21beta1" or "go1.21rc1" for a pre-release
42+
// - "go1.21rc2" for a pre-release
43+
// - "go1.21.0" for a major Go release
44+
// - "go1.21.1" for a minor Go release
4545
Version string
4646
// SecondaryVersion is an older Go version that was also released.
4747
// This only applies to minor releases when two releases are made.
48-
// For example, "go1.16.10".
48+
// For example, "go1.20.9".
4949
SecondaryVersion string
5050

5151
// Security is a list of descriptions, one for each distinct
@@ -407,7 +407,7 @@ var announceTmpl = template.Must(template.New("").Funcs(template.FuncMap{
407407
// short and helpers below manipulate valid Go version strings
408408
// for the current needs of the announcement templates.
409409
"short": func(v string) string { return strings.TrimPrefix(v, "go") },
410-
// major extracts the major part of a valid Go version.
410+
// major extracts the major prefix of a valid Go version.
411411
// For example, major("go1.18.4") == "1.18".
412412
"major": func(v string) (string, error) {
413413
x, ok := version.Go1PointX(v)

internal/task/dlcl.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import (
2020
// MailDLCL mails a golang.org/dl CL that adds commands for the
2121
// specified Go version.
2222
//
23-
// The version must use the same format as Go tags. For example:
24-
// - "go1.17.2" and "go1.16.9" for a minor Go release
23+
// The version string must use the same format as Go tags. For example:
24+
// - "go1.21rc2" for a pre-release
2525
// - "go1.21.0" for a major Go release
26-
// - "go1.18beta1" or "go1.18rc1" for a pre-release
26+
// - "go1.21.1" for a minor Go release
2727
//
2828
// On success, the ID of the change is returned, like "dl~1234".
2929
func (t *VersionTasks) MailDLCL(ctx *workflow.TaskContext, major int, kind ReleaseKind, version string, reviewers []string, dryRun bool) (changeID string, _ error) {

internal/task/dlcl_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ func main() {
163163
if got, want := changeID, "(dry-run)"; got != want {
164164
t.Errorf("unexpected changeID: got = %q, want %q", got, want)
165165
}
166-
if diff := cmp.Diff(buf.String(), tc.wantLog); diff != "" {
167-
t.Errorf("unexpected log:\n%s", diff)
166+
if diff := cmp.Diff(tc.wantLog, buf.String()); diff != "" {
167+
t.Errorf("log mismatch (-want +got):\n%s", diff)
168168
}
169169
})
170170
}

internal/task/tweet.go

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,30 @@ import (
3535

3636
// releaseTweet describes a tweet that announces a Go release.
3737
type releaseTweet struct {
38+
// Kind is the kind of release being announced.
39+
Kind ReleaseKind
40+
3841
// Version is the Go version that has been released.
3942
//
4043
// The version string must use the same format as Go tags. For example:
41-
// "go1.17.2" for a minor Go release
42-
// "go1.18" for a major Go release
43-
// • "go1.18beta1" or "go1.18rc1" for a pre-release
44+
// - "go1.21rc2" for a pre-release
45+
// - "go1.21.0" for a major Go release
46+
// - "go1.21.1" for a minor Go release
4447
Version string
4548
// SecondaryVersion is an older Go version that was also released.
4649
// This only applies to minor releases when two releases are made.
47-
// For example, "go1.16.10".
50+
// For example, "go1.20.9".
4851
SecondaryVersion string
4952

5053
// Security is an optional sentence describing security fixes
5154
// included in this release.
5255
//
5356
// The empty string means there are no security fixes to highlight.
5457
// Past examples:
55-
// "Includes a security fix for the Wasm port (CVE-2021-38297)."
56-
// "Includes a security fix for archive/zip (CVE-2021-39293)."
57-
// "Includes a security fix for crypto/tls (CVE-2021-34558)."
58-
// "Includes security fixes for archive/zip, net, net/http/httputil, and math/big packages."
58+
// - "Includes a security fix for the Wasm port (CVE-2021-38297)."
59+
// - "Includes a security fix for archive/zip (CVE-2021-39293)."
60+
// - "Includes a security fix for crypto/tls (CVE-2021-34558)."
61+
// - "Includes security fixes for archive/zip, net, net/http/httputil, and math/big packages."
5962
Security string
6063

6164
// Announcement is the announcement URL.
@@ -86,12 +89,13 @@ type TweetTasks struct {
8689

8790
// TweetRelease posts a tweet announcing that a Go release has been published.
8891
// ErrTweetTooLong is returned if the inputs result in a tweet that's too long.
89-
func (t TweetTasks) TweetRelease(ctx *workflow.TaskContext, published []Published, security string, announcement string) (tweetURL string, _ error) {
92+
func (t TweetTasks) TweetRelease(ctx *workflow.TaskContext, kind ReleaseKind, published []Published, security string, announcement string) (tweetURL string, _ error) {
9093
if len(published) < 1 || len(published) > 2 {
9194
return "", fmt.Errorf("got %d published Go releases, TweetRelease supports only 1 or 2 at once", len(published))
9295
}
9396

9497
r := releaseTweet{
98+
Kind: kind,
9599
Version: published[0].Version,
96100
Security: security,
97101
Announcement: announcement,
@@ -153,33 +157,47 @@ func tweetText(r releaseTweet, rnd *rand.Rand) (string, error) {
153157
name string
154158
data interface{}
155159
)
156-
if i := strings.Index(r.Version, "beta"); i != -1 { // A beta release.
160+
switch r.Kind {
161+
case KindBeta:
162+
maj, beta, ok := strings.Cut(r.Version, "beta")
163+
if !ok {
164+
return "", fmt.Errorf("no 'beta' substring in beta version %q", r.Version)
165+
}
157166
name, data = "beta", struct {
158167
Maj, Beta string
159168
releaseTweet
160169
}{
161-
Maj: r.Version[len("go"):i],
162-
Beta: r.Version[i+len("beta"):],
170+
Maj: maj[len("go"):],
171+
Beta: beta,
163172
releaseTweet: r,
164173
}
165-
} else if i := strings.Index(r.Version, "rc"); i != -1 { // Release Candidate.
174+
case KindRC:
175+
maj, rc, ok := strings.Cut(r.Version, "rc")
176+
if !ok {
177+
return "", fmt.Errorf("no 'rc' substring in RC version %q", r.Version)
178+
}
166179
name, data = "rc", struct {
167180
Maj, RC string
168181
releaseTweet
169182
}{
170-
Maj: r.Version[len("go"):i],
171-
RC: r.Version[i+len("rc"):],
183+
Maj: maj[len("go"):],
184+
RC: rc,
172185
releaseTweet: r,
173186
}
174-
} else if strings.Count(r.Version, ".") == 1 { // Major release like "go1.X".
187+
case KindMajor:
188+
if !strings.HasSuffix(r.Version, ".0") {
189+
return "", fmt.Errorf("no '.0' suffix in major version %q", r.Version)
190+
}
175191
name, data = "major", struct {
176-
Maj string
192+
Maj string
193+
CapitalSpaceVersion string // "Go 1.5.0"
177194
releaseTweet
178195
}{
179-
Maj: r.Version[len("go"):],
180-
releaseTweet: r,
196+
Maj: r.Version[len("go") : len(r.Version)-len(".0")],
197+
CapitalSpaceVersion: strings.Replace(r.Version, "go", "Go ", 1),
198+
releaseTweet: r,
181199
}
182-
} else if strings.Count(r.Version, ".") == 2 { // Minor release like "go1.X.Y".
200+
case KindCurrentMinor, KindPrevMinor:
183201
name, data = "minor", struct {
184202
Curr, Prev string
185203
releaseTweet
@@ -188,10 +206,9 @@ func tweetText(r releaseTweet, rnd *rand.Rand) (string, error) {
188206
Prev: strings.TrimPrefix(r.SecondaryVersion, "go"),
189207
releaseTweet: r,
190208
}
191-
} else {
192-
return "", fmt.Errorf("unknown version format: %q", r.Version)
209+
default:
210+
return "", fmt.Errorf("unknown release kind: %v", r.Kind)
193211
}
194-
195212
if r.SecondaryVersion != "" && name != "minor" {
196213
return "", fmt.Errorf("tweet template %q doesn't support more than one release; the SecondaryVersion field can only be used in minor releases", name)
197214
}
@@ -244,11 +261,11 @@ const tweetTextTmpl = `{{define "minor" -}}
244261
245262
246263
{{define "major" -}}
247-
{{emoji "release"}} Go {{.Maj}} is released!
264+
{{emoji "release"}} {{.CapitalSpaceVersion}} is released!
248265
249266
{{with .Security}}{{emoji "security"}} Security: {{.}}{{"\n\n"}}{{end -}}
250267
251-
{{emoji "notes"}} Release notes: https://go.dev/doc/{{.Version}}
268+
{{emoji "notes"}} Release notes: https://go.dev/doc/go{{.Maj}}
252269
253270
{{emoji "download"}} Download: https://go.dev/dl/#{{.Version}}
254271

internal/task/tweet_test.go

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ import (
1818
"path/filepath"
1919
"testing"
2020

21+
"github.com/google/go-cmp/cmp"
2122
"golang.org/x/build/internal/workflow"
2223
)
2324

2425
func TestTweetRelease(t *testing.T) {
2526
tests := [...]struct {
2627
name string
28+
kind ReleaseKind
2729
published []Published
2830
security string
2931
announcement string
@@ -32,6 +34,7 @@ func TestTweetRelease(t *testing.T) {
3234
}{
3335
{
3436
name: "minor",
37+
kind: KindCurrentMinor,
3538
published: []Published{
3639
{Version: "go1.17.1", Files: []WebsiteFile{{
3740
OS: "linux", Arch: "arm64",
@@ -65,6 +68,7 @@ go version go1.17.1 linux/arm64` + "\n",
6568
},
6669
{
6770
name: "minor-solo",
71+
kind: KindCurrentMinor,
6872
published: []Published{{Version: "go1.11.1", Files: []WebsiteFile{{
6973
OS: "darwin", Arch: "amd64",
7074
Filename: "go1.11.1.darwin-amd64.tar.gz", Size: 124181190, Kind: "archive"}},
@@ -92,6 +96,7 @@ go version go1.11.1 darwin/amd64` + "\n",
9296
},
9397
{
9498
name: "beta",
99+
kind: KindBeta,
95100
published: []Published{{Version: "go1.17beta1", Files: []WebsiteFile{{
96101
OS: "darwin", Arch: "amd64",
97102
Filename: "go1.17beta1.darwin-amd64.tar.gz", Size: 135610703, Kind: "archive"}},
@@ -121,6 +126,7 @@ go version go1.17beta1 darwin/amd64` + "\n",
121126
},
122127
{
123128
name: "rc",
129+
kind: KindRC,
124130
published: []Published{{Version: "go1.17rc2", Files: []WebsiteFile{{
125131
OS: "windows", Arch: "arm64",
126132
Filename: "go1.17rc2.windows-arm64.zip", Size: 116660997, Kind: "archive"}},
@@ -150,32 +156,33 @@ go version go1.17rc2 windows/arm64` + "\n",
150156
},
151157
{
152158
name: "major",
153-
published: []Published{{Version: "go1.17", Files: []WebsiteFile{{
159+
kind: KindMajor,
160+
published: []Published{{Version: "go1.21.0", Files: []WebsiteFile{{
154161
OS: "freebsd", Arch: "amd64",
155-
Filename: "go1.17.freebsd-amd64.tar.gz", Size: 133579378, Kind: "archive"}},
162+
Filename: "go1.21.0.freebsd-amd64.tar.gz", Size: 133579378, Kind: "archive"}},
156163
}},
157164
security: "Includes a super duper security fix (CVE-123).",
158165
randomSeed: 123,
159166
wantLog: `tweet text:
160-
🥳 Go 1.17 is released!
167+
🥳 Go 1.21.0 is released!
161168
162169
🔐 Security: Includes a super duper security fix (CVE-123).
163170
164-
📝 Release notes: https://go.dev/doc/go1.17
171+
📝 Release notes: https://go.dev/doc/go1.21
165172
166-
📦 Download: https://go.dev/dl/#go1.17
173+
📦 Download: https://go.dev/dl/#go1.21.0
167174
168175
#golang
169176
tweet image:
170-
$ go install golang.org/dl/go1.17@latest
171-
$ go1.17 download
177+
$ go install golang.org/dl/go1.21.0@latest
178+
$ go1.21.0 download
172179
Downloaded 0.0% ( 0 / 133579378 bytes) ...
173180
Downloaded 50.0% ( 66789689 / 133579378 bytes) ...
174181
Downloaded 100.0% (133579378 / 133579378 bytes)
175-
Unpacking go1.17.freebsd-amd64.tar.gz ...
176-
Success. You may now run 'go1.17'
177-
$ go1.17 version
178-
go version go1.17 freebsd/amd64` + "\n",
182+
Unpacking go1.21.0.freebsd-amd64.tar.gz ...
183+
Success. You may now run 'go1.21.0'
184+
$ go1.21.0 version
185+
go version go1.21.0 freebsd/amd64` + "\n",
179186
},
180187
}
181188
for _, tc := range tests {
@@ -184,15 +191,15 @@ go version go1.17 freebsd/amd64` + "\n",
184191
// doesn't actually try to tweet, but capture its log.
185192
var buf bytes.Buffer
186193
ctx := &workflow.TaskContext{Context: context.Background(), Logger: fmtWriter{&buf}}
187-
tweetURL, err := (TweetTasks{RandomSeed: tc.randomSeed}).TweetRelease(ctx, tc.published, tc.security, tc.announcement)
194+
tweetURL, err := (TweetTasks{RandomSeed: tc.randomSeed}).TweetRelease(ctx, tc.kind, tc.published, tc.security, tc.announcement)
188195
if err != nil {
189196
t.Fatal("got a non-nil error:", err)
190197
}
191198
if got, want := tweetURL, "(dry-run)"; got != want {
192199
t.Errorf("unexpected tweetURL: got = %q, want %q", got, want)
193200
}
194-
if got, want := buf.String(), tc.wantLog; got != want {
195-
t.Errorf("unexpected log:\n got: %q\nwant: %q", got, want)
201+
if diff := cmp.Diff(tc.wantLog, buf.String()); diff != "" {
202+
t.Errorf("log mismatch (-want +got):\n%s", diff)
196203
}
197204
})
198205
}

0 commit comments

Comments
 (0)