Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only bump and create changelog if there ir a breaking change, feature or fix #99

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions command.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ const yargs = require('yargs')
default: defaults.npmPublishHint,
describe: 'Customized publishing hint'
})
.option('noBumpWhenEmptyChanges', {
type: 'boolean',
default: false,
describe: 'Avoid bumping files and generating changelog if there are no changes.'
})
.check((argv) => {
if (typeof argv.scripts !== 'object' || Array.isArray(argv.scripts)) {
throw Error('scripts must be an object')
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ module.exports = async function standardVersion (argv) {
}

const newVersion = await bump(args, version)
if (!newVersion) return
await changelog(args, newVersion)
await commit(args, newVersion)
await tag(newVersion, pkg ? pkg.private : false, args)
Expand Down
55 changes: 53 additions & 2 deletions lib/lifecycles/bump.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,45 @@
const semver = require('semver')
const writeFile = require('../write-file')
const { resolveUpdaterObjectFromArgument } = require('../updaters')
const addBangNotes = require('conventional-changelog-conventionalcommits/add-bang-notes')
let configsToUpdate = {}

function _whatBump (config, commits) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this perhaps be named noBumpWhenEmptyChanges ?

let level = 2
let breakings = 0
let features = 0
let fix = 0

Check warning on line 22 in lib/lifecycles/bump.js

View check run for this annotation

Codecov / codecov/patch

lib/lifecycles/bump.js#L19-L22

Added lines #L19 - L22 were not covered by tests

commits.forEach(commit => {
addBangNotes(commit)
if (commit.notes.length > 0) {
breakings += commit.notes.length
level = 0
} else if (commit.type === 'feat' || commit.type === 'feature') {
features += 1
if (level === 2) {
level = 1

Check warning on line 32 in lib/lifecycles/bump.js

View check run for this annotation

Codecov / codecov/patch

lib/lifecycles/bump.js#L24-L32

Added lines #L24 - L32 were not covered by tests
}
}
if (commit.type === 'fix') {
fix += 1

Check warning on line 36 in lib/lifecycles/bump.js

View check run for this annotation

Codecov / codecov/patch

lib/lifecycles/bump.js#L35-L36

Added lines #L35 - L36 were not covered by tests
}
})

if (config.preMajor && level < 2) {
level++

Check warning on line 41 in lib/lifecycles/bump.js

View check run for this annotation

Codecov / codecov/patch

lib/lifecycles/bump.js#L40-L41

Added lines #L40 - L41 were not covered by tests
}

if (!breakings && !features && !fix) return {}

Check warning on line 44 in lib/lifecycles/bump.js

View check run for this annotation

Codecov / codecov/patch

lib/lifecycles/bump.js#L44

Added line #L44 was not covered by tests

return {

Check warning on line 46 in lib/lifecycles/bump.js

View check run for this annotation

Codecov / codecov/patch

lib/lifecycles/bump.js#L46

Added line #L46 was not covered by tests
level,
reason: breakings === 1
hazzo marked this conversation as resolved.
Show resolved Hide resolved
? `There is ${breakings} BREAKING CHANGE and ${features} features`
: `There are ${breakings} BREAKING CHANGES and ${features} features`
}
}

async function Bump (args, version) {
// reset the cache of updated config files each
// time we perform the version bump step.
Expand All @@ -25,6 +62,14 @@
const stdout = await runLifecycleScript(args, 'prebump')
if (stdout && stdout.trim().length) args.releaseAs = stdout.trim()
const release = await bumpVersion(args.releaseAs, version, args)
if (!Object.keys(release).length) {
checkpoint(
args,
'no commits found, so not bumping version',
[]
)
return null
}
if (!args.firstRelease) {
const releaseType = getReleaseType(args.prerelease, release.releaseType, version)
const releaseTypeAsVersion = releaseType === 'pre' + release.releaseType ? semver.valid(release.releaseType + '-' + args.prerelease + '.0') : semver.valid(releaseType)
Expand Down Expand Up @@ -108,7 +153,8 @@
}

function bumpVersion (releaseAs, currentVersion, args) {
return new Promise((resolve, reject) => {
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve, reject) => {
Comment on lines +156 to +157
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve, reject) => {
return new Promise((resolve, reject) => {

Unless I'm missing something, you don't need this async

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I'll remove it it's from an old implementation.

if (releaseAs) {
return resolve({
releaseType: releaseAs
Expand All @@ -123,7 +169,12 @@
preset: presetOptions,
path: args.path,
tagPrefix: args.tagPrefix,
lernaPackage: args.lernaPackage
lernaPackage: args.lernaPackage,
...args.noBumpWhenEmptyChanges && {
whatBump (commits) {
return _whatBump(presetOptions, commits)

Check warning on line 175 in lib/lifecycles/bump.js

View check run for this annotation

Codecov / codecov/patch

lib/lifecycles/bump.js#L175

Added line #L175 was not covered by tests
}
Comment on lines +173 to +176
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
...args.noBumpWhenEmptyChanges && {
whatBump (commits) {
return _whatBump(presetOptions, commits)
}
...(args.noBumpWhenEmptyChanges
? {
whatBump (commits) {
return _whatBump(presetOptions, commits)
}
}
: {})

^ I think this is a bit more idiomatic

}
}, args.parserOpts, function (err, release) {
if (err) return reject(err)
else return resolve(release)
Expand Down