diff --git a/tools/release/base-release-task.ts b/tools/release/base-release-task.ts index 2ddf148b89c9..9153a0164c66 100644 --- a/tools/release/base-release-task.ts +++ b/tools/release/base-release-task.ts @@ -13,7 +13,7 @@ export class BaseReleaseTask { constructor(public git: GitClient) {} /** Checks if the user is on an allowed publish branch for the specified version. */ - protected switchToPublishBranch(newVersion: Version): string { + protected async assertValidPublishBranch(newVersion: Version): Promise { const allowedBranches = getAllowedPublishBranches(newVersion); const currentBranchName = this.git.getCurrentBranch(); @@ -24,30 +24,24 @@ export class BaseReleaseTask { return currentBranchName; } - // In case there are multiple allowed publish branches for this version, we just - // exit and let the user decide which branch they want to release from. - if (allowedBranches.length !== 1) { - console.warn(chalk.yellow(' ✘ You are not on an allowed publish branch.')); - console.warn(chalk.yellow(` Please switch to one of the following branches: ` + - `${allowedBranches.join(', ')}`)); - process.exit(0); - } - - // For this version there is only *one* allowed publish branch, so we could - // automatically switch to that branch in case the user isn't on it yet. - const defaultPublishBranch = allowedBranches[0]; + console.error(chalk.red(' ✘ You are not on an allowed publish branch.')); + console.info(chalk.yellow( + ` Allowed branches are: ${chalk.bold(allowedBranches.join(', '))}`)); + console.info(); - if (!this.git.checkoutBranch(defaultPublishBranch)) { - console.error(chalk.red( - ` ✘ Could not switch to the "${chalk.italic(defaultPublishBranch)}" branch.`)); - console.error(chalk.red( - ` Please ensure that the branch exists or manually switch to the branch.`)); - process.exit(1); + // Prompt the user if they wants to forcibly use the current branch. We support this + // because in some cases, releases do not use the common publish branches. e.g. a major + // release is delayed, and new features for the next minor version are collected. + if (await this.promptConfirm( + `Do you want to forcibly use the current branch? (${chalk.italic(currentBranchName)})`)) { + console.log(); + console.log(chalk.green(` ✓ Using the "${chalk.italic(currentBranchName)}" branch.`)); + return currentBranchName; } - console.log(chalk.green( - ` ✓ Switched to the "${chalk.italic(defaultPublishBranch)}" branch.`)); - return defaultPublishBranch; + console.warn(); + console.warn(chalk.yellow(' Please switch to one of the allowed publish branches.')); + process.exit(0); } /** Verifies that the local branch is up to date with the given publish branch. */ @@ -73,11 +67,12 @@ export class BaseReleaseTask { } /** Prompts the user with a confirmation question and a specified message. */ - protected async promptConfirm(message: string): Promise { + protected async promptConfirm(message: string, defaultValue = false): Promise { return (await prompt<{result: boolean}>({ type: 'confirm', name: 'result', message: message, + default: defaultValue, })).result; } } diff --git a/tools/release/publish-release.ts b/tools/release/publish-release.ts index 15c546ebcb1a..ac093d5d7a75 100644 --- a/tools/release/publish-release.ts +++ b/tools/release/publish-release.ts @@ -76,7 +76,7 @@ class PublishReleaseTask extends BaseReleaseTask { this.verifyNoUncommittedChanges(); // Branch that will be used to build the output for the release of the current version. - const publishBranch = this.switchToPublishBranch(newVersion); + const publishBranch = await this.assertValidPublishBranch(newVersion); this._verifyLastCommitFromStagingScript(); this.verifyLocalCommitsMatchUpstream(publishBranch); diff --git a/tools/release/stage-release.ts b/tools/release/stage-release.ts index 697a0fd03152..3ada109987a8 100644 --- a/tools/release/stage-release.ts +++ b/tools/release/stage-release.ts @@ -92,7 +92,7 @@ class StageReleaseTask extends BaseReleaseTask { this.verifyNoUncommittedChanges(); // Branch that will be used to stage the release for the new selected version. - const publishBranch = this.switchToPublishBranch(newVersion); + const publishBranch = await this.assertValidPublishBranch(newVersion); this.verifyLocalCommitsMatchUpstream(publishBranch); this._verifyAngularPeerDependencyVersion(newVersion);