From 68dc25766adf2e4c4931bc70caaab1512cb23375 Mon Sep 17 00:00:00 2001 From: Joseph Petersen Date: Sun, 13 Feb 2022 08:53:20 +0100 Subject: [PATCH] Provide sane defaults if we have no prior releases (#1067) 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 --- dist/index.js | 47 ++++++++++++++++++++++++++++++++++++++++++- lib/versions.js | 47 ++++++++++++++++++++++++++++++++++++++++++- test/index.test.js | 6 +++--- test/versions.test.js | 11 ++++------ 4 files changed, 99 insertions(+), 12 deletions(-) diff --git a/dist/index.js b/dist/index.js index ddddcea80..b537eab14 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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' }), @@ -129965,7 +130009,7 @@ const getVersionInfo = ( inputVersion = coerceVersion(inputVersion) if (!version && !inputVersion) { - return + return defaultVersionInfo } return { @@ -129979,6 +130023,7 @@ const getVersionInfo = ( } exports.getVersionInfo = getVersionInfo +exports.defaultVersionInfo = defaultVersionInfo /***/ }), diff --git a/lib/versions.js b/lib/versions.js index d6daad6ee..abff55e1b 100644 --- a/lib/versions.js +++ b/lib/versions.js @@ -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' }), @@ -112,7 +156,7 @@ const getVersionInfo = ( inputVersion = coerceVersion(inputVersion) if (!version && !inputVersion) { - return + return defaultVersionInfo } return { @@ -126,3 +170,4 @@ const getVersionInfo = ( } exports.getVersionInfo = getVersionInfo +exports.defaultVersionInfo = defaultVersionInfo diff --git a/test/index.test.js b/test/index.test.js index 4a43c3243..3f2671444 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -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') @@ -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", } `) diff --git a/test/versions.test.js b/test/versions.test.js index e8fa6fea1..4cb929bda 100644 --- a/test/versions.test.js +++ b/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', () => { @@ -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([