Skip to content

Commit

Permalink
fix: adjust base branch when prepare --security release (#889)
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelGSS authored Jan 15, 2025
1 parent 6eb25bd commit 8788be2
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions lib/prepare_release.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,14 @@ export default class ReleasePreparation extends Session {
try {
runSync('git', ['rev-parse', tagName]);
} catch {
this.cli.startSpinner(`Error parsing git ref ${tagName}, attempting fetching it as a tag`);
runSync('git', ['fetch', this.upstream, 'tag', '-n', tagName]);
this.cli.error(`Error parsing git ref ${tagName}`);
this.cli.startSpinner('Attempting fetching it as a tag\n');
try {
runSync('git', ['fetch', this.upstream, 'tag', '-n', tagName]);
} catch (e) {
this.cli.error(`${e.message}\nRun: git remote update`);
process.exit(1);
}
this.cli.stopSpinner(`Tag fetched: ${tagName}`);
}
try {
Expand Down Expand Up @@ -765,7 +771,7 @@ export default class ReleasePreparation extends Session {
}

async prepareLocalBranch() {
const { cli } = this;
const { cli, isSecurityRelease } = this;
if (this.newVersion) {
// If the CLI asked for a specific version:
const newVersion = semver.parse(this.newVersion);
Expand All @@ -789,11 +795,19 @@ export default class ReleasePreparation extends Session {
// Otherwise, we need to figure out what's the next version number for the
// release line of the branch that's currently checked out.
const currentBranch = this.getCurrentBranch();
const match = /^v(\d+)\.x-staging$/.exec(currentBranch);

// In security releases vN.x branch is the base
let regex = /^v(\d+)\.x-staging$/;
let targetBranch = 'vN.x-staging';
if (isSecurityRelease) {
regex = /^v(\d+)\.x$/;
targetBranch = 'vN.x';
}

const match = regex.exec(currentBranch);
if (!match) {
cli.warn(`Cannot prepare a release from ${currentBranch
}. Switch to a staging branch before proceeding.`);
}. Switch to a ${targetBranch} branch before proceeding.`);
return;
}
this.stagingBranch = currentBranch;
Expand Down

0 comments on commit 8788be2

Please sign in to comment.