From 2206e73e6a1083a1a0e67905af97c88676a36e6e Mon Sep 17 00:00:00 2001 From: ddixit14 Date: Tue, 8 Nov 2022 09:28:14 -0500 Subject: [PATCH 1/6] chore: Adding new versioning strategies --- src/factories/versioning-strategy-factory.ts | 4 +++ src/factory.ts | 2 ++ src/plugins/maven-workspace.ts | 2 ++ .../always-bump-major.ts | 31 +++++++++++++++++++ .../always-bump-minor.ts | 31 +++++++++++++++++++ 5 files changed, 70 insertions(+) create mode 100644 src/versioning-strategies/always-bump-major.ts create mode 100644 src/versioning-strategies/always-bump-minor.ts diff --git a/src/factories/versioning-strategy-factory.ts b/src/factories/versioning-strategy-factory.ts index eed9f6924..3a12b2b18 100644 --- a/src/factories/versioning-strategy-factory.ts +++ b/src/factories/versioning-strategy-factory.ts @@ -15,6 +15,8 @@ import {VersioningStrategy} from '../versioning-strategy'; import {DefaultVersioningStrategy} from '../versioning-strategies/default'; import {AlwaysBumpPatch} from '../versioning-strategies/always-bump-patch'; +import {AlwaysBumpMinor} from '../versioning-strategies/always-bump-minor'; +import {AlwaysBumpMajor} from '../versioning-strategies/always-bump-major'; import {ServicePackVersioningStrategy} from '../versioning-strategies/service-pack'; import {GitHub} from '../github'; import {ConfigurationError} from '../errors'; @@ -35,6 +37,8 @@ export type VersioningStrategyBuilder = ( const versioningTypes: Record = { default: options => new DefaultVersioningStrategy(options), 'always-bump-patch': options => new AlwaysBumpPatch(options), + 'always-bump-minor': options => new AlwaysBumpMinor(options), + 'always-bump-major': options => new AlwaysBumpMajor(options), 'service-pack': options => new ServicePackVersioningStrategy(options), }; diff --git a/src/factory.ts b/src/factory.ts index 58f30ad05..e3c70334f 100644 --- a/src/factory.ts +++ b/src/factory.ts @@ -34,6 +34,8 @@ import {Expo} from './strategies/expo'; import {GitHub} from './github'; import {ReleaserConfig} from './manifest'; import {AlwaysBumpPatch} from './versioning-strategies/always-bump-patch'; +import {AlwaysBumpMinor} from './versioning-strategies/always-bump-minor'; +import {AlwaysBumpMajor} from './versioning-strategies/always-bump-major'; import {ServicePackVersioningStrategy} from './versioning-strategies/service-pack'; import {DependencyManifest} from './versioning-strategies/dependency-manifest'; import {BaseStrategyOptions} from './strategies/base'; diff --git a/src/plugins/maven-workspace.ts b/src/plugins/maven-workspace.ts index 76486a7d0..8883c870f 100644 --- a/src/plugins/maven-workspace.ts +++ b/src/plugins/maven-workspace.ts @@ -36,6 +36,8 @@ import {logger as defaultLogger, Logger} from '../util/logger'; import {GitHub} from '../github'; import {JavaSnapshot} from '../versioning-strategies/java-snapshot'; import {AlwaysBumpPatch} from '../versioning-strategies/always-bump-patch'; +import {AlwaysBumpMinor} from '../versioning-strategies/always-bump-minor'; +import {AlwaysBumpMajor} from '../versioning-strategies/always-bump-major'; import {ConventionalCommit} from '../commit'; import {CompositeUpdater} from '../updaters/composite'; diff --git a/src/versioning-strategies/always-bump-major.ts b/src/versioning-strategies/always-bump-major.ts new file mode 100644 index 000000000..cd932442b --- /dev/null +++ b/src/versioning-strategies/always-bump-major.ts @@ -0,0 +1,31 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import {Version} from '../version'; +import {ConventionalCommit} from '../commit'; +import {DefaultVersioningStrategy} from './default'; +import {VersionUpdater, MajorVersionUpdate} from '../versioning-strategy'; + +/** + * This VersioningStrategy always bumps the patch version. This + * strategy is useful for backport branches. + */ +export class AlwaysBumpMajor extends DefaultVersioningStrategy { + determineReleaseType( + _version: Version, + _commits: ConventionalCommit[] + ): VersionUpdater { + return new MajorVersionUpdate(); + } +} diff --git a/src/versioning-strategies/always-bump-minor.ts b/src/versioning-strategies/always-bump-minor.ts new file mode 100644 index 000000000..7f1bf850b --- /dev/null +++ b/src/versioning-strategies/always-bump-minor.ts @@ -0,0 +1,31 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import {Version} from '../version'; +import {ConventionalCommit} from '../commit'; +import {DefaultVersioningStrategy} from './default'; +import {VersionUpdater, MinorVersionUpdate} from '../versioning-strategy'; + +/** + * This VersioningStrategy always bumps the patch version. This + * strategy is useful for backport branches. + */ +export class AlwaysBumpMinor extends DefaultVersioningStrategy { + determineReleaseType( + _version: Version, + _commits: ConventionalCommit[] + ): VersionUpdater { + return new MinorVersionUpdate(); + } +} From 7894a308929b87091c6a9ddba469f834bec63458 Mon Sep 17 00:00:00 2001 From: ddixit14 Date: Tue, 8 Nov 2022 09:32:55 -0500 Subject: [PATCH 2/6] chore: fixing documentation --- docs/customizing.md | 10 ++++++---- src/versioning-strategies/always-bump-major.ts | 3 +-- src/versioning-strategies/always-bump-minor.ts | 3 +-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/customizing.md b/docs/customizing.md index 522eab583..1f672c4d9 100644 --- a/docs/customizing.md +++ b/docs/customizing.md @@ -36,11 +36,13 @@ as a starting point. A versioning strategy's job is to determine how to increment a SemVer version given a list of parsed commits. -| Versioning Strategy | Description | -| ------------------- | ----------- | -| `default` | Breaking changes bump the major version, features bump the minor version, bugfixes bump the patch version | +| Versioning Strategy | Description | +|---------------------|-------------------------------------------------------------------------------------------------------------| +| `default` | Breaking changes bump the major version, features bump the minor version, bugfixes bump the patch version | | `always-bump-patch` | Always bump patch version. This is useful for backporting bugfixes to previous major/minor release branches | -| `service-pack` | Designed for Java backport fixes. Uses Maven's specification for service pack versions (e.g. 1.2.3-sp.1) | +| `always-bump-minor` | Always bump minor version | | +| `always-bump-major` | Always bump major version | +| `service-pack` | Designed for Java backport fixes. Uses Maven's specification for service pack versions (e.g. 1.2.3-sp.1) | ### Adding additional versioning strategy types diff --git a/src/versioning-strategies/always-bump-major.ts b/src/versioning-strategies/always-bump-major.ts index cd932442b..f0f9542f5 100644 --- a/src/versioning-strategies/always-bump-major.ts +++ b/src/versioning-strategies/always-bump-major.ts @@ -18,8 +18,7 @@ import {DefaultVersioningStrategy} from './default'; import {VersionUpdater, MajorVersionUpdate} from '../versioning-strategy'; /** - * This VersioningStrategy always bumps the patch version. This - * strategy is useful for backport branches. + * This VersioningStrategy always bumps the major version. */ export class AlwaysBumpMajor extends DefaultVersioningStrategy { determineReleaseType( diff --git a/src/versioning-strategies/always-bump-minor.ts b/src/versioning-strategies/always-bump-minor.ts index 7f1bf850b..d19a5773a 100644 --- a/src/versioning-strategies/always-bump-minor.ts +++ b/src/versioning-strategies/always-bump-minor.ts @@ -18,8 +18,7 @@ import {DefaultVersioningStrategy} from './default'; import {VersionUpdater, MinorVersionUpdate} from '../versioning-strategy'; /** - * This VersioningStrategy always bumps the patch version. This - * strategy is useful for backport branches. + * This VersioningStrategy always bumps the minor version. */ export class AlwaysBumpMinor extends DefaultVersioningStrategy { determineReleaseType( From efce4527cebf3fa5276ef0c16c290a165a461d74 Mon Sep 17 00:00:00 2001 From: ddixit14 Date: Tue, 8 Nov 2022 09:46:33 -0500 Subject: [PATCH 3/6] chore: trying to fix --- src/factory.ts | 2 -- src/plugins/maven-workspace.ts | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/factory.ts b/src/factory.ts index e3c70334f..58f30ad05 100644 --- a/src/factory.ts +++ b/src/factory.ts @@ -34,8 +34,6 @@ import {Expo} from './strategies/expo'; import {GitHub} from './github'; import {ReleaserConfig} from './manifest'; import {AlwaysBumpPatch} from './versioning-strategies/always-bump-patch'; -import {AlwaysBumpMinor} from './versioning-strategies/always-bump-minor'; -import {AlwaysBumpMajor} from './versioning-strategies/always-bump-major'; import {ServicePackVersioningStrategy} from './versioning-strategies/service-pack'; import {DependencyManifest} from './versioning-strategies/dependency-manifest'; import {BaseStrategyOptions} from './strategies/base'; diff --git a/src/plugins/maven-workspace.ts b/src/plugins/maven-workspace.ts index 8883c870f..76486a7d0 100644 --- a/src/plugins/maven-workspace.ts +++ b/src/plugins/maven-workspace.ts @@ -36,8 +36,6 @@ import {logger as defaultLogger, Logger} from '../util/logger'; import {GitHub} from '../github'; import {JavaSnapshot} from '../versioning-strategies/java-snapshot'; import {AlwaysBumpPatch} from '../versioning-strategies/always-bump-patch'; -import {AlwaysBumpMinor} from '../versioning-strategies/always-bump-minor'; -import {AlwaysBumpMajor} from '../versioning-strategies/always-bump-major'; import {ConventionalCommit} from '../commit'; import {CompositeUpdater} from '../updaters/composite'; From 374b41e18857feb8499ef75612963a2543abbd1e Mon Sep 17 00:00:00 2001 From: ddixit14 Date: Tue, 8 Nov 2022 09:47:54 -0500 Subject: [PATCH 4/6] fixing headers --- src/versioning-strategies/always-bump-major.ts | 2 +- src/versioning-strategies/always-bump-minor.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/versioning-strategies/always-bump-major.ts b/src/versioning-strategies/always-bump-major.ts index f0f9542f5..e0c04fae0 100644 --- a/src/versioning-strategies/always-bump-major.ts +++ b/src/versioning-strategies/always-bump-major.ts @@ -1,4 +1,4 @@ -// Copyright 2021 Google LLC +// Copyright 2022 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/src/versioning-strategies/always-bump-minor.ts b/src/versioning-strategies/always-bump-minor.ts index d19a5773a..1602b447f 100644 --- a/src/versioning-strategies/always-bump-minor.ts +++ b/src/versioning-strategies/always-bump-minor.ts @@ -1,4 +1,4 @@ -// Copyright 2021 Google LLC +// Copyright 2022 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. From 20d2c2d715605fbc3c2d081a882acb550f158254 Mon Sep 17 00:00:00 2001 From: ddixit14 Date: Wed, 9 Nov 2022 09:43:01 -0500 Subject: [PATCH 5/6] rewriting test snapshots --- __snapshots__/cli.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/__snapshots__/cli.js b/__snapshots__/cli.js index a4a0ff800..2ce0e42ff 100644 --- a/__snapshots__/cli.js +++ b/__snapshots__/cli.js @@ -185,7 +185,8 @@ Options: --snapshot is it a snapshot (or pre-release) being generated? [boolean] [default: false] --versioning-strategy strategy used for bumping versions - [choices: "always-bump-patch", "default", "service-pack"] [default: "default"] + [choices: "always-bump-major", "always-bump-minor", "always-bump-patch", + "default", "service-pack"] [default: "default"] --changelog-path where can the CHANGELOG be found in the project? [string] [default: "CHANGELOG.md"] --changelog-type type of changelog to build From 392a6d7726e82bb8473fe3385641a3677c1c955b Mon Sep 17 00:00:00 2001 From: deepankar Date: Fri, 11 Nov 2022 16:30:33 +0000 Subject: [PATCH 6/6] adding unit tests --- .../always-bump-major.ts | 142 ++++++++++++++++++ .../always-bump-minor.ts | 142 ++++++++++++++++++ 2 files changed, 284 insertions(+) create mode 100644 test/versioning-strategies/always-bump-major.ts create mode 100644 test/versioning-strategies/always-bump-minor.ts diff --git a/test/versioning-strategies/always-bump-major.ts b/test/versioning-strategies/always-bump-major.ts new file mode 100644 index 000000000..ef261986c --- /dev/null +++ b/test/versioning-strategies/always-bump-major.ts @@ -0,0 +1,142 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import {describe, it} from 'mocha'; + +import {expect} from 'chai'; +import {AlwaysBumpMajor} from '../../src/versioning-strategies/always-bump-major'; +import {Version} from '../../src/version'; + +describe('MajorVersioningStrategy', () => { + describe('with breaking change', () => { + const commits = [ + { + sha: 'sha1', + message: 'feat: some feature', + files: ['path1/file1.txt'], + type: 'feat', + scope: null, + bareMessage: 'some feature', + notes: [], + references: [], + breaking: false, + }, + { + sha: 'sha2', + message: 'fix!: some bugfix', + files: ['path1/file1.rb'], + type: 'fix', + scope: null, + bareMessage: 'some bugfix', + notes: [{title: 'BREAKING CHANGE', text: 'some bugfix'}], + references: [], + breaking: true, + }, + { + sha: 'sha3', + message: 'docs: some documentation', + files: ['path1/file1.java'], + type: 'docs', + scope: null, + bareMessage: 'some documentation', + notes: [], + references: [], + breaking: false, + }, + ]; + it('bumps major', async () => { + const strategy = new AlwaysBumpMajor(); + const oldVersion = Version.parse('1.2.3'); + const newVersion = await strategy.bump(oldVersion, commits); + expect(newVersion.toString()).to.equal('2.0.0'); + }); + }); + + describe('with a feature', () => { + const commits = [ + { + sha: 'sha1', + message: 'feat: some feature', + files: ['path1/file1.txt'], + type: 'feat', + scope: null, + bareMessage: 'some feature', + notes: [], + references: [], + breaking: false, + }, + { + sha: 'sha2', + message: 'fix: some bugfix', + files: ['path1/file1.rb'], + type: 'fix', + scope: null, + bareMessage: 'some bugfix', + notes: [], + references: [], + breaking: false, + }, + { + sha: 'sha3', + message: 'docs: some documentation', + files: ['path1/file1.java'], + type: 'docs', + scope: null, + bareMessage: 'some documentation', + notes: [], + references: [], + breaking: false, + }, + ]; + it('bumps major for minor', async () => { + const strategy = new AlwaysBumpMajor(); + const oldVersion = Version.parse('1.2.3'); + const newVersion = await strategy.bump(oldVersion, commits); + expect(newVersion.toString()).to.equal('2.0.0'); + }); + }); + + describe('with a fix', () => { + const commits = [ + { + sha: 'sha2', + message: 'fix: some bugfix', + files: ['path1/file1.rb'], + type: 'fix', + scope: null, + bareMessage: 'some bugfix', + notes: [], + references: [], + breaking: false, + }, + { + sha: 'sha3', + message: 'docs: some documentation', + files: ['path1/file1.java'], + type: 'docs', + scope: null, + bareMessage: 'some documentation', + notes: [], + references: [], + breaking: false, + }, + ]; + it('bumps major for patch', async () => { + const strategy = new AlwaysBumpMajor(); + const oldVersion = Version.parse('1.2.3'); + const newVersion = await strategy.bump(oldVersion, commits); + expect(newVersion.toString()).to.equal('2.0.0'); + }); + }); +}); diff --git a/test/versioning-strategies/always-bump-minor.ts b/test/versioning-strategies/always-bump-minor.ts new file mode 100644 index 000000000..cc20627fc --- /dev/null +++ b/test/versioning-strategies/always-bump-minor.ts @@ -0,0 +1,142 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import {describe, it} from 'mocha'; + +import {expect} from 'chai'; +import {AlwaysBumpMinor} from '../../src/versioning-strategies/always-bump-minor'; +import {Version} from '../../src/version'; + +describe('MinorVersioningStrategy', () => { + describe('with breaking change', () => { + const commits = [ + { + sha: 'sha1', + message: 'feat: some feature', + files: ['path1/file1.txt'], + type: 'feat', + scope: null, + bareMessage: 'some feature', + notes: [], + references: [], + breaking: false, + }, + { + sha: 'sha2', + message: 'fix!: some bugfix', + files: ['path1/file1.rb'], + type: 'fix', + scope: null, + bareMessage: 'some bugfix', + notes: [{title: 'BREAKING CHANGE', text: 'some bugfix'}], + references: [], + breaking: true, + }, + { + sha: 'sha3', + message: 'docs: some documentation', + files: ['path1/file1.java'], + type: 'docs', + scope: null, + bareMessage: 'some documentation', + notes: [], + references: [], + breaking: false, + }, + ]; + it('bumps minor for major', async () => { + const strategy = new AlwaysBumpMinor(); + const oldVersion = Version.parse('1.2.3'); + const newVersion = await strategy.bump(oldVersion, commits); + expect(newVersion.toString()).to.equal('1.3.0'); + }); + }); + + describe('with a feature', () => { + const commits = [ + { + sha: 'sha1', + message: 'feat: some feature', + files: ['path1/file1.txt'], + type: 'feat', + scope: null, + bareMessage: 'some feature', + notes: [], + references: [], + breaking: false, + }, + { + sha: 'sha2', + message: 'fix: some bugfix', + files: ['path1/file1.rb'], + type: 'fix', + scope: null, + bareMessage: 'some bugfix', + notes: [], + references: [], + breaking: false, + }, + { + sha: 'sha3', + message: 'docs: some documentation', + files: ['path1/file1.java'], + type: 'docs', + scope: null, + bareMessage: 'some documentation', + notes: [], + references: [], + breaking: false, + }, + ]; + it('bumps minor', async () => { + const strategy = new AlwaysBumpMinor(); + const oldVersion = Version.parse('1.2.3'); + const newVersion = await strategy.bump(oldVersion, commits); + expect(newVersion.toString()).to.equal('1.3.0'); + }); + }); + + describe('with a fix', () => { + const commits = [ + { + sha: 'sha2', + message: 'fix: some bugfix', + files: ['path1/file1.rb'], + type: 'fix', + scope: null, + bareMessage: 'some bugfix', + notes: [], + references: [], + breaking: false, + }, + { + sha: 'sha3', + message: 'docs: some documentation', + files: ['path1/file1.java'], + type: 'docs', + scope: null, + bareMessage: 'some documentation', + notes: [], + references: [], + breaking: false, + }, + ]; + it('bumps minor for patch', async () => { + const strategy = new AlwaysBumpMinor(); + const oldVersion = Version.parse('1.2.3'); + const newVersion = await strategy.bump(oldVersion, commits); + expect(newVersion.toString()).to.equal('1.3.0'); + }); + }); +});