Skip to content

Commit

Permalink
Provide sane defaults if we have no prior releases (#1067)
Browse files Browse the repository at this point in the history
the sane default should start in a minor
as 0.0.1 does not make sense from a SemVer perspective
some tools cannot handle 0.0.1 as a starting point

Co-authored-by: Devon Stewart <dstewart@tubi.tv>
  • Loading branch information
jetersen and Devon Stewart committed Feb 13, 2022
1 parent cc4a759 commit 68dc257
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 12 deletions.
47 changes: 46 additions & 1 deletion dist/index.js
Expand Up @@ -129872,6 +129872,50 @@ const splitSemVersion = (input, versionKey = 'version') => {
}
}

const defaultVersionInfo = {
$NEXT_MAJOR_VERSION: {
version: '1.0.0',
template: '$MAJOR.$MINOR.$PATCH',
inputVersion: null,
versionKeyIncrement: 'patch',
inc: 'major',
$MAJOR: 1,
$MINOR: 0,
$PATCH: 0,
},
$NEXT_MINOR_VERSION: {
version: '0.1.0',
template: '$MAJOR.$MINOR.$PATCH',
inputVersion: null,
versionKeyIncrement: 'patch',
inc: 'minor',
$MAJOR: 0,
$MINOR: 1,
$PATCH: 0,
},
$NEXT_PATCH_VERSION: {
version: '0.1.0',
template: '$MAJOR.$MINOR.$PATCH',
inputVersion: null,
versionKeyIncrement: 'patch',
inc: 'patch',
$MAJOR: 0,
$MINOR: 1,
$PATCH: 0,
},
$INPUT_VERSION: null,
$RESOLVED_VERSION: {
version: '0.1.0',
template: '$MAJOR.$MINOR.$PATCH',
inputVersion: null,
versionKeyIncrement: 'patch',
inc: 'patch',
$MAJOR: 0,
$MINOR: 1,
$PATCH: 0,
},
}

const getTemplatableVersion = (input) => {
const templatableVersion = {
$NEXT_MAJOR_VERSION: splitSemVersion({ ...input, inc: 'major' }),
Expand Down Expand Up @@ -129965,7 +130009,7 @@ const getVersionInfo = (
inputVersion = coerceVersion(inputVersion)

if (!version && !inputVersion) {
return
return defaultVersionInfo
}

return {
Expand All @@ -129979,6 +130023,7 @@ const getVersionInfo = (
}

exports.getVersionInfo = getVersionInfo
exports.defaultVersionInfo = defaultVersionInfo


/***/ }),
Expand Down
47 changes: 46 additions & 1 deletion lib/versions.js
Expand Up @@ -19,6 +19,50 @@ const splitSemVersion = (input, versionKey = 'version') => {
}
}

const defaultVersionInfo = {
$NEXT_MAJOR_VERSION: {
version: '1.0.0',
template: '$MAJOR.$MINOR.$PATCH',
inputVersion: null,
versionKeyIncrement: 'patch',
inc: 'major',
$MAJOR: 1,
$MINOR: 0,
$PATCH: 0,
},
$NEXT_MINOR_VERSION: {
version: '0.1.0',
template: '$MAJOR.$MINOR.$PATCH',
inputVersion: null,
versionKeyIncrement: 'patch',
inc: 'minor',
$MAJOR: 0,
$MINOR: 1,
$PATCH: 0,
},
$NEXT_PATCH_VERSION: {
version: '0.1.0',
template: '$MAJOR.$MINOR.$PATCH',
inputVersion: null,
versionKeyIncrement: 'patch',
inc: 'patch',
$MAJOR: 0,
$MINOR: 1,
$PATCH: 0,
},
$INPUT_VERSION: null,
$RESOLVED_VERSION: {
version: '0.1.0',
template: '$MAJOR.$MINOR.$PATCH',
inputVersion: null,
versionKeyIncrement: 'patch',
inc: 'patch',
$MAJOR: 0,
$MINOR: 1,
$PATCH: 0,
},
}

const getTemplatableVersion = (input) => {
const templatableVersion = {
$NEXT_MAJOR_VERSION: splitSemVersion({ ...input, inc: 'major' }),
Expand Down Expand Up @@ -112,7 +156,7 @@ const getVersionInfo = (
inputVersion = coerceVersion(inputVersion)

if (!version && !inputVersion) {
return
return defaultVersionInfo
}

return {
Expand All @@ -126,3 +170,4 @@ const getVersionInfo = (
}

exports.getVersionInfo = getVersionInfo
exports.defaultVersionInfo = defaultVersionInfo
6 changes: 3 additions & 3 deletions test/index.test.js
Expand Up @@ -2620,7 +2620,7 @@ describe('release-drafter', () => {
})

describe('without previous releases, no overrides', () => {
it('resolves to the calculated version, which will be empty', async () => {
it('resolves to the calculated version, which will be default', async () => {
getConfigMock('config-with-resolved-version-template.yml')

nock('https://api.github.com')
Expand Down Expand Up @@ -2651,9 +2651,9 @@ describe('release-drafter', () => {
",
"draft": true,
"name": "",
"name": "v0.1.0 🌈",
"prerelease": false,
"tag_name": "",
"tag_name": "v0.1.0",
"target_commitish": "refs/heads/master",
}
`)
Expand Down
11 changes: 4 additions & 7 deletions test/versions.test.js
@@ -1,4 +1,4 @@
const { getVersionInfo } = require('../lib/versions')
const { getVersionInfo, defaultVersionInfo } = require('../lib/versions')

describe('versions', () => {
it('extracts a version-like string from the last tag', () => {
Expand Down Expand Up @@ -170,13 +170,10 @@ describe('versions', () => {
expect(versionInfo.$NEXT_PATCH_VERSION_PATCH.template).toEqual('$PATCH')
})

it('returns undefined if no version was found in tag or name', () => {
const versionInfo = getVersionInfo({
tag_name: 'nope',
name: 'nope nope nope',
})
it('returns default version info if no version was found in tag or name', () => {
const versionInfo = getVersionInfo({})

expect(versionInfo).toEqual(undefined)
expect(versionInfo).toEqual(defaultVersionInfo)
})

it.each([
Expand Down

0 comments on commit 68dc257

Please sign in to comment.