diff --git a/README.md b/README.md index 6728df705..3c4b6545f 100644 --- a/README.md +++ b/README.md @@ -162,11 +162,12 @@ You can use any of the following variables in your `template`, `name-template` a You can use any of the following variables in `version-template` to format the `$NEXT_{PATCH,MINOR,MAJOR}_VERSION` variables: -| Variable | Description | -| -------- | ------------------------- | -| `$PATCH` | The patch version number. | -| `$MINOR` | The minor version number. | -| `$MAJOR` | The major version number. | +| Variable | Description | +| ----------- | ------------------------------------------------------------ | +| `$PATCH` | The patch version number. | +| `$MINOR` | The minor version number. | +| `$MAJOR` | The major version number. | +| `$COMPLETE` | The complete version string (including any prerelease info). | ## Version Resolver diff --git a/dist/index.js b/dist/index.js index b748a8e34..95a8d8600 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1319,7 +1319,7 @@ const splitSemVer = (input, versionKey = 'version') => { const version = input.inc ? semver.inc(input[versionKey], input.inc, true) - : semver.parse(input[versionKey]) + : input[versionKey].version return { ...input, @@ -1327,6 +1327,7 @@ const splitSemVer = (input, versionKey = 'version') => { $MAJOR: semver.major(version), $MINOR: semver.minor(version), $PATCH: semver.patch(version), + $COMPLETE: version, } } @@ -1393,14 +1394,24 @@ const getTemplatableVersion = (input) => { return templatableVersion } +const toSemver = (version) => { + const result = semver.parse(version) + if (result) { + return result + } + + // doesn't handle prerelease + return semver.coerce(version) +} + const coerceVersion = (input) => { if (!input) { return null } return typeof input === 'object' - ? semver.coerce(input.tag_name) || semver.coerce(input.name) - : semver.coerce(input) + ? toSemver(input.tag_name) || toSemver(input.name) + : toSemver(input) } module.exports.getVersionInfo = ( diff --git a/lib/versions.js b/lib/versions.js index 7346d703f..54dd7d038 100644 --- a/lib/versions.js +++ b/lib/versions.js @@ -7,7 +7,7 @@ const splitSemVer = (input, versionKey = 'version') => { const version = input.inc ? semver.inc(input[versionKey], input.inc, true) - : semver.parse(input[versionKey]) + : input[versionKey].version return { ...input, @@ -15,6 +15,7 @@ const splitSemVer = (input, versionKey = 'version') => { $MAJOR: semver.major(version), $MINOR: semver.minor(version), $PATCH: semver.patch(version), + $COMPLETE: version, } } @@ -81,14 +82,24 @@ const getTemplatableVersion = (input) => { return templatableVersion } +const toSemver = (version) => { + const result = semver.parse(version) + if (result) { + return result + } + + // doesn't handle prerelease + return semver.coerce(version) +} + const coerceVersion = (input) => { if (!input) { return null } return typeof input === 'object' - ? semver.coerce(input.tag_name) || semver.coerce(input.name) - : semver.coerce(input) + ? toSemver(input.tag_name) || toSemver(input.name) + : toSemver(input) } module.exports.getVersionInfo = ( diff --git a/test/versions.test.js b/test/versions.test.js index 1261f1058..16a86e8d4 100644 --- a/test/versions.test.js +++ b/test/versions.test.js @@ -131,7 +131,8 @@ describe('versions', () => { tag_name: 'v10.0.3-alpha', name: 'Some release', }, - '$MAJOR.$MINOR.$PATCH' + '$MAJOR.$MINOR.$PATCH', + 'v10.0.3-alpha' ) expect(versionInfo.$NEXT_MAJOR_VERSION.version).toEqual('11.0.0') @@ -145,6 +146,10 @@ describe('versions', () => { expect(versionInfo.$NEXT_MAJOR_VERSION_PATCH.version).toEqual('11.0.0') expect(versionInfo.$NEXT_MAJOR_VERSION_PATCH.template).toEqual('$PATCH') expect(versionInfo.$NEXT_MINOR_VERSION.version).toEqual('10.1.0') + expect(versionInfo.$NEXT_PATCH_VERSION.version).toEqual('10.0.3') + expect(versionInfo.$INPUT_VERSION.version).toEqual('10.0.3-alpha') + expect(versionInfo.$RESOLVED_VERSION.version).toEqual('10.0.3-alpha') + expect(versionInfo.$NEXT_MINOR_VERSION.template).toEqual( '$MAJOR.$MINOR.$PATCH' ) @@ -154,15 +159,15 @@ describe('versions', () => { expect(versionInfo.$NEXT_MINOR_VERSION_MINOR.template).toEqual('$MINOR') expect(versionInfo.$NEXT_MINOR_VERSION_PATCH.version).toEqual('10.1.0') expect(versionInfo.$NEXT_MINOR_VERSION_PATCH.template).toEqual('$PATCH') - expect(versionInfo.$NEXT_PATCH_VERSION.version).toEqual('10.0.4') + expect(versionInfo.$NEXT_PATCH_VERSION.version).toEqual('10.0.3') expect(versionInfo.$NEXT_PATCH_VERSION.template).toEqual( '$MAJOR.$MINOR.$PATCH' ) - expect(versionInfo.$NEXT_PATCH_VERSION_MAJOR.version).toEqual('10.0.4') + expect(versionInfo.$NEXT_PATCH_VERSION_MAJOR.version).toEqual('10.0.3') expect(versionInfo.$NEXT_PATCH_VERSION_MAJOR.template).toEqual('$MAJOR') - expect(versionInfo.$NEXT_PATCH_VERSION_MINOR.version).toEqual('10.0.4') + expect(versionInfo.$NEXT_PATCH_VERSION_MINOR.version).toEqual('10.0.3') expect(versionInfo.$NEXT_PATCH_VERSION_MINOR.template).toEqual('$MINOR') - expect(versionInfo.$NEXT_PATCH_VERSION_PATCH.version).toEqual('10.0.4') + expect(versionInfo.$NEXT_PATCH_VERSION_PATCH.version).toEqual('10.0.3') expect(versionInfo.$NEXT_PATCH_VERSION_PATCH.template).toEqual('$PATCH') })