Skip to content

Commit

Permalink
internal/task: add a step to mail announcement for vscode prerelease
Browse files Browse the repository at this point in the history
The relui will accept two input parameters specifying the announcement
sender and the receiver.

As mentioned previously, the email announcement is not locally testable.

For golang/vscode-go#3500

Change-Id: I8b22bc8a4bf5f62b42b22bc34f081c914bc0d7fd
Reviewed-on: https://go-review.googlesource.com/c/build/+/613599
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
  • Loading branch information
h9jiang committed Sep 19, 2024
1 parent 8d2443a commit 8ec72b2
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 11 deletions.
2 changes: 2 additions & 0 deletions cmd/relui/deployment-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ spec:
- "[email protected]"
# TODO(hxjiang): replace builder alerts with tooling gopher google group.
- "[email protected]"
- "[email protected]"
- "[email protected]"
- "--twitter-api-secret=secret:symbolic-datum-552/twitter-api-secret"
- "--mastodon-api-secret=secret:symbolic-datum-552/mastodon-api-secret"
- "--builder-master-key=secret:symbolic-datum-552/builder-master-key"
Expand Down
11 changes: 8 additions & 3 deletions cmd/relui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ func main() {
var goplsAnnMail task.MailHeader
addressVarFlag(&goplsAnnMail.From, "gopls-announce-mail-from", "The From address to use for the gopls (pre-)announcement mail.")
addressVarFlag(&goplsAnnMail.To, "gopls-announce-mail-to", "The To address to use for the gopls (pre-)announcement mail.")
var vscodeGoAnnMail task.MailHeader
addressVarFlag(&vscodeGoAnnMail.From, "vscode-go-announce-mail-from", "The From address to use for the vscode-go (pre-)announcement mail.")
addressVarFlag(&vscodeGoAnnMail.To, "vscode-go-announce-mail-to", "The To address to use for the vscode-go (pre-)announcement mail.")
var twitterAPI secret.TwitterCredentials
secret.JSONVarFlag(&twitterAPI, "twitter-api-secret", "Twitter API secret to use for workflows involving tweeting.")
var mastodonAPI secret.MastodonCredentials
Expand Down Expand Up @@ -312,9 +315,11 @@ func main() {
V3: github.NewClient(githubHTTPClient),
V4: githubv4.NewClient(githubHTTPClient),
},
Gerrit: gerritClient,
CloudBuild: cloudBuildClient,
ApproveAction: relui.ApproveActionDep(dbPool),
Gerrit: gerritClient,
CloudBuild: cloudBuildClient,
ApproveAction: relui.ApproveActionDep(dbPool),
SendMail: mailFunc,
AnnounceMailHeader: vscodeGoAnnMail,
}
dh.RegisterDefinition("Create a vscode-go release candidate", releaseVSCodeGoTasks.NewPrereleaseDefinition())
dh.RegisterDefinition("Release a vscode-go insider version", releaseVSCodeGoTasks.NewInsiderDefinition())
Expand Down
4 changes: 3 additions & 1 deletion internal/task/announce.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ func announcementMail(data any) (MailContent, error) {
name = "gopls-announce.md"
case goplsPrereleaseAnnouncement:
name = "gopls-pre-announce.md"
case vscodeGoPrereleaseAnnouncement:
name = "vscode-go-pre-announce.md"
default:
return MailContent{}, fmt.Errorf("unknown template data type %T", data)
}
Expand Down Expand Up @@ -469,7 +471,7 @@ var announceTmpl = template.Must(template.New("").Funcs(template.FuncMap{
}
return "", fmt.Errorf("internal error: unhandled pre-release Go version %q", v)
},
}).ParseFS(tmplDir, "template/announce-*.md", "template/pre-announce-minor.md", "template/gopls-announce.md", "template/gopls-pre-announce.md"))
}).ParseFS(tmplDir, "template/announce-*.md", "template/pre-announce-minor.md", "template/gopls-announce.md", "template/gopls-pre-announce.md", "template/vscode-go-pre-announce.md"))

//go:embed template
var tmplDir embed.FS
Expand Down
10 changes: 10 additions & 0 deletions internal/task/announce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ This is CVE-2022-27536 and https://go.dev/issue/51759.`,
},
wantSubject: "Gopls v0.16.2 is released",
},
{
name: "vscode-go-pre-announce",
in: vscodeGoPrereleaseAnnouncement{
Version: "v0.44.2-rc.1",
Branch: "release-v0.44",
Commit: "abc123def456ghi789",
Issue: 12345,
},
wantSubject: "VSCode-Go v0.44.2-rc.1 is released",
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
Expand Down
45 changes: 38 additions & 7 deletions internal/task/releasevscodego.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ import (
// * insider workflow: creates a insider version. There are no pre-releases for
// insider versions.
type ReleaseVSCodeGoTasks struct {
Gerrit GerritClient
GitHub GitHubClientInterface
CloudBuild CloudBuildClient
ApproveAction func(*wf.TaskContext) error
Gerrit GerritClient
GitHub GitHubClientInterface
CloudBuild CloudBuildClient
ApproveAction func(*wf.TaskContext) error
SendMail func(MailHeader, MailContent) error
AnnounceMailHeader MailHeader
}

var nextVersionParam = wf.ParamDef[string]{
Expand Down Expand Up @@ -129,6 +131,10 @@ func vscodeGoActiveReleaseBranch(ctx *wf.TaskContext, gerrit GerritClient) (stri
return active, nil
}

func vscodeGoReleaseBranch(release releaseVersion) string {
return fmt.Sprintf("release-v%v.%v", release.Major, release.Minor)
}

// NewPrereleaseDefinition create a new workflow definition for vscode-go pre-release.
func (r *ReleaseVSCodeGoTasks) NewPrereleaseDefinition() *wf.Definition {
wd := wf.New(wf.ACL{Groups: []string{groups.ToolsTeam}})
Expand All @@ -142,13 +148,14 @@ func (r *ReleaseVSCodeGoTasks) NewPrereleaseDefinition() *wf.Definition {

verified := wf.Action1(wd, "verify the release candidate", r.verifyTestResults, revision, wf.After(approved))

_ = wf.Task1(wd, "create release milestone and issue", r.createReleaseMilestoneAndIssue, release, wf.After(verified))
issue := wf.Task1(wd, "create release milestone and issue", r.createReleaseMilestoneAndIssue, release, wf.After(verified))
branched := wf.Action2(wd, "create release branch", r.createReleaseBranch, release, prerelease, wf.After(verified))
build := wf.Task3(wd, "generate package extension (.vsix) for release candidate", r.generatePackageExtension, release, prerelease, revision, wf.After(verified))

tagged := wf.Action3(wd, "tag release candidate", r.tag, revision, release, prerelease, wf.After(branched))
_ = wf.Action3(wd, "create release note", r.createGitHubReleaseAsDraft, release, prerelease, build, wf.After(tagged))
released := wf.Action3(wd, "create release note", r.createGitHubReleaseAsDraft, release, prerelease, build, wf.After(tagged))

wf.Action4(wd, "mail announcement", r.mailPrereleaseAnnouncement, release, prerelease, revision, issue, wf.After(released))
return wd
}

Expand All @@ -157,7 +164,7 @@ func (r *ReleaseVSCodeGoTasks) NewPrereleaseDefinition() *wf.Definition {
// for a stable minor version (as no release branch exists yet).
// Returns the head of the corresponding release branch otherwise.
func (r *ReleaseVSCodeGoTasks) findRevision(ctx *wf.TaskContext, release releaseVersion, prerelease string) (string, error) {
branch := fmt.Sprintf("release-v%v.%v", release.Major, release.Minor)
branch := vscodeGoReleaseBranch(release)
if release.Patch == 0 && prerelease == "rc.1" {
branch = "master"
}
Expand Down Expand Up @@ -464,6 +471,30 @@ func (r *ReleaseVSCodeGoTasks) createGitHubReleaseAsDraft(ctx *wf.TaskContext, r
return nil
}

type vscodeGoPrereleaseAnnouncement struct {
Commit string
Issue int
Branch string
Version string
}

func (r *ReleaseVSCodeGoTasks) mailPrereleaseAnnouncement(ctx *wf.TaskContext, release releaseVersion, prerelease, revision string, issue int) error {
announce := vscodeGoPrereleaseAnnouncement{
Version: release.String() + "-" + prerelease,
Branch: vscodeGoReleaseBranch(release),
Commit: revision,
Issue: issue,
}
content, err := announcementMail(announce)
if err != nil {
return err
}
ctx.Printf("pre-announcement subject: %s\n\n", content.Subject)
ctx.Printf("pre-announcement body HTML:\n%s\n", content.BodyHTML)
ctx.Printf("pre-announcement body text:\n%s", content.BodyText)
return r.SendMail(r.AnnounceMailHeader, content)
}

func (r *ReleaseVSCodeGoTasks) tag(ctx *wf.TaskContext, commit string, release releaseVersion, prerelease string) error {
tag := fmt.Sprintf("%s-%s", release, prerelease)
if err := r.Gerrit.Tag(ctx, "vscode-go", tag, commit); err != nil {
Expand Down
12 changes: 12 additions & 0 deletions internal/task/template/vscode-go-pre-announce.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Subject: VSCode-Go {{.Version}} is released

Hello gophers,

We have just released vscode-go {{.Version}}, a release candidate for the upcoming vscode-go release. It is picked from release branch {{.Branch}} at commit {{.Commit | shortcommit}}.

Find installation and testing instructions for the release candidate at https://github.com/golang/vscode-go/releases/tag/{{.Version}}.

This vscode-go release is being tracked at https://go.dev/issue/{{.Issue}}.

Cheers,
The Go Tools Team
6 changes: 6 additions & 0 deletions internal/task/testdata/vscode-go-pre-announce.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<p>Hello gophers,</p>
<p>We have just released vscode-go v0.44.2-rc.1, a release candidate for the upcoming vscode-go release. It is picked from release branch release-v0.44 at commit abc123d.</p>
<p>Find installation and testing instructions for the release candidate at <a href="https://github.com/golang/vscode-go/releases/tag/v0.44.2-rc.1">https://github.com/golang/vscode-go/releases/tag/v0.44.2-rc.1</a>.</p>
<p>This vscode-go release is being tracked at <a href="https://go.dev/issue/12345">https://go.dev/issue/12345</a>.</p>
<p>Cheers,<br>
The Go Tools Team</p>
10 changes: 10 additions & 0 deletions internal/task/testdata/vscode-go-pre-announce.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Hello gophers,

We have just released vscode-go v0.44.2-rc.1, a release candidate for the upcoming vscode-go release. It is picked from release branch release-v0.44 at commit abc123d.

Find installation and testing instructions for the release candidate at https://github.com/golang/vscode-go/releases/tag/v0.44.2-rc.1.

This vscode-go release is being tracked at https://go.dev/issue/12345.

Cheers,
The Go Tools Team

0 comments on commit 8ec72b2

Please sign in to comment.