Skip to content

Commit

Permalink
internal/task: add a step to create github release as draft
Browse files Browse the repository at this point in the history
This step will accept release, prerelease and cloud build as input
parameter.
The first two parameter is being use to determine the release version.
The CloudBuild will be used in the next CL to upload generated package
extension.

A local relui screenshot is at golang/vscode-go#3500 (comment)

For golang/vscode-go#3500

Change-Id: Ia9b7fdf2869ceae2baecfbb0179c9985e7a9e1ad
Reviewed-on: https://go-review.googlesource.com/c/build/+/613595
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
  • Loading branch information
h9jiang committed Sep 17, 2024
1 parent 30938eb commit 591f2af
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
4 changes: 4 additions & 0 deletions internal/task/fakes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,10 @@ func (f *FakeGitHub) FetchMilestoneIssues(_ context.Context, owner, repo string,
return issueLabels, nil
}

func (*FakeGitHub) CreateRelease(ctx context.Context, owner, repo string, release *github.RepositoryRelease) (*github.RepositoryRelease, error) {
return nil, nil
}

func (*FakeGitHub) EditIssue(_ context.Context, owner string, repo string, number int, issue *github.IssueRequest) (*github.Issue, *github.Response, error) {
return nil, nil, nil
}
Expand Down
8 changes: 8 additions & 0 deletions internal/task/milestones.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ type GitHubClientInterface interface {
// PostComment creates a comment on a GitHub issue or pull request
// identified by the given GitHub Node ID.
PostComment(_ context.Context, id githubv4.ID, body string) error

// See github.Client.Repositories.CreateRelease.
CreateRelease(ctx context.Context, owner, repo string, release *github.RepositoryRelease) (*github.RepositoryRelease, error)
}

type GitHubClient struct {
Expand All @@ -341,6 +344,11 @@ func (c *GitHubClient) FetchMilestone(ctx context.Context, owner, repo, name str
return *m.Number, nil
}

func (c *GitHubClient) CreateRelease(ctx context.Context, owner, repo string, release *github.RepositoryRelease) (*github.RepositoryRelease, error) {
release, _, err := c.V3.Repositories.CreateRelease(ctx, owner, repo, release)
return release, err
}

func findMilestone(ctx context.Context, client *githubv4.Client, owner, repo, name string) (int, bool, error) {
var query struct {
Repository struct {
Expand Down
44 changes: 42 additions & 2 deletions internal/task/releasevscodego.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ var nextVersionParam = wf.ParamDef[string]{
//go:embed template/vscode-go-release-issue.md
var vscodeGoReleaseIssueTmplStr string

//go:embed template/vscode-go-pre-release-note.md
var vscodeGoPreReleaseNoteTmplStr string

// vscodeGoActiveReleaseBranch returns the current active release branch in
// vscode-go project.
func vscodeGoActiveReleaseBranch(ctx *wf.TaskContext, gerrit GerritClient) (string, error) {
Expand Down Expand Up @@ -141,9 +144,10 @@ func (r *ReleaseVSCodeGoTasks) NewPrereleaseDefinition() *wf.Definition {

_ = 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))
_ = wf.Task3(wd, "generate package extension (.vsix) for release candidate", r.generatePackageExtension, release, prerelease, revision, wf.After(verified))
build := wf.Task3(wd, "generate package extension (.vsix) for release candidate", r.generatePackageExtension, release, prerelease, revision, wf.After(verified))

_ = wf.Action3(wd, "tag release candidate", r.tag, revision, release, prerelease, wf.After(branched))
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))

return wd
}
Expand Down Expand Up @@ -402,6 +406,42 @@ func (r *ReleaseVSCodeGoTasks) nextPrereleaseVersion(ctx *wf.TaskContext, releas
return fmt.Sprintf("rc.%v", pre+1), nil
}

func (r *ReleaseVSCodeGoTasks) createGitHubReleaseAsDraft(ctx *wf.TaskContext, release releaseVersion, prerelease string, build CloudBuild) error {
tags, err := r.Gerrit.ListTags(ctx, "vscode-go")
if err != nil {
return err
}

// The release notes will display the differences between the current release
// and the appropriate previous release.
// - For minor versions (vX.Y.0), the diff is shown against the latest patch
// of the previous minor version (vX.Y-1.Z).
// - For patch versions (vX.Y.Z), the diff is shown against the previous
// patch version (vX.Y.Z-1).
var previous releaseVersion
if release.Patch == 0 {
previous, _ = latestVersion(tags, isSameMajorMinor(release.Major, release.Minor-1), isReleaseVersion)
} else {
previous, _ = latestVersion(tags, isSameMajorMinor(release.Major, release.Minor), isReleaseVersion)
}

current := fmt.Sprintf("%s-%s", release, prerelease)

ctx.DisableRetries() // Beyond this point we want retries to be done manually, not automatically.
draft, err := r.GitHub.CreateRelease(ctx, "golang", "vscode-go", &github.RepositoryRelease{
TagName: github.String(current),
Name: github.String("Release " + current),
Body: github.String(fmt.Sprintf(vscodeGoPreReleaseNoteTmplStr, previous, current, release.String())),
Prerelease: github.Bool(true),
Draft: github.Bool(true),
})
if err != nil {
return err
}
ctx.Printf("Find the draft release note in %s", draft.GetHTMLURL())
return nil
}

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
7 changes: 7 additions & 0 deletions internal/task/template/vscode-go-pre-release-note.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
**Full Changelog**: https://github.com/golang/vscode-go/compare/%s...%s
**Milestone**: https://github.com/golang/vscode-go/issues?q=milestone%%3A%s

* How to test prerelease
* Download the .vsix file from this Releases page.
* Navigate to the Extensions view in VS Code (Ctrl+Shift+X). Click on the "..." in the top-right corner, select "Install from VSIX", and select the .vsix file you downloaded. Alternatively, you can run code --install-extension Go-latest.vsix or open the Command Palette and run the "Extensions: Install from VSIX..." command.
* If prompted, reload VS Code.

0 comments on commit 591f2af

Please sign in to comment.