From 7526ca8be4fec4d785b44bfb8c8c70078ad7fc73 Mon Sep 17 00:00:00 2001 From: Deepankar Dixit <90280028+ddixit14@users.noreply.github.com> Date: Fri, 11 Nov 2022 16:48:35 +0000 Subject: [PATCH] feat: add always-bump-minor versioning strategy (#1744) feat: add always-bump-major versioning strategy --- __snapshots__/cli.js | 3 +- docs/customizing.md | 10 +- src/factories/versioning-strategy-factory.ts | 4 + .../always-bump-major.ts | 30 ++++ .../always-bump-minor.ts | 30 ++++ .../always-bump-major.ts | 142 ++++++++++++++++++ .../always-bump-minor.ts | 142 ++++++++++++++++++ 7 files changed, 356 insertions(+), 5 deletions(-) create mode 100644 src/versioning-strategies/always-bump-major.ts create mode 100644 src/versioning-strategies/always-bump-minor.ts create mode 100644 test/versioning-strategies/always-bump-major.ts create mode 100644 test/versioning-strategies/always-bump-minor.ts 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 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/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/versioning-strategies/always-bump-major.ts b/src/versioning-strategies/always-bump-major.ts new file mode 100644 index 000000000..e0c04fae0 --- /dev/null +++ b/src/versioning-strategies/always-bump-major.ts @@ -0,0 +1,30 @@ +// 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 {Version} from '../version'; +import {ConventionalCommit} from '../commit'; +import {DefaultVersioningStrategy} from './default'; +import {VersionUpdater, MajorVersionUpdate} from '../versioning-strategy'; + +/** + * This VersioningStrategy always bumps the major version. + */ +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..1602b447f --- /dev/null +++ b/src/versioning-strategies/always-bump-minor.ts @@ -0,0 +1,30 @@ +// 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 {Version} from '../version'; +import {ConventionalCommit} from '../commit'; +import {DefaultVersioningStrategy} from './default'; +import {VersionUpdater, MinorVersionUpdate} from '../versioning-strategy'; + +/** + * This VersioningStrategy always bumps the minor version. + */ +export class AlwaysBumpMinor extends DefaultVersioningStrategy { + determineReleaseType( + _version: Version, + _commits: ConventionalCommit[] + ): VersionUpdater { + return new MinorVersionUpdate(); + } +} 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'); + }); + }); +});