From b861fb41c249a02a36bf86f4a584a054606b938c Mon Sep 17 00:00:00 2001 From: Tomasz Jaworski Date: Thu, 7 Nov 2024 07:41:48 +0100 Subject: [PATCH 1/3] Add support for premajor and prepatch bump types --- common/config/rush/version-policies.json | 2 +- common/reviews/api/rush-lib.api.md | 4 ++ .../common/config/rush/version-policies.json | 2 +- libraries/rush-lib/src/api/VersionPolicy.ts | 8 +-- .../src/api/test/VersionPolicy.test.ts | 52 ++++++++++++++++++- .../RushCommandLine.test.ts.snap | 2 +- .../test/jsonFiles/rushWithLockVersion.json | 15 ++++++ .../rush-lib/src/cli/actions/VersionAction.ts | 4 +- .../CommandLineHelp.test.ts.snap | 6 +-- .../src/schemas/version-policies.schema.json | 2 +- 10 files changed, 84 insertions(+), 13 deletions(-) diff --git a/common/config/rush/version-policies.json b/common/config/rush/version-policies.json index c1ba1f77cef..003360565d7 100644 --- a/common/config/rush/version-policies.json +++ b/common/config/rush/version-policies.json @@ -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", // diff --git a/common/reviews/api/rush-lib.api.md b/common/reviews/api/rush-lib.api.md index 454ac3daa07..29b4cb5640c 100644 --- a/common/reviews/api/rush-lib.api.md +++ b/common/reviews/api/rush-lib.api.md @@ -87,8 +87,12 @@ export enum BumpType { // (undocumented) 'patch' = 2, // (undocumented) + 'premajor' = 6, + // (undocumented) 'preminor' = 3, // (undocumented) + 'prepatch' = 7, + // (undocumented) 'prerelease' = 1 } diff --git a/libraries/rush-lib/assets/rush-init/common/config/rush/version-policies.json b/libraries/rush-lib/assets/rush-init/common/config/rush/version-policies.json index fa53012f5b2..a8b1f388bf5 100644 --- a/libraries/rush-lib/assets/rush-init/common/config/rush/version-policies.json +++ b/libraries/rush-lib/assets/rush-init/common/config/rush/version-policies.json @@ -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", diff --git a/libraries/rush-lib/src/api/VersionPolicy.ts b/libraries/rush-lib/src/api/VersionPolicy.ts index 2b1986c7943..4b312ed14fb 100644 --- a/libraries/rush-lib/src/api/VersionPolicy.ts +++ b/libraries/rush-lib/src/api/VersionPolicy.ts @@ -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 { // No version bump @@ -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 } /** diff --git a/libraries/rush-lib/src/api/test/VersionPolicy.test.ts b/libraries/rush-lib/src/api/test/VersionPolicy.test.ts index 5371bcff7b1..52c50b12222 100644 --- a/libraries/rush-lib/src/api/test/VersionPolicy.test.ts +++ b/libraries/rush-lib/src/api/test/VersionPolicy.test.ts @@ -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.', () => { @@ -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; @@ -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; diff --git a/libraries/rush-lib/src/api/test/__snapshots__/RushCommandLine.test.ts.snap b/libraries/rush-lib/src/api/test/__snapshots__/RushCommandLine.test.ts.snap index f36ce6efc6f..0a94444cae9 100644 --- a/libraries/rush-lib/src/api/test/__snapshots__/RushCommandLine.test.ts.snap +++ b/libraries/rush-lib/src/api/test/__snapshots__/RushCommandLine.test.ts.snap @@ -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", diff --git a/libraries/rush-lib/src/api/test/jsonFiles/rushWithLockVersion.json b/libraries/rush-lib/src/api/test/jsonFiles/rushWithLockVersion.json index ca829e9ecf3..5ccd3769a4f 100644 --- a/libraries/rush-lib/src/api/test/jsonFiles/rushWithLockVersion.json +++ b/libraries/rush-lib/src/api/test/jsonFiles/rushWithLockVersion.json @@ -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" } ] diff --git a/libraries/rush-lib/src/cli/actions/VersionAction.ts b/libraries/rush-lib/src/cli/actions/VersionAction.ts index 54070750902..11a8b3d3af7 100644 --- a/libraries/rush-lib/src/cli/actions/VersionAction.ts +++ b/libraries/rush-lib/src/cli/actions/VersionAction.ts @@ -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({ @@ -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' ); } } diff --git a/libraries/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap b/libraries/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap index 007ff234fc5..8043ec3ffbf 100644 --- a/libraries/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap +++ b/libraries/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap @@ -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 diff --git a/libraries/rush-lib/src/schemas/version-policies.schema.json b/libraries/rush-lib/src/schemas/version-policies.schema.json index 35995c5cc30..06661031433 100644 --- a/libraries/rush-lib/src/schemas/version-policies.schema.json +++ b/libraries/rush-lib/src/schemas/version-policies.schema.json @@ -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", From f5b952a75ba7cb116c87cf8aa136207af6c0f248 Mon Sep 17 00:00:00 2001 From: Tomasz Jaworski Date: Thu, 7 Nov 2024 07:43:33 +0100 Subject: [PATCH 2/3] chore: rush change --- ...or-prepatch-version-bump-type_2024-11-07-06-42.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 common/changes/@microsoft/rush/support-premajor-prepatch-version-bump-type_2024-11-07-06-42.json diff --git a/common/changes/@microsoft/rush/support-premajor-prepatch-version-bump-type_2024-11-07-06-42.json b/common/changes/@microsoft/rush/support-premajor-prepatch-version-bump-type_2024-11-07-06-42.json new file mode 100644 index 00000000000..302355d00cc --- /dev/null +++ b/common/changes/@microsoft/rush/support-premajor-prepatch-version-bump-type_2024-11-07-06-42.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@microsoft/rush", + "comment": "Add support for premajor and prepatch bump types", + "type": "none" + } + ], + "packageName": "@microsoft/rush" +} \ No newline at end of file From 0a07d10a50d765f4621ca1752aa9fd9032124bb1 Mon Sep 17 00:00:00 2001 From: Tomasz Jaworski Date: Fri, 15 Nov 2024 00:30:33 +0100 Subject: [PATCH 3/3] Update common/changes/@microsoft/rush/support-premajor-prepatch-version-bump-type_2024-11-07-06-42.json Co-authored-by: Ian Clanton-Thuon --- ...rt-premajor-prepatch-version-bump-type_2024-11-07-06-42.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/changes/@microsoft/rush/support-premajor-prepatch-version-bump-type_2024-11-07-06-42.json b/common/changes/@microsoft/rush/support-premajor-prepatch-version-bump-type_2024-11-07-06-42.json index 302355d00cc..a498c958920 100644 --- a/common/changes/@microsoft/rush/support-premajor-prepatch-version-bump-type_2024-11-07-06-42.json +++ b/common/changes/@microsoft/rush/support-premajor-prepatch-version-bump-type_2024-11-07-06-42.json @@ -2,7 +2,7 @@ "changes": [ { "packageName": "@microsoft/rush", - "comment": "Add support for premajor and prepatch bump types", + "comment": "Add support for `premajor` and `prepatch` bump types in lockstep versions.", "type": "none" } ],