Skip to content
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

[rush] Add support for premajor and prepatch bump types #4994

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Add support for `premajor` and `prepatch` bump types in lockstep versions.",
"type": "none"
}
],
"packageName": "@microsoft/rush"
}
2 changes: 1 addition & 1 deletion common/config/rush/version-policies.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
// * When creating a release branch in Git, this field should be updated according to the
// * type of release.
// *
// * Valid values are: "prerelease", "preminor", "minor", "patch", "major"
// * Valid values are: "prerelease", "prepatch", "preminor", "premajor", "minor", "patch", "major"
// */
// "nextBump": "prerelease",
//
Expand Down
4 changes: 4 additions & 0 deletions common/reviews/api/rush-lib.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,12 @@ export enum BumpType {
// (undocumented)
'patch' = 2,
// (undocumented)
'premajor' = 6,
// (undocumented)
'preminor' = 3,
// (undocumented)
'prepatch' = 7,
// (undocumented)
'prerelease' = 1
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* When creating a release branch in Git, this field should be updated according to the
* type of release.
*
* Valid values are: "prerelease", "preminor", "minor", "patch", "major"
* Valid values are: "prerelease", "prepatch", "preminor", "premajor", "minor", "patch", "major"
*/
"nextBump": "prerelease",

Expand Down
8 changes: 5 additions & 3 deletions libraries/rush-lib/src/api/VersionPolicy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import { cloneDeep } from '../utilities/objectUtilities';
* This is a copy of the semver ReleaseType enum, but with the `none` value added and
* the `premajor` and `prepatch` omitted.
* See {@link LockStepVersionPolicy._getReleaseType}.
*
* TODO: Consider supporting `premajor` and `prepatch` in the future.
*/
export enum BumpType {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do the numeric values of these need to be updated to reflect the order of increasing severity? These may be used to ensure that the most severe bump type wins if multiple are specified in a package's changefiles.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, we need to confirm that doing that as a breaking API change won't cause issues.

Maybe we make premajor be 4.5 and prepatch be 1.5? When preminor was added, was that also a breaking reordering of values? It that's the case, then reshuffling these and using integers is probably fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iclanton IMHO it makes sense for them to be ordered in more natural way, but as you mentioned it could be a breaking API change.

I'll wait for other maintainers to comment on this before making changes here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@octogonz - thoughts?

// No version bump
Expand All @@ -40,7 +38,11 @@ export enum BumpType {
// Minor version bump
'minor' = 4,
// Major version bump
'major' = 5
'major' = 5,
// Premajor version bump
'premajor' = 6,
// Prepatch version bump
'prepatch' = 7
}

/**
Expand Down
52 changes: 51 additions & 1 deletion libraries/rush-lib/src/api/test/VersionPolicy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@ import { VersionPolicy, LockStepVersionPolicy, IndividualVersionPolicy, BumpType
describe(VersionPolicy.name, () => {
describe(LockStepVersionPolicy.name, () => {
const filename: string = `${__dirname}/jsonFiles/rushWithLockVersion.json`;
const versionPolicyConfig: VersionPolicyConfiguration = new VersionPolicyConfiguration(filename);
let versionPolicyConfig: VersionPolicyConfiguration;
let versionPolicy1: VersionPolicy;
let versionPolicy2: VersionPolicy;
let versionPolicy3: VersionPolicy;
let versionPolicy4: VersionPolicy;
let versionPolicy5: VersionPolicy;

beforeEach(() => {
versionPolicyConfig = new VersionPolicyConfiguration(filename);
versionPolicy1 = versionPolicyConfig.getVersionPolicy('testPolicy1');
versionPolicy2 = versionPolicyConfig.getVersionPolicy('testPolicy2');
versionPolicy3 = versionPolicyConfig.getVersionPolicy('testPolicy3');
versionPolicy4 = versionPolicyConfig.getVersionPolicy('testPolicy4');
versionPolicy5 = versionPolicyConfig.getVersionPolicy('testPolicy5');
});

it('loads configuration.', () => {
Expand Down Expand Up @@ -90,6 +97,23 @@ describe(VersionPolicy.name, () => {
expect(lockStepVersionPolicy.nextBump).toEqual(undefined);
});

it('bumps version for premajor release', () => {
expect(versionPolicy1).toBeInstanceOf(LockStepVersionPolicy);
const lockStepVersionPolicy: LockStepVersionPolicy = versionPolicy1 as LockStepVersionPolicy;
lockStepVersionPolicy.bump(BumpType.premajor, 'pr');
expect(lockStepVersionPolicy.version).toEqual('2.0.0-pr.0');
expect(lockStepVersionPolicy.nextBump).toEqual(BumpType.patch);
});

it('patch gets rid of prerelease version made with premajor', () => {
expect(versionPolicy3).toBeInstanceOf(LockStepVersionPolicy);
const lockStepVersionPolicy: LockStepVersionPolicy = versionPolicy3 as LockStepVersionPolicy;
expect(lockStepVersionPolicy.nextBump).toEqual(undefined);
lockStepVersionPolicy.bump(BumpType.patch);
expect(lockStepVersionPolicy.version).toEqual('1.0.0');
expect(lockStepVersionPolicy.nextBump).toEqual(undefined);
});

it('bumps version for preminor release', () => {
expect(versionPolicy1).toBeInstanceOf(LockStepVersionPolicy);
const lockStepVersionPolicy: LockStepVersionPolicy = versionPolicy1 as LockStepVersionPolicy;
Expand All @@ -98,6 +122,32 @@ describe(VersionPolicy.name, () => {
expect(lockStepVersionPolicy.nextBump).toEqual(BumpType.patch);
});

it('patch gets rid of prerelease version made with preminor', () => {
expect(versionPolicy4).toBeInstanceOf(LockStepVersionPolicy);
const lockStepVersionPolicy: LockStepVersionPolicy = versionPolicy4 as LockStepVersionPolicy;
expect(lockStepVersionPolicy.nextBump).toEqual(undefined);
lockStepVersionPolicy.bump(BumpType.patch);
expect(lockStepVersionPolicy.version).toEqual('1.1.0');
expect(lockStepVersionPolicy.nextBump).toEqual(undefined);
});

it('bumps version for prepatch release', () => {
expect(versionPolicy1).toBeInstanceOf(LockStepVersionPolicy);
const lockStepVersionPolicy: LockStepVersionPolicy = versionPolicy1 as LockStepVersionPolicy;
lockStepVersionPolicy.bump(BumpType.prepatch, 'pr');
expect(lockStepVersionPolicy.version).toEqual('1.1.1-pr.0');
expect(lockStepVersionPolicy.nextBump).toEqual(BumpType.patch);
});

it('patch gets rid of prepatch version made with preminor', () => {
expect(versionPolicy5).toBeInstanceOf(LockStepVersionPolicy);
const lockStepVersionPolicy: LockStepVersionPolicy = versionPolicy5 as LockStepVersionPolicy;
expect(lockStepVersionPolicy.nextBump).toEqual(undefined);
lockStepVersionPolicy.bump(BumpType.patch);
expect(lockStepVersionPolicy.version).toEqual('1.1.1');
expect(lockStepVersionPolicy.nextBump).toEqual(undefined);
});

it('bumps version for minor release', () => {
expect(versionPolicy1).toBeInstanceOf(LockStepVersionPolicy);
const lockStepVersionPolicy: LockStepVersionPolicy = versionPolicy1 as LockStepVersionPolicy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ Object {
"shortName": undefined,
},
Object {
"description": "Overrides the bump type in the version-policy.json for the specified version policy. Valid BUMPTYPE values include: prerelease, patch, preminor, minor, major. This setting only works for lock-step version policy in bump action.",
"description": "Overrides the bump type in the version-policy.json for the specified version policy. Valid BUMPTYPE values include: prerelease, prepatch, patch, preminor, minor, premajor and major. This setting only works for lock-step version policy in bump action.",
"environmentVariable": undefined,
"kind": "String",
"longName": "--override-bump",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,20 @@
"policyName": "testPolicy2",
"definitionName": "lockStepVersion",
"version": "1.2.0"
},
{
"policyName": "testPolicy3",
"definitionName": "lockStepVersion",
"version": "1.0.0-pr.0"
},
{
"policyName": "testPolicy4",
"definitionName": "lockStepVersion",
"version": "1.1.0-pr.0"
},
{
"policyName": "testPolicy5",
"definitionName": "lockStepVersion",
"version": "1.1.1-pr.0"
}
]
4 changes: 2 additions & 2 deletions libraries/rush-lib/src/cli/actions/VersionAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class VersionAction extends BaseRushAction {
argumentName: 'BUMPTYPE',
description:
'Overrides the bump type in the version-policy.json for the specified version policy. ' +
'Valid BUMPTYPE values include: prerelease, patch, preminor, minor, major. ' +
'Valid BUMPTYPE values include: prerelease, prepatch, patch, preminor, minor, premajor and major. ' +
'This setting only works for lock-step version policy in bump action.'
});
this._prereleaseIdentifier = this.defineStringParameter({
Expand Down Expand Up @@ -202,7 +202,7 @@ export class VersionAction extends BaseRushAction {
if (this._overwriteBump.value && !Enum.tryGetValueByKey(BumpType, this._overwriteBump.value)) {
throw new Error(
'The value of override-bump is not valid. ' +
'Valid values include prerelease, patch, preminor, minor, and major'
'Valid values include prerelease, prepatch, patch, preminor, minor, premajor and major'
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1410,9 +1410,9 @@ Optional arguments:
--override-bump BUMPTYPE
Overrides the bump type in the version-policy.json
for the specified version policy. Valid BUMPTYPE
values include: prerelease, patch, preminor, minor,
major. This setting only works for lock-step version
policy in bump action.
values include: prerelease, prepatch, patch, preminor,
minor, premajor and major. This setting only works
for lock-step version policy in bump action.
--override-prerelease-id ID
Overrides the prerelease identifier in the version
value of version-policy.json for the specified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
},
"nextBump": {
"description": "Type of next version bump",
"enum": ["none", "prerelease", "preminor", "minor", "patch", "major"]
"enum": ["none", "prerelease", "prepatch", "preminor", "premajor", "minor", "patch", "major"]
},
"mainProject": {
"description": "The main project for this version policy",
Expand Down
Loading