From 6541519b2bc8993323be080349e6c3a03d85a646 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sun, 22 Mar 2026 12:17:56 +0100 Subject: [PATCH] fix(git-node): remove duplicated code in `prepare_release.js` Security releases preparation follow the same steps as regular releases, having duplicated steps is only cumbersome AFAICT. --- lib/prepare_release.js | 124 ++++++++++------------------------------- 1 file changed, 28 insertions(+), 96 deletions(-) diff --git a/lib/prepare_release.js b/lib/prepare_release.js index 785d5ea0..c798c466 100644 --- a/lib/prepare_release.js +++ b/lib/prepare_release.js @@ -133,88 +133,12 @@ export default class ReleasePreparation extends Session { return true; } - async prepareSecurity() { - const { - cli, - newVersion, - versionComponents, - releaseBranch, - filterLabels - } = this; - - // Create new proposal branch. - cli.startSpinner(`Switching to proposal branch for ${newVersion}`); - const proposalBranch = await this.createProposalBranch(releaseBranch); - cli.stopSpinner(`Switched to proposal branch for ${newVersion}`); - - const success = await this.cherryPickSecurityPRs(filterLabels); - if (!success) { - cli.error('Aborting security release preparation. ' + - 'Remember to exclude the proposal branch.' + - 'git branch -D ' + proposalBranch); - return; - } - // Update version and release info in src/node_version.h. - cli.startSpinner(`Updating 'src/node_version.h' for ${newVersion}`); - await this.updateNodeVersion(); - cli.stopSpinner(`Updated 'src/node_version.h' for ${newVersion}`); - - // Update any REPLACEME tags in the docs. - cli.startSpinner('Updating REPLACEME items in docs'); - await this.updateREPLACEMEs(); - cli.stopSpinner('Updated REPLACEME items in docs'); - - // Fetch date to use in release commit & changelogs. - const todayDate = new Date().toISOString().split('T')[0]; - this.date = await cli.prompt('Enter release date in YYYY-MM-DD format:', - { questionType: 'input', defaultAnswer: todayDate }); - - cli.startSpinner('Updating CHANGELOG.md'); - await this.updateMainChangelog(); - cli.stopSpinner('Updated CHANGELOG.md'); - - cli.startSpinner(`Updating CHANGELOG_V${versionComponents.major}.md`); - await this.updateMajorChangelog(); - cli.stopSpinner(`Updated CHANGELOG_V${versionComponents.major}.md`); - - // Create release commit. - const shouldCreateReleaseCommit = await cli.prompt( - 'Create release commit?'); - if (!shouldCreateReleaseCommit) { - cli.warn(`Aborting \`git node release\` for version ${newVersion}`); - return; - } - - // Proceed with release only after the releaser has amended - // it to their liking. - const createDefaultCommit = await this.createReleaseCommit(); - if (!createDefaultCommit) { - const lastCommitSha = runSync('git', ['rev-parse', '--short', 'HEAD']); - cli.warn(`Please manually edit commit ${lastCommitSha} by running ` + - '`git commit --amend` before proceeding.'); - } - - cli.separator(); - cli.ok(`Release preparation for ${newVersion} complete.\n`); - cli.info( - 'To finish the release proposal, run: \n' + - ` $ git push -u ${this.upstream} v${newVersion}-proposal\n` + - 'Finally, proceed to Jenkins and begin the following CI jobs:\n' + - ' * https://ci.nodejs.org/job/node-test-pull-request/\n' + - ' * https://ci.nodejs.org/job/citgm-smoker/'); - cli.info( - 'If this release has deps/v8 changes, you\'ll also need to run:\n' + - ' * https://ci.nodejs.org/job/node-test-commit-v8-linux/' - ); - } - async prepare() { const { cli, newVersion, versionComponents, isSecurityRelease } = this; if (isSecurityRelease) { this.config.owner = 'nodejs-private'; this.config.repo = 'node-private'; - return this.prepareSecurity(); } const runBranchDiff = await cli.prompt( @@ -222,30 +146,38 @@ export default class ReleasePreparation extends Session { '(recommended except for Maintenance releases)?', { defaultAnswer: this.runBranchDiff }); if (runBranchDiff) { - // TODO: UPDATE re-use - // Check the branch diff to determine if the releaser - // wants to backport any more commits before proceeding. - cli.startSpinner('Fetching branch-diff'); - const raw = await this.getBranchDiff({ - onlyNotableChanges: false, - comparisonBranch: newVersion - }); - - const diff = raw.split('*'); - cli.stopSpinner('Got branch diff'); - - const outstandingCommits = diff.length - 1; - if (outstandingCommits !== 0) { - const proceed = await cli.prompt( + if (isSecurityRelease) { + const success = await this.cherryPickSecurityPRs(this.filterLabels); + if (!success) { + cli.error('Aborting security release preparation.'); + return; + } + } else { + // TODO: UPDATE re-use + // Check the branch diff to determine if the releaser + // wants to backport any more commits before proceeding. + cli.startSpinner('Fetching branch-diff'); + const raw = await this.getBranchDiff({ + onlyNotableChanges: false, + comparisonBranch: newVersion + }); + + const diff = raw.split('*'); + cli.stopSpinner('Got branch diff'); + + const outstandingCommits = diff.length - 1; + if (outstandingCommits !== 0) { + const proceed = await cli.prompt( `There are ${outstandingCommits} commits that may be ` + `backported to ${this.stagingBranch} - do you still want to proceed?`, { defaultAnswer: false }); - if (!proceed) { - const seeDiff = await cli.prompt( - 'Do you want to see the branch diff?'); - if (seeDiff) cli.log(raw); - return; + if (!proceed) { + const seeDiff = await cli.prompt( + 'Do you want to see the branch diff?'); + if (seeDiff) cli.log(raw); + return; + } } } }