Skip to content

Commit

Permalink
fix(git-node): prepare_release resilient checkout
Browse files Browse the repository at this point in the history
In `git node release --prepare` when checking out a new proposal branch
make sure it's also possible to update an already existing branch of
that same name instead of failing and terminating the automation.
  • Loading branch information
ruyadorno committed Jan 6, 2025
1 parent b1a15a9 commit 38ad9c8
Showing 1 changed file with 38 additions and 12 deletions.
50 changes: 38 additions & 12 deletions lib/prepare_release.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ export default class ReleasePreparation extends Session {
} = this;

// Create new proposal branch.
cli.startSpinner(`Creating new proposal branch for ${newVersion}`);
const proposalBranch = await this.createProposalBranch(releaseBranch);
cli.stopSpinner(`Created new proposal branch for ${newVersion}`);
cli.startSpinner(`Switching to proposal branch for ${newVersion}`);
const { proposalBranch, resultMsg } =
await this.createProposalBranch(releaseBranch);
cli.stopSpinner(resultMsg);

const success = await this.cherryPickSecurityPRs(filterLabels);
if (!success) {
Expand Down Expand Up @@ -201,9 +202,10 @@ export default class ReleasePreparation extends Session {
}

// Create new proposal branch.
cli.startSpinner(`Creating new proposal branch for ${newVersion}`);
await this.createProposalBranch();
cli.stopSpinner(`Created new proposal branch for ${newVersion}`);
cli.startSpinner(`Switching to proposal branch for ${newVersion}`);
const { resultMsg } =
await this.createProposalBranch();
cli.stopSpinner(resultMsg);

if (this.isLTSTransition) {
// For releases transitioning into LTS, fetch the new code name.
Expand Down Expand Up @@ -533,13 +535,37 @@ export default class ReleasePreparation extends Session {
const { newVersion } = this;
const proposalBranch = `v${newVersion}-proposal`;

await runAsync('git', [
'checkout',
'-b',
try {
await forceRunAsync('git', [
'checkout',
'-b',
proposalBranch,
base
], { captureStdout: true, captureStderr: true, ignoreFailure: false });
} catch (err) {
const branchExistsRE = /fatal: a branch named '.*' already exists/i;
if (branchExistsRE.test(err.stderr)) {
await runAsync('git', [
'checkout',
proposalBranch
]);
await runAsync('git', [
'reset',
'--hard',
base
]);
return {
proposalBranch,
resultMsg: `Updated proposal branch for ${newVersion}`
};
} else {
throw err;
}
}
return {
proposalBranch,
base
]);
return proposalBranch;
resultMsg: `Created new proposal branch for ${newVersion}`
};
}

async updateNodeVersion() {
Expand Down

0 comments on commit 38ad9c8

Please sign in to comment.