Skip to content

Commit 82527ad

Browse files
authored
feat(git-node): use a single git push command (#870)
1 parent 391487b commit 82527ad

File tree

1 file changed

+24
-43
lines changed

1 file changed

+24
-43
lines changed

lib/promote_release.js

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,9 @@ export default class ReleasePromotion extends Session {
134134

135135
// Set up for next release.
136136
cli.startSpinner('Setting up for next release');
137-
await this.setupForNextRelease();
137+
const workingOnNewReleaseCommit = await this.setupForNextRelease();
138138
cli.stopSpinner('Successfully set up for next release');
139139

140-
// Merge vX.Y.Z-proposal into vX.x.
141-
await this.mergeProposalBranch();
142-
143140
// Cherry pick release commit to master.
144141
const shouldCherryPick = await cli.prompt(
145142
'Cherry-pick release commit to the default branch?', { defaultAnswer: true });
@@ -186,8 +183,8 @@ export default class ReleasePromotion extends Session {
186183
}
187184
}
188185

189-
// Push to the remote default branch and release tag.
190-
await this.pushTagAndDefaultBranchToRemote();
186+
// Push to the remote the release tag, and default, release, and staging branch.
187+
await this.pushToRemote(workingOnNewReleaseCommit);
191188

192189
// Promote and sign the release builds.
193190
await this.promoteAndSignRelease();
@@ -385,56 +382,36 @@ export default class ReleasePromotion extends Session {
385382

386383
// Create 'Working On' commit.
387384
await forceRunAsync('git', ['add', filePath], { ignoreFailure: false });
388-
return forceRunAsync('git', [
385+
await forceRunAsync('git', [
389386
'commit',
390387
...this.gpgSign,
391388
'-m',
392389
`Working on ${workingOnVersion}`,
393390
'-m',
394391
`PR-URL: https://github.com/nodejs/node/pull/${prid}`
395392
], { ignoreFailure: false });
393+
const workingOnNewReleaseCommit = await forceRunAsync('git', ['rev-parse', 'HEAD'],
394+
{ ignoreFailure: false, captureStdout: true });
395+
return workingOnNewReleaseCommit.trim();
396396
}
397397

398-
async mergeProposalBranch() {
399-
const { cli, dryRun, stagingBranch, versionComponents } = this;
398+
async pushToRemote(workingOnNewReleaseCommit) {
399+
const { cli, dryRun, version, versionComponents, stagingBranch } = this;
400400
const releaseBranch = `v${versionComponents.major}.x`;
401-
402-
let prompt = 'Merge proposal branch into staging branch?';
403-
if (dryRun) {
404-
cli.info(dryRunMessage);
405-
cli.info('Run the following commands to merge the staging branch:');
406-
cli.info(`git push ${this.upstream} HEAD:refs/heads/${releaseBranch
407-
} HEAD:refs/heads/${stagingBranch}`);
408-
prompt = 'Ready to continue?';
409-
}
410-
411-
const shouldMergeProposalBranch = await cli.prompt(prompt, { defaultAnswer: true });
412-
if (!shouldMergeProposalBranch) {
413-
cli.warn('Aborting release promotion');
414-
throw new Error('Aborted');
415-
} else if (dryRun) {
416-
return;
417-
}
418-
419-
// TODO: find a solution for key passphrase from the terminal
420-
cli.startSpinner('Merging proposal branch');
421-
await forceRunAsync('git', ['push', this.upstream, `HEAD:refs/heads/${releaseBranch}`,
422-
`HEAD:refs/heads/${stagingBranch}`],
423-
{ ignoreFailure: false });
424-
cli.stopSpinner('Merged proposal branch');
425-
}
426-
427-
async pushTagAndDefaultBranchToRemote() {
428-
const { cli, dryRun, version } = this;
429401
const tagVersion = `v${version}`;
430402

431403
this.defaultBranch ??= await this.getDefaultBranch();
432404

433-
let prompt = `Push release tag and ${this.defaultBranch} to ${this.upstream}?`;
405+
let prompt = `Push release tag and commits to ${this.upstream}?`;
434406
if (dryRun) {
435407
cli.info(dryRunMessage);
436-
cli.info('Run the following commands to push to remote:');
437-
cli.info(`git push ${this.upstream} ${this.defaultBranch} ${tagVersion}`);
408+
cli.info('Run the following command to push to remote:');
409+
cli.info(`git push ${this.upstream} ${
410+
this.defaultBranch} ${
411+
tagVersion} ${
412+
workingOnNewReleaseCommit}:refs/heads/${releaseBranch} ${
413+
workingOnNewReleaseCommit}:refs/heads/${stagingBranch}`);
414+
cli.warn('Once pushed, you must not delete the local tag');
438415
prompt = 'Ready to continue?';
439416
}
440417

@@ -447,9 +424,13 @@ export default class ReleasePromotion extends Session {
447424
}
448425

449426
cli.startSpinner('Pushing to remote');
450-
await forceRunAsync('git', ['push', this.upstream, this.defaultBranch, tagVersion],
451-
{ ignoreFailure: false });
452-
cli.stopSpinner(`Pushed ${tagVersion} and ${this.defaultBranch} to remote`);
427+
await forceRunAsync('git', ['push', this.upstream, this.defaultBranch, tagVersion,
428+
`${workingOnNewReleaseCommit}:refs/heads/${releaseBranch}`,
429+
`${workingOnNewReleaseCommit}:refs/heads/${stagingBranch}`],
430+
{ ignoreFailure: false });
431+
cli.stopSpinner(`Pushed ${tagVersion}, ${this.defaultBranch}, ${
432+
releaseBranch}, and ${stagingBranch} to remote`);
433+
cli.warn('Now that it has been pushed, you must not delete the local tag');
453434
}
454435

455436
async promoteAndSignRelease() {

0 commit comments

Comments
 (0)