Skip to content

Commit ca545ba

Browse files
committed
internal/task: update the package.json version after branch cut
There are two places we need to update the "package.json": - Insider Release (from master branch) update the "package.json" in the master branch to reference the next stable version with a "-dex" suffix. - Stable Prerelease (from release branch) update the "package.json" in the release branch to reference the corresponding release version withou any suffix. "npx vsce package" generate "package.json" with offending new line. Trim the "package.json" before creating the CL. A local relui screenshot is at golang/vscode-go#3500 (comment) For golang/vscode-go#3500 Change-Id: I59476917f960e0dbc0903ee2cf128ba6fb8b96a1 Reviewed-on: https://go-review.googlesource.com/c/build/+/617157 Reviewed-by: Hyang-Ah Hana Kim <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 9fd11d6 commit ca545ba

File tree

2 files changed

+177
-57
lines changed

2 files changed

+177
-57
lines changed

internal/task/releasevscodego.go

Lines changed: 55 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -146,35 +146,27 @@ func (r *ReleaseVSCodeGoTasks) NewPrereleaseDefinition() *wf.Definition {
146146

147147
release := wf.Task1(wd, "determine the release version", r.determineReleaseVersion, versionBumpStrategy)
148148
prerelease := wf.Task1(wd, "find the next pre-release version", r.nextPrereleaseVersion, release)
149-
revision := wf.Task2(wd, "find the revision for the pre-release version", r.findRevision, release, prerelease)
150149
approved := wf.Action2(wd, "await release coordinator's approval", r.approveStablePrerelease, release, prerelease)
151150

152-
verified := wf.Action1(wd, "verify the release candidate", r.verifyTestResults, revision, wf.After(approved))
151+
branch := wf.Task2(wd, "create release branch", r.createReleaseBranch, release, prerelease, wf.After(approved))
152+
153+
changeID := wf.Task2(wd, "update package.json in release branch", r.updatePackageJSONVersionInReleaseBranch, release, coordinators, wf.After(branch))
154+
submitted := wf.Task1(wd, "await config CL submission", clAwaiter{r.Gerrit}.awaitSubmission, changeID)
155+
156+
// Read the head of the release branch after the required CL submission.
157+
revision := wf.Task2(wd, "find the revision for the pre-release version", r.Gerrit.ReadBranchHead, wf.Const("vscode-go"), branch, wf.After(submitted))
158+
verified := wf.Action1(wd, "verify the release candidate", r.verifyTestResults, revision)
153159

154160
issue := wf.Task2(wd, "create release milestone and issue", r.createReleaseMilestoneAndIssue, release, coordinators, wf.After(verified))
155-
branched := wf.Action2(wd, "create release branch", r.createReleaseBranch, release, prerelease, wf.After(verified))
156161
build := wf.Task3(wd, "generate package extension (.vsix) for release candidate", r.generatePackageExtension, release, prerelease, revision, wf.After(verified))
157162

158-
tagged := wf.Action3(wd, "tag the release candidate", r.tag, revision, release, prerelease, wf.After(branched))
163+
tagged := wf.Action3(wd, "tag the release candidate", r.tag, revision, release, prerelease, wf.After(branch))
159164
released := wf.Action3(wd, "create release note", r.createGitHubReleaseDraft, release, prerelease, build, wf.After(tagged))
160165

161166
wf.Action4(wd, "mail announcement", r.mailAnnouncement, release, prerelease, revision, issue, wf.After(released))
162167
return wd
163168
}
164169

165-
// findRevision determines the appropriate revision for the current release.
166-
// Returns the head of the master branch if this is the first release candidate
167-
// for a stable minor version (as no release branch exists yet).
168-
// Returns the head of the corresponding release branch otherwise.
169-
func (r *ReleaseVSCodeGoTasks) findRevision(ctx *wf.TaskContext, release releaseVersion, prerelease string) (string, error) {
170-
branch := vscodeGoReleaseBranch(release)
171-
if release.Patch == 0 && prerelease == "rc.1" {
172-
branch = "master"
173-
}
174-
175-
return r.Gerrit.ReadBranchHead(ctx, "vscode-go", branch)
176-
}
177-
178170
func (r *ReleaseVSCodeGoTasks) verifyTestResults(ctx *wf.TaskContext, revision string) error {
179171
// We are running all tests in a docker as a user 'node' (uid: 1000)
180172
// Let the user own the directory.
@@ -269,48 +261,48 @@ func (r *ReleaseVSCodeGoTasks) createReleaseMilestoneAndIssue(ctx *wf.TaskContex
269261

270262
// createReleaseBranch creates corresponding release branch only for the initial
271263
// release candidate of a minor version.
272-
func (r *ReleaseVSCodeGoTasks) createReleaseBranch(ctx *wf.TaskContext, release releaseVersion, prerelease string) error {
264+
func (r *ReleaseVSCodeGoTasks) createReleaseBranch(ctx *wf.TaskContext, release releaseVersion, prerelease string) (string, error) {
273265
branch := fmt.Sprintf("release-v%v.%v", release.Major, release.Minor)
274266
releaseHead, err := r.Gerrit.ReadBranchHead(ctx, "vscode-go", branch)
275267

276268
if err == nil {
277269
ctx.Printf("Found the release branch %q with head pointing to %s\n", branch, releaseHead)
278-
return nil
270+
return branch, nil
279271
}
280272

281273
if !errors.Is(err, gerrit.ErrResourceNotExist) {
282-
return fmt.Errorf("failed to read the release branch: %w", err)
274+
return "", fmt.Errorf("failed to read the release branch: %w", err)
283275
}
284276

285277
// Require vscode release branch existence if this is a non-minor release.
286278
if release.Patch != 0 {
287-
return fmt.Errorf("release branch is required for patch releases: %w", err)
279+
return "", fmt.Errorf("release branch is required for patch releases: %w", err)
288280
}
289281

290282
rc, err := prereleaseNumber(prerelease)
291283
if err != nil {
292-
return err
284+
return "", err
293285
}
294286

295287
// Require vscode release branch existence if this is not the first rc in
296288
// a minor release.
297289
if rc != 1 {
298-
return fmt.Errorf("release branch is required for non-initial release candidates: %w", err)
290+
return "", fmt.Errorf("release branch is required for non-initial release candidates: %w", err)
299291
}
300292

301293
// Create the release branch using the revision from the head of master branch.
302294
head, err := r.Gerrit.ReadBranchHead(ctx, "vscode-go", "master")
303295
if err != nil {
304-
return err
296+
return "", err
305297
}
306298

307299
ctx.DisableRetries() // Beyond this point we want retries to be done manually, not automatically.
308300
_, err = r.Gerrit.CreateBranch(ctx, "vscode-go", branch, gerrit.BranchInput{Revision: head})
309301
if err != nil {
310-
return err
302+
return "", err
311303
}
312304
ctx.Printf("Created branch %q at revision %s.\n", branch, head)
313-
return nil
305+
return branch, nil
314306
}
315307

316308
// generatePackageExtension builds the vscode-go package extension from source.
@@ -776,7 +768,7 @@ func (r *ReleaseVSCodeGoTasks) NewInsiderDefinition() *wf.Definition {
776768

777769
reviewers := wf.Param(wd, reviewersParam)
778770

779-
changeID := wf.Task1(wd, "update package.json in master branch", r.updatePackageJSONVersion, reviewers)
771+
changeID := wf.Task1(wd, "update package.json in master branch", r.updatePackageJSONVersionInMasterBranch, reviewers)
780772
submitted := wf.Task1(wd, "await config CL submission", clAwaiter{r.Gerrit}.awaitSubmission, changeID)
781773

782774
release := wf.Task0(wd, "determine the insider version", r.determineInsiderVersion)
@@ -819,12 +811,20 @@ func (r *ReleaseVSCodeGoTasks) determineInsiderVersion(ctx *wf.TaskContext) (rel
819811
return insider, nil
820812
}
821813

822-
// updatePackageJSONVersion updates the "package.json" and "package-lock.json"
823-
// files in the master branch of the vscode-go repository.
814+
// updatePackageJSONVersionInReleaseBranch updates the "package.json" and
815+
// "package-lock.json" files in the release branch of the vscode-go repository.
816+
// The "package.json" and "package-lock.json" will reference the current release
817+
// version.
818+
func (r *ReleaseVSCodeGoTasks) updatePackageJSONVersionInReleaseBranch(ctx *wf.TaskContext, release releaseVersion, reviewers []string) (string, error) {
819+
return r.updatePackageJSONVersion(ctx, vscodeGoReleaseBranch(release), release.String()[1:], reviewers)
820+
}
821+
822+
// updatePackageJSONVersionInMasterBranch updates the "package.json" and
823+
// "package-lock.json" files in the master branch of the vscode-go repository.
824824
// The updated "package.json" and "package-lock.json" will reference the next
825825
// stable release version with special suffix "-dev" to indicate this is a
826826
// prerelease.
827-
func (r *ReleaseVSCodeGoTasks) updatePackageJSONVersion(ctx *wf.TaskContext, reviewers []string) (string, error) {
827+
func (r *ReleaseVSCodeGoTasks) updatePackageJSONVersionInMasterBranch(ctx *wf.TaskContext, reviewers []string) (string, error) {
828828
tags, err := r.Gerrit.ListTags(ctx, "vscode-go")
829829
if err != nil {
830830
return "", err
@@ -842,10 +842,19 @@ func (r *ReleaseVSCodeGoTasks) updatePackageJSONVersion(ctx *wf.TaskContext, rev
842842
// point to "0.46.0-dev".
843843
devVersion := versionString(releaseVersion{Major: latestStable.Major, Minor: latestStable.Minor + 2, Patch: 0}, "dev")[1:]
844844

845-
clTitle := "extension/package.json: update version to " + devVersion
846-
openCL, err := openCL(ctx, r.Gerrit, "vscode-go", "master", clTitle)
845+
return r.updatePackageJSONVersion(ctx, "master", devVersion, reviewers)
846+
}
847+
848+
// updatePackageJSONVersion updates the "package.json" and "package-lock.json"
849+
// files in the given branch of the vscode-go repository with the desired version.
850+
func (r *ReleaseVSCodeGoTasks) updatePackageJSONVersion(ctx *wf.TaskContext, branch string, version string, reviewers []string) (string, error) {
851+
clTitle := "extension/package.json: update version to " + version
852+
if branch != "master" {
853+
clTitle = "[" + branch + "]" + clTitle
854+
}
855+
openCL, err := openCL(ctx, r.Gerrit, "vscode-go", branch, clTitle)
847856
if err != nil {
848-
return "", fmt.Errorf("failed to find the open CL of title %q in branch %q: %w", clTitle, "master", err)
857+
return "", fmt.Errorf("failed to find the open CL of title %q in branch %q: %w", clTitle, branch, err)
849858
}
850859
if openCL != "" {
851860
ctx.Printf("not creating CL: found existing CL %s", openCL)
@@ -862,7 +871,7 @@ npm ci &> npm-output.log
862871
npx vsce package %s --no-git-tag-version &> npx-output.log
863872
cat npm-output.log
864873
cat npx-output.log
865-
`, devVersion)
874+
`, version)
866875

867876
saveScriptFmt := cloudBuildClientScriptPrefix
868877
for _, file := range []string{
@@ -881,6 +890,11 @@ cat npx-output.log
881890
Name: "gcr.io/cloud-builders/git",
882891
Args: []string{"clone", "https://go.googlesource.com/vscode-go", "vscode-go"},
883892
},
893+
{
894+
Name: "gcr.io/cloud-builders/git",
895+
Args: []string{"checkout", branch},
896+
Dir: "vscode-go",
897+
},
884898
{
885899
Name: "gcr.io/cloud-builders/npm",
886900
Script: script,
@@ -908,11 +922,13 @@ cat npx-output.log
908922
ctx.Printf("the output from npx package:\n%s\n", outputs["npx-output.log"])
909923

910924
changed := map[string]string{}
911-
if outputs["package.json"] != outputs["package.json.before"] {
912-
changed["extension/package.json"] = outputs["package.json"]
925+
// "npx vsce package" generate "package.json" with an offending trailing
926+
// new line. Remove this new line before creating the CL.
927+
if after := strings.TrimRight(outputs["package.json"], "\n"); after != outputs["package.json.before"] {
928+
changed["extension/package.json"] = after
913929
}
914-
if outputs["package-lock.json"] != outputs["package-lock.json.before"] {
915-
changed["extension/package-lock.json"] = outputs["package-lock.json"]
930+
if after := outputs["package-lock.json"]; after != outputs["package-lock.json.before"] {
931+
changed["extension/package-lock.json"] = after
916932
}
917933

918934
// Skip CL creation as nothing changed.
@@ -923,7 +939,7 @@ cat npx-output.log
923939

924940
changeID, err := r.Gerrit.CreateAutoSubmitChange(ctx, gerrit.ChangeInput{
925941
Project: "vscode-go",
926-
Branch: "master",
942+
Branch: branch,
927943
Subject: fmt.Sprintf("%s\n\nThis is an automated CL which updates the package.json and package-lock.json.\n", clTitle),
928944
}, reviewers, changed)
929945
if err != nil {

0 commit comments

Comments
 (0)