@@ -35,27 +35,30 @@ import (
35
35
36
36
// releaseTweet describes a tweet that announces a Go release.
37
37
type releaseTweet struct {
38
+ // Kind is the kind of release being announced.
39
+ Kind ReleaseKind
40
+
38
41
// Version is the Go version that has been released.
39
42
//
40
43
// 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
44
47
Version string
45
48
// SecondaryVersion is an older Go version that was also released.
46
49
// This only applies to minor releases when two releases are made.
47
- // For example, "go1.16.10 ".
50
+ // For example, "go1.20.9 ".
48
51
SecondaryVersion string
49
52
50
53
// Security is an optional sentence describing security fixes
51
54
// included in this release.
52
55
//
53
56
// The empty string means there are no security fixes to highlight.
54
57
// 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."
59
62
Security string
60
63
61
64
// Announcement is the announcement URL.
@@ -86,12 +89,13 @@ type TweetTasks struct {
86
89
87
90
// TweetRelease posts a tweet announcing that a Go release has been published.
88
91
// 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 ) {
90
93
if len (published ) < 1 || len (published ) > 2 {
91
94
return "" , fmt .Errorf ("got %d published Go releases, TweetRelease supports only 1 or 2 at once" , len (published ))
92
95
}
93
96
94
97
r := releaseTweet {
98
+ Kind : kind ,
95
99
Version : published [0 ].Version ,
96
100
Security : security ,
97
101
Announcement : announcement ,
@@ -153,33 +157,47 @@ func tweetText(r releaseTweet, rnd *rand.Rand) (string, error) {
153
157
name string
154
158
data interface {}
155
159
)
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
+ }
157
166
name , data = "beta" , struct {
158
167
Maj , Beta string
159
168
releaseTweet
160
169
}{
161
- Maj : r . Version [len ("go" ):i ],
162
- Beta : r . Version [ i + len ( " beta" ):] ,
170
+ Maj : maj [len ("go" ):],
171
+ Beta : beta ,
163
172
releaseTweet : r ,
164
173
}
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
+ }
166
179
name , data = "rc" , struct {
167
180
Maj , RC string
168
181
releaseTweet
169
182
}{
170
- Maj : r . Version [len ("go" ):i ],
171
- RC : r . Version [ i + len ( "rc" ):] ,
183
+ Maj : maj [len ("go" ):],
184
+ RC : rc ,
172
185
releaseTweet : r ,
173
186
}
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
+ }
175
191
name , data = "major" , struct {
176
- Maj string
192
+ Maj string
193
+ CapitalSpaceVersion string // "Go 1.5.0"
177
194
releaseTweet
178
195
}{
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 ,
181
199
}
182
- } else if strings . Count ( r . Version , "." ) == 2 { // Minor release like "go1.X.Y".
200
+ case KindCurrentMinor , KindPrevMinor :
183
201
name , data = "minor" , struct {
184
202
Curr , Prev string
185
203
releaseTweet
@@ -188,10 +206,9 @@ func tweetText(r releaseTweet, rnd *rand.Rand) (string, error) {
188
206
Prev : strings .TrimPrefix (r .SecondaryVersion , "go" ),
189
207
releaseTweet : r ,
190
208
}
191
- } else {
192
- return "" , fmt .Errorf ("unknown version format : %q " , r .Version )
209
+ default :
210
+ return "" , fmt .Errorf ("unknown release kind : %v " , r .Kind )
193
211
}
194
-
195
212
if r .SecondaryVersion != "" && name != "minor" {
196
213
return "" , fmt .Errorf ("tweet template %q doesn't support more than one release; the SecondaryVersion field can only be used in minor releases" , name )
197
214
}
@@ -244,11 +261,11 @@ const tweetTextTmpl = `{{define "minor" -}}
244
261
245
262
246
263
{{define "major" -}}
247
- {{emoji "release"}} Go {{.Maj }} is released!
264
+ {{emoji "release"}} {{.CapitalSpaceVersion }} is released!
248
265
249
266
{{with .Security}}{{emoji "security"}} Security: {{.}}{{"\n\n"}}{{end -}}
250
267
251
- {{emoji "notes"}} Release notes: https://go.dev/doc/{{.Version }}
268
+ {{emoji "notes"}} Release notes: https://go.dev/doc/go {{.Maj }}
252
269
253
270
{{emoji "download"}} Download: https://go.dev/dl/#{{.Version}}
254
271
0 commit comments