Skip to content

Commit

Permalink
feat: add always-bump-minor versioning strategy (#1744)
Browse files Browse the repository at this point in the history
feat: add always-bump-major versioning strategy
  • Loading branch information
ddixit14 committed Nov 11, 2022
1 parent 09ae5a2 commit 7526ca8
Show file tree
Hide file tree
Showing 7 changed files with 356 additions and 5 deletions.
3 changes: 2 additions & 1 deletion __snapshots__/cli.js
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions docs/customizing.md
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions src/factories/versioning-strategy-factory.ts
Expand Up @@ -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';
Expand All @@ -35,6 +37,8 @@ export type VersioningStrategyBuilder = (
const versioningTypes: Record<string, VersioningStrategyBuilder> = {
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),
};

Expand Down
30 changes: 30 additions & 0 deletions 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();
}
}
30 changes: 30 additions & 0 deletions 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();
}
}
142 changes: 142 additions & 0 deletions 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');
});
});
});
142 changes: 142 additions & 0 deletions 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');
});
});
});

0 comments on commit 7526ca8

Please sign in to comment.