Skip to content

Commit 33db574

Browse files
authored
feat(release-cli): Support custom (classic) releases (elastic#8629)
1 parent f9c7f4e commit 33db574

4 files changed

Lines changed: 37 additions & 16 deletions

File tree

packages/release-cli/src/cli.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const cli = () => {
3939
})
4040
.option('allowCustom', {
4141
type: 'boolean',
42+
description: '[UNSAFE!] Allow custom releases from unpushed changes. This should only be used with snapshot or custom releases',
4243
default: false,
4344
})
4445
.option('verbose', {
@@ -53,6 +54,11 @@ export const cli = () => {
5354
'Skip user prompts and proceed with recommended settings. Use in CI only!',
5455
default: false,
5556
})
57+
.option('skipUpdateVersions', {
58+
type: 'boolean',
59+
description: '[UNSAFE!] Skip the update version step. This should only be used for special releases like backports. The --workspaces argument is required when this argument is set.',
60+
default: false,
61+
})
5662
.option('useAuthToken', {
5763
type: 'boolean',
5864
description:
@@ -68,6 +74,7 @@ export const cli = () => {
6874
allowCustom,
6975
verbose,
7076
skipPrompts,
77+
skipUpdateVersions,
7178
useAuthToken,
7279
} = argv;
7380
const logger = new Logger(verbose);
@@ -79,6 +86,7 @@ export const cli = () => {
7986
workspaces,
8087
logger,
8188
skipPrompts,
89+
skipUpdateVersions,
8290
useAuthToken,
8391
allowCustomReleases: allowCustom,
8492
});

packages/release-cli/src/release.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface ReleaseOptions {
2929
logger: Logger;
3030
allowCustomReleases: boolean;
3131
skipPrompts: boolean;
32+
skipUpdateVersions: boolean;
3233
useAuthToken: boolean;
3334
}
3435

@@ -45,8 +46,10 @@ export const release = async (options: ReleaseOptions) => {
4546
}
4647

4748
if (options.tag !== 'latest') {
48-
throw new ValidationError(
49-
'Custom tags are not allowed for type `official`! Please use another type to perform custom releases'
49+
logger.warning(
50+
`A custom tag "${options.tag}" was provided for the official` +
51+
` release type. This should be used only for special releases like` +
52+
` backports. Stop here if you don't know what you're doing!`
5053
);
5154
}
5255
} else if (type === 'snapshot') {
@@ -68,6 +71,14 @@ export const release = async (options: ReleaseOptions) => {
6871
throw new ValidationError('Skipping prompts is not allowed when not using auth tokens');
6972
}
7073

74+
if (options.skipUpdateVersions) {
75+
logger.warning('--skip-update-versions is set');
76+
77+
if (!options.workspaces?.length) {
78+
throw new ValidationError('--workspaces must be set when --skip-update-version is used');
79+
}
80+
}
81+
7182
const allWorkspaces = await getYarnWorkspaces();
7283
let currentWorkspaces: Array<YarnWorkspace> = [];
7384

packages/release-cli/src/steps/init_checks.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,18 @@ export const stepInitChecks = async (options: ReleaseOptions) => {
3131

3232
// Check if releasing from main branch
3333
const currentBranch = await getCurrentBranch();
34-
if (currentBranch !== 'main' && type === 'official') {
34+
if (currentBranch !== 'main' && type === 'official' && !allowCustomReleases) {
3535
throw new ValidationError(
3636
'Official releases are only allowed from the `main` branch!'
3737
);
3838
}
3939

4040
if (!(await isWorkingTreeClean())) {
4141
throw new ValidationError(
42-
'Git working tree is dirty. Please clean up your working tree from any uncommited changes and try again.',
43-
`To clean local changes and restore the branch to remote state, please run:` +
44-
`\n ${chalk.yellowBright(
42+
'Git working tree is dirty. Please clean up your working tree' +
43+
' from any uncommited changes and try again.',
44+
`To clean local changes and restore the branch to remote state,` +
45+
` please run:\n ${chalk.yellowBright(
4546
`git reset --hard upstream/${currentBranch}`
4647
)}\n` +
4748
`Please note that ${chalk.underline.bold(
@@ -56,16 +57,11 @@ export const stepInitChecks = async (options: ReleaseOptions) => {
5657
logger.debug(`Local HEAD = ${localHash}`);
5758

5859
if (localHash !== remoteHash) {
59-
if (type === 'official') {
60-
throw new ValidationError(
61-
'Local `main` branch is out of sync with the upstream branch. Please pull the latest changes and try again.'
62-
);
63-
}
64-
6560
if (!allowCustomReleases) {
6661
throw new ValidationError(
67-
'Local HEAD does not match the remote HEAD. Use --allow-custom to create a custom non-official release ' +
68-
'if that really is what you were planning to do.'
62+
'Local HEAD does not match the remote HEAD. Use --allow-custom to' +
63+
' create a custom non-official release if that really is what' +
64+
'you were planning to do.'
6965
);
7066
} else {
7167
logger.warning('Local HEAD does not match the remote HEAD');
@@ -82,7 +78,8 @@ export const stepInitChecks = async (options: ReleaseOptions) => {
8278
const registryUser = await getAuthenticatedUser();
8379
if (!registryUser) {
8480
throw new ValidationError(
85-
'Authentication to npmjs is required. Please log in before running this command again.',
81+
'Authentication to npmjs is required. Please log in before running' +
82+
' this command again.',
8683
`To authenticate run the following command:\n` +
8784
` ${chalk.yellowBright('yarn npm login')}`
8885
);

packages/release-cli/src/steps/update_versions.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ export const stepUpdateVersions = async (
3535
options: ReleaseOptions,
3636
workspaces: Array<YarnWorkspace>
3737
) => {
38-
const { logger } = options;
38+
const { logger, skipUpdateVersions } = options;
39+
40+
if (skipUpdateVersions) {
41+
logger.warning('Skipping the update versions step');
42+
return workspaces;
43+
}
3944

4045
logger.info('Updating package versions and changelogs');
4146

0 commit comments

Comments
 (0)