Skip to content

build: allow force overriding of publish branch #18238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 18 additions & 23 deletions tools/release/base-release-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
const allowedBranches = getAllowedPublishBranches(newVersion);
const currentBranchName = this.git.getCurrentBranch();

Expand All @@ -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. */
Expand All @@ -73,11 +67,12 @@ export class BaseReleaseTask {
}

/** Prompts the user with a confirmation question and a specified message. */
protected async promptConfirm(message: string): Promise<boolean> {
protected async promptConfirm(message: string, defaultValue = false): Promise<boolean> {
return (await prompt<{result: boolean}>({
type: 'confirm',
name: 'result',
message: message,
default: defaultValue,
})).result;
}
}
2 changes: 1 addition & 1 deletion tools/release/publish-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tools/release/stage-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down