Skip to content

Commit

Permalink
feat: allow "standard" pre 1.0.0 patch bumps (#847)
Browse files Browse the repository at this point in the history
opt-in behavior for packages that want to follow the standard
convetional-commits behavior of bumping the patch instead of the minor

Co-authored-by: sofisl <55454395+sofisl@users.noreply.github.com>
  • Loading branch information
joeldodge79 and sofisl committed Apr 7, 2021
1 parent 2799647 commit a5e2cc2
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 89 deletions.
194 changes: 106 additions & 88 deletions __snapshots__/cli.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions docs/manifest-releaser.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ documented in comments)
// absence defaults to false
"bump-minor-pre-major": true,

// feat commits bump semver patch instead of minor if version < 1.0.0
// absence defaults to false
"bump-patch-for-minor-pre-major": true,

// set default conventional commit => changelog sections mapping/appearance.
// absence defaults to https://git.io/JqCZL
"changelog-sections": [...]
Expand Down
7 changes: 7 additions & 0 deletions src/bin/release-please.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ function releaserCommon(ya: YargsOptionsBuilder) {
default: false,
type: 'boolean',
});
ya.option('bump-minor-for-patch-pre-major', {
describe:
'should we bump the semver patch instead of the minor for non-breaking' +
' changes prior to the first major release',
default: false,
type: 'boolean',
});
ya.option('path', {
describe: 'release from path other than root directory',
type: 'string',
Expand Down
7 changes: 6 additions & 1 deletion src/conventional-commits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ interface ConventionalCommitsOptions {
repository: string;
host?: string;
bumpMinorPreMajor?: boolean;
bumpPatchForMinorPreMajor?: boolean;
// allow for customized commit template.
commitPartial?: string;
headerPartial?: string;
Expand Down Expand Up @@ -146,6 +147,7 @@ export class ConventionalCommits {
owner: string;
repository: string;
bumpMinorPreMajor?: boolean;
bumpPatchForMinorPreMajor?: boolean;

// allow for customized commit template.
commitPartial?: string;
Expand All @@ -157,6 +159,7 @@ export class ConventionalCommits {
constructor(options: ConventionalCommitsOptions) {
this.commits = options.commits;
this.bumpMinorPreMajor = options.bumpMinorPreMajor || false;
this.bumpPatchForMinorPreMajor = options.bumpPatchForMinorPreMajor || false;
this.host = options.host || 'https://www.github.com';
this.owner = options.owner;
this.repository = options.repository;
Expand Down Expand Up @@ -237,9 +240,11 @@ export class ConventionalCommits {

// we have slightly different logic than the default of conventional commits,
// the minor should be bumped when features are introduced for pre 1.x.x libs:
// turn off custom logic here by setting bumpPatchForMinorPreMajor = true
if (
result.reason.indexOf(' 0 features') === -1 &&
result.releaseType === 'patch'
result.releaseType === 'patch' &&
!this.bumpPatchForMinorPreMajor
) {
result.releaseType = 'minor';
}
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface ReleasePROptions {
path?: string;
packageName?: string;
bumpMinorPreMajor?: boolean;
bumpPatchForMinorPreMajor?: boolean;
releaseAs?: string;
snapshot?: boolean;
monorepoTags?: boolean;
Expand Down
5 changes: 5 additions & 0 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {ReleasePR} from './release-pr';
interface ReleaserConfigJson {
'release-type'?: ReleaseType;
'bump-minor-pre-major'?: boolean;
'bump-patch-for-minor-pre-major'?: boolean;
'changelog-sections'?: ChangelogSection[];
'release-as'?: string;
draft?: boolean;
Expand Down Expand Up @@ -74,6 +75,7 @@ type Package = Pick<
| 'draft'
| 'packageName'
| 'bumpMinorPreMajor'
| 'bumpPatchForMinorPreMajor'
| 'releaseAs'
| 'changelogSections'
| 'changelogPath'
Expand Down Expand Up @@ -252,6 +254,9 @@ export class Manifest {
packageName: pkgCfg['package-name'],
bumpMinorPreMajor:
pkgCfg['bump-minor-pre-major'] ?? config['bump-minor-pre-major'],
bumpPatchForMinorPreMajor:
pkgCfg['bump-patch-for-minor-pre-major'] ??
config['bump-patch-for-minor-pre-major'],
changelogSections:
pkgCfg['changelog-sections'] ?? config['changelog-sections'],
changelogPath: pkgCfg['changelog-path'],
Expand Down
2 changes: 2 additions & 0 deletions src/release-pr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export class ReleasePR {
labels: string[];
gh: GitHub;
bumpMinorPreMajor?: boolean;
bumpPatchForMinorPreMajor?: boolean;
path?: string;
packageName: string;
monorepoTags: boolean;
Expand All @@ -86,6 +87,7 @@ export class ReleasePR {

constructor(options: ReleasePRConstructorOptions) {
this.bumpMinorPreMajor = options.bumpMinorPreMajor || false;
this.bumpPatchForMinorPreMajor = options.bumpPatchForMinorPreMajor || false;
this.labels = options.labels ?? DEFAULT_LABELS;
// undefined represents the root path of the library, if the special
// '.' path is provided, simply ignore it:
Expand Down
1 change: 1 addition & 0 deletions src/releasers/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class Node extends ReleasePR {
owner: this.gh.owner,
repository: this.gh.repo,
bumpMinorPreMajor: this.bumpMinorPreMajor,
bumpPatchForMinorPreMajor: this.bumpPatchForMinorPreMajor,
changelogSections: this.changelogSections,
});
const candidate: ReleaseCandidate = await this.coerceReleaseCandidate(
Expand Down
1 change: 1 addition & 0 deletions src/releasers/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class Python extends ReleasePR {
owner: this.gh.owner,
repository: this.gh.repo,
bumpMinorPreMajor: this.bumpMinorPreMajor,
bumpPatchForMinorPreMajor: this.bumpPatchForMinorPreMajor,
changelogSections: this.changelogSections || CHANGELOG_SECTIONS,
});
const candidate: ReleaseCandidate = await this.coerceReleaseCandidate(
Expand Down
22 changes: 22 additions & 0 deletions test/conventional-commits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,28 @@ describe('ConventionalCommits', () => {
expect(bump.releaseType).to.equal('minor');
expect(bump.reason).to.equal('There is 1 BREAKING CHANGE and 1 features');
});

it('follows standard patch for minor bump behavior pre 1.0', async () => {
const cc = new ConventionalCommits({
commits: [
{
message: 'fix: addressed issues with foo',
sha: 'abc123',
files: [],
},
{message: 'feat: awesome feature', sha: 'abc678', files: []},
],
owner: 'bcoe',
repository: 'release-please',
bumpMinorPreMajor: true,
bumpPatchForMinorPreMajor: true,
});
const bump = await cc.suggestBump('0.3.0');
expect(bump.releaseType).to.equal('patch');
expect(bump.reason).to.equal(
'There are 0 BREAKING CHANGES and 1 features'
);
});
});

describe('generateChangelogEntry', () => {
Expand Down

0 comments on commit a5e2cc2

Please sign in to comment.