Skip to content

Commit deea0ca

Browse files
devversionjelbourn
authored andcommitted
build: allow force overriding of expected publish branch (#18238)
(cherry picked from commit e51f80d)
1 parent cd3c8ef commit deea0ca

File tree

3 files changed

+20
-25
lines changed

3 files changed

+20
-25
lines changed

tools/release/base-release-task.ts

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class BaseReleaseTask {
1313
constructor(public git: GitClient) {}
1414

1515
/** Checks if the user is on an allowed publish branch for the specified version. */
16-
protected switchToPublishBranch(newVersion: Version): string {
16+
protected async assertValidPublishBranch(newVersion: Version): Promise<string> {
1717
const allowedBranches = getAllowedPublishBranches(newVersion);
1818
const currentBranchName = this.git.getCurrentBranch();
1919

@@ -24,30 +24,24 @@ export class BaseReleaseTask {
2424
return currentBranchName;
2525
}
2626

27-
// In case there are multiple allowed publish branches for this version, we just
28-
// exit and let the user decide which branch they want to release from.
29-
if (allowedBranches.length !== 1) {
30-
console.warn(chalk.yellow(' ✘ You are not on an allowed publish branch.'));
31-
console.warn(chalk.yellow(` Please switch to one of the following branches: ` +
32-
`${allowedBranches.join(', ')}`));
33-
process.exit(0);
34-
}
35-
36-
// For this version there is only *one* allowed publish branch, so we could
37-
// automatically switch to that branch in case the user isn't on it yet.
38-
const defaultPublishBranch = allowedBranches[0];
27+
console.error(chalk.red(' ✘ You are not on an allowed publish branch.'));
28+
console.info(chalk.yellow(
29+
` Allowed branches are: ${chalk.bold(allowedBranches.join(', '))}`));
30+
console.info();
3931

40-
if (!this.git.checkoutBranch(defaultPublishBranch)) {
41-
console.error(chalk.red(
42-
` ✘ Could not switch to the "${chalk.italic(defaultPublishBranch)}" branch.`));
43-
console.error(chalk.red(
44-
` Please ensure that the branch exists or manually switch to the branch.`));
45-
process.exit(1);
32+
// Prompt the user if they wants to forcibly use the current branch. We support this
33+
// because in some cases, releases do not use the common publish branches. e.g. a major
34+
// release is delayed, and new features for the next minor version are collected.
35+
if (await this.promptConfirm(
36+
`Do you want to forcibly use the current branch? (${chalk.italic(currentBranchName)})`)) {
37+
console.log();
38+
console.log(chalk.green(` ✓ Using the "${chalk.italic(currentBranchName)}" branch.`));
39+
return currentBranchName;
4640
}
4741

48-
console.log(chalk.green(
49-
` ✓ Switched to the "${chalk.italic(defaultPublishBranch)}" branch.`));
50-
return defaultPublishBranch;
42+
console.warn();
43+
console.warn(chalk.yellow(' Please switch to one of the allowed publish branches.'));
44+
process.exit(0);
5145
}
5246

5347
/** Verifies that the local branch is up to date with the given publish branch. */
@@ -73,11 +67,12 @@ export class BaseReleaseTask {
7367
}
7468

7569
/** Prompts the user with a confirmation question and a specified message. */
76-
protected async promptConfirm(message: string): Promise<boolean> {
70+
protected async promptConfirm(message: string, defaultValue = false): Promise<boolean> {
7771
return (await prompt<{result: boolean}>({
7872
type: 'confirm',
7973
name: 'result',
8074
message: message,
75+
default: defaultValue,
8176
})).result;
8277
}
8378
}

tools/release/publish-release.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class PublishReleaseTask extends BaseReleaseTask {
7676
this.verifyNoUncommittedChanges();
7777

7878
// Branch that will be used to build the output for the release of the current version.
79-
const publishBranch = this.switchToPublishBranch(newVersion);
79+
const publishBranch = await this.assertValidPublishBranch(newVersion);
8080

8181
this._verifyLastCommitFromStagingScript();
8282
this.verifyLocalCommitsMatchUpstream(publishBranch);

tools/release/stage-release.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class StageReleaseTask extends BaseReleaseTask {
9292
this.verifyNoUncommittedChanges();
9393

9494
// Branch that will be used to stage the release for the new selected version.
95-
const publishBranch = this.switchToPublishBranch(newVersion);
95+
const publishBranch = await this.assertValidPublishBranch(newVersion);
9696

9797
this.verifyLocalCommitsMatchUpstream(publishBranch);
9898
this._verifyAngularPeerDependencyVersion(newVersion);

0 commit comments

Comments
 (0)