Update the version bump command to support accelerated releases (#40608)
* Update the version bump command to support accelerated releases * Appease Linter * Update Accel Release check to only allow for 4-digit numbers
This commit is contained in:
parent
c0f2e69191
commit
44a78870b3
|
@ -16,7 +16,7 @@ import { createPullRequest } from '../../../core/github/repo';
|
||||||
import { getEnvVar } from '../../../core/environment';
|
import { getEnvVar } from '../../../core/environment';
|
||||||
import { getMajorMinor } from '../../../core/version';
|
import { getMajorMinor } from '../../../core/version';
|
||||||
import { bumpFiles } from './bump';
|
import { bumpFiles } from './bump';
|
||||||
import { validateArgs } from './lib/validate';
|
import { validateArgs, getIsAccelRelease } from './lib/validate';
|
||||||
import { Options } from './types';
|
import { Options } from './types';
|
||||||
|
|
||||||
export const versionBumpCommand = new Command( 'version-bump' )
|
export const versionBumpCommand = new Command( 'version-bump' )
|
||||||
|
@ -47,6 +47,16 @@ export const versionBumpCommand = new Command( 'version-bump' )
|
||||||
'Commit directly to the base branch. Do not create a PR just push directly to base branch',
|
'Commit directly to the base branch. Do not create a PR just push directly to base branch',
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
|
.option(
|
||||||
|
'-f --force',
|
||||||
|
'Force a version bump, even when the new version is less than the existing version',
|
||||||
|
false
|
||||||
|
)
|
||||||
|
.option(
|
||||||
|
'-a --allow-accel',
|
||||||
|
'Allow accelerated versioning. When this option is not present, versions must be semantically correct',
|
||||||
|
false
|
||||||
|
)
|
||||||
.action( async ( version, options: Options ) => {
|
.action( async ( version, options: Options ) => {
|
||||||
const { owner, name, base, dryRun, commitDirectToBase } = options;
|
const { owner, name, base, dryRun, commitDirectToBase } = options;
|
||||||
|
|
||||||
|
@ -78,7 +88,10 @@ export const versionBumpCommand = new Command( 'version-bump' )
|
||||||
baseDir: tmpRepoPath,
|
baseDir: tmpRepoPath,
|
||||||
config: [ 'core.hooksPath=/dev/null' ],
|
config: [ 'core.hooksPath=/dev/null' ],
|
||||||
} );
|
} );
|
||||||
const majorMinor = getMajorMinor( version );
|
|
||||||
|
const majorMinor = getIsAccelRelease( version )
|
||||||
|
? version
|
||||||
|
: getMajorMinor( version );
|
||||||
const branch = `prep/${ base }-for-next-dev-cycle-${ majorMinor }`;
|
const branch = `prep/${ base }-for-next-dev-cycle-${ majorMinor }`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -10,6 +10,18 @@ import { readFile } from 'fs/promises';
|
||||||
*/
|
*/
|
||||||
import { Logger } from '../../../../core/logger';
|
import { Logger } from '../../../../core/logger';
|
||||||
import { Options } from '../types';
|
import { Options } from '../types';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether a version is an accel release.
|
||||||
|
*
|
||||||
|
* @param {string} version Version number
|
||||||
|
* @return {boolean} True if the version corresponds with an accel release, otherwise false
|
||||||
|
*/
|
||||||
|
export const getIsAccelRelease = ( version: string ): boolean => {
|
||||||
|
const isAccelRelease = version.match( /^(?:\d+\.){3}\d+?$/ );
|
||||||
|
return isAccelRelease !== null;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a plugin's current version.
|
* Get a plugin's current version.
|
||||||
*
|
*
|
||||||
|
@ -57,12 +69,21 @@ export const validateArgs = async (
|
||||||
version: string,
|
version: string,
|
||||||
options: Options
|
options: Options
|
||||||
): Promise< void > => {
|
): Promise< void > => {
|
||||||
const { base } = options;
|
const { allowAccel, base, force } = options;
|
||||||
const nextVersion = version;
|
const nextVersion = version;
|
||||||
|
const isAllowedAccelRelease =
|
||||||
|
allowAccel && getIsAccelRelease( nextVersion );
|
||||||
|
|
||||||
|
if ( isAllowedAccelRelease ) {
|
||||||
|
if ( base === 'trunk' ) {
|
||||||
|
Logger.error(
|
||||||
|
`Version ${ nextVersion } is not a development version bump and cannot be applied to trunk, which only accepts development version bumps.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if ( ! valid( nextVersion ) ) {
|
if ( ! valid( nextVersion ) ) {
|
||||||
Logger.error(
|
Logger.error(
|
||||||
'Invalid version supplied, please pass in a semantically correct version.'
|
'Invalid version supplied, please pass in a semantically correct version or use the correct option for accel releases.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +96,12 @@ export const validateArgs = async (
|
||||||
`Version ${ nextVersion } is not a development version bump and cannot be applied to trunk, which only accepts development version bumps.`
|
`Version ${ nextVersion } is not a development version bump and cannot be applied to trunk, which only accepts development version bumps.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( force ) {
|
||||||
|
// When the force option is set, we do not compare currentVersion.
|
||||||
|
return;
|
||||||
|
}
|
||||||
const currentVersion = await getCurrentVersion( tmpRepoPath );
|
const currentVersion = await getCurrentVersion( tmpRepoPath );
|
||||||
|
|
||||||
if ( ! currentVersion ) {
|
if ( ! currentVersion ) {
|
||||||
|
|
|
@ -4,4 +4,6 @@ export type Options = {
|
||||||
base?: string;
|
base?: string;
|
||||||
dryRun?: boolean;
|
dryRun?: boolean;
|
||||||
commitDirectToBase?: boolean;
|
commitDirectToBase?: boolean;
|
||||||
|
allowAccel?: boolean;
|
||||||
|
force?: boolean;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue