-
Notifications
You must be signed in to change notification settings - Fork 794
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
feat: detect if a release is necessary #750
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,10 @@ async function Bump (args, version) { | |
if (stdout && stdout.trim().length) args.releaseAs = stdout.trim() | ||
const release = await bumpVersion(args.releaseAs, version, args) | ||
if (!args.firstRelease) { | ||
if (args.detectRelease && !release.releaseType) { | ||
checkpoint(args, release.reason, []) | ||
process.exit() | ||
} | ||
const releaseType = getReleaseType(args.prerelease, release.releaseType, version) | ||
newVersion = semver.valid(releaseType) || semver.inc(version, releaseType, args.prerelease) | ||
updateConfigs(args, newVersion) | ||
|
@@ -77,7 +81,12 @@ function isInPrerelease (version) { | |
return Array.isArray(semver.prerelease(version)) | ||
} | ||
|
||
const TypeList = ['major', 'minor', 'patch'].reverse() | ||
const MAJOR = 'major' | ||
const MINOR = 'minor' | ||
const PATCH = 'patch' | ||
const VERSIONS = [MAJOR, MINOR, PATCH] | ||
|
||
const TypeList = [...VERSIONS].reverse() | ||
|
||
/** | ||
* extract the in-pre-release type in target version | ||
|
@@ -106,6 +115,8 @@ function getTypePriority (type) { | |
} | ||
|
||
function bumpVersion (releaseAs, currentVersion, args) { | ||
const releaseTypes = args.types.reduce((acc, current) => (!current.hidden ? [...acc, current.type] : acc), []) | ||
|
||
return new Promise((resolve, reject) => { | ||
if (releaseAs) { | ||
return resolve({ | ||
|
@@ -120,7 +131,34 @@ function bumpVersion (releaseAs, currentVersion, args) { | |
debug: args.verbose && console.info.bind(console, 'conventional-recommended-bump'), | ||
preset: presetOptions, | ||
path: args.path, | ||
tagPrefix: args.tagPrefix | ||
tagPrefix: args.tagPrefix, | ||
whatBump: (commits) => { | ||
let level = PATCH | ||
let breakings = 0 | ||
let features = 0 | ||
|
||
commits.forEach(commit => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is most of the way there, but one concern, the conventional-commits strategy has a more complex Which includes support for Is it possible for us to use whatever default There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Initially, I had that approach in mind but after some exploring, I was not able to find a clear way to get the default 💭 Would be cool if How do you think we should proceed @bcoe ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nelsonfncosta I think each preset should be exporting its The problem with copying the logic over from any one preset, is that we allow folks to configure their own preset -- so although the logic would be good for conventional commits, it would be off potentially for another plugin. I haven't tried to do this myself, and apologize for how much of a yarn ball the conventional changelog codebase is -- I think though you should be able to pluck There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will take a closer look into this! 👀 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have been looking for a way to get the preset config, they are not directly exported
the problem I'm facing I'm not really sure how to "wait/get" my value from here |
||
if (commit.notes.length > 0) { | ||
breakings += commit.notes.length | ||
level = MAJOR | ||
} else if (releaseTypes.includes(commit.type)) { | ||
features += 1 | ||
|
||
level = level === PATCH ? MINOR : level | ||
} | ||
}) | ||
|
||
if (breakings + features === 0) { | ||
return { | ||
level: null, | ||
reason: `No commits found for types: [${releaseTypes.join(', ')}], skipping release stage.` | ||
} | ||
} | ||
|
||
return { | ||
level: VERSIONS.indexOf(level) | ||
} | ||
} | ||
}, function (err, release) { | ||
if (err) return reject(err) | ||
else return resolve(release) | ||
|
@@ -169,3 +207,4 @@ function updateConfigs (args, newVersion) { | |
} | ||
|
||
module.exports = Bump | ||
module.exports.bumpVersion = bumpVersion |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* global describe it beforeEach afterEach */ | ||
|
||
'use strict' | ||
|
||
const { bumpVersion } = require('../lib/lifecycles/bump') | ||
const shell = require('shelljs') | ||
const chai = require('chai') | ||
const { expect } = chai | ||
|
||
describe('bumpVersion', () => { | ||
const args = { | ||
types: [ | ||
{ type: 'feat', section: 'Features' }, | ||
{ type: 'test', section: 'Tests', hidden: true } | ||
] | ||
} | ||
|
||
beforeEach(() => { | ||
shell.rm('-rf', 'tmp') | ||
shell.config.silent = true | ||
shell.mkdir('tmp') | ||
shell.cd('tmp') | ||
shell.exec('git init') | ||
shell.exec('git config commit.gpgSign false') | ||
shell.exec('git config core.autocrlf false') | ||
}) | ||
|
||
afterEach(() => { | ||
shell.cd('../') | ||
shell.rm('-rf', 'tmp') | ||
}) | ||
|
||
describe('when a tag is avaialble', () => { | ||
let result | ||
|
||
beforeEach(async () => { | ||
shell.exec('git commit --allow-empty -m "first-commit"') | ||
shell.exec('git tag 1.2.3') | ||
}) | ||
|
||
describe('and release commits are present', () => { | ||
beforeEach(async () => { | ||
shell.exec('git commit --allow-empty -m "feat: second-commit"') | ||
|
||
result = await bumpVersion(null, '1.2.3', args) | ||
}) | ||
|
||
it('should return a release recommendation', async () => { | ||
expect(result).to.include({ level: 1, releaseType: 'minor' }) | ||
}) | ||
}) | ||
|
||
describe('and no release commits are present', () => { | ||
beforeEach(async () => { | ||
shell.exec('git commit --allow-empty -m "test: second-commit"') | ||
|
||
result = await bumpVersion(null, '1.2.3', args) | ||
}) | ||
|
||
it('should return no release', async () => { | ||
expect(result).to.include({ | ||
level: null, | ||
reason: 'No commits found for types: [feat], skipping release stage.' | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('when no tag is found', () => { | ||
let result | ||
|
||
beforeEach(async () => { | ||
shell.exec('git commit --allow-empty -m "first-commit"') | ||
shell.exec('git commit --allow-empty -m "second-commit"') | ||
|
||
result = await bumpVersion(null, '1.2.3', args) | ||
}) | ||
|
||
it('should return no release', async () => { | ||
expect(result).to.include({ | ||
level: null, | ||
reason: 'No commits found for types: [feat], skipping release stage.' | ||
}) | ||
}) | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wanted to highlight this change,
args.dryRun
seems to have been a typo.Looking at the usage of
args
the expected is an array and not an object.standard-version/lib/checkpoint.js
Line 8 in 4383381