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

Add $NEXT_{PATCH,MINOR,MAJOR}_VERSION_{PATCH,MINOR,MAJOR} variables #823

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 45 additions & 0 deletions dist/index.js
Expand Up @@ -1313,8 +1313,53 @@ const splitSemVer = (input, versionKey = 'version') => {
const getTemplatableVersion = (input) => {
const templatableVersion = {
$NEXT_MAJOR_VERSION: splitSemVer({ ...input, inc: 'major' }),
$NEXT_MAJOR_VERSION_MAJOR: splitSemVer({
...input,
inc: 'major',
template: '$MAJOR',
}),
$NEXT_MAJOR_VERSION_MINOR: splitSemVer({
...input,
inc: 'major',
template: '$MINOR',
}),
$NEXT_MAJOR_VERSION_PATCH: splitSemVer({
...input,
inc: 'major',
template: '$PATCH',
}),
$NEXT_MINOR_VERSION: splitSemVer({ ...input, inc: 'minor' }),
$NEXT_MINOR_VERSION_MAJOR: splitSemVer({
...input,
inc: 'minor',
template: '$MAJOR',
}),
$NEXT_MINOR_VERSION_MINOR: splitSemVer({
...input,
inc: 'minor',
template: '$MINOR',
}),
$NEXT_MINOR_VERSION_PATCH: splitSemVer({
...input,
inc: 'minor',
template: '$PATCH',
}),
$NEXT_PATCH_VERSION: splitSemVer({ ...input, inc: 'patch' }),
$NEXT_PATCH_VERSION_MAJOR: splitSemVer({
...input,
inc: 'patch',
template: '$MAJOR',
}),
$NEXT_PATCH_VERSION_MINOR: splitSemVer({
...input,
inc: 'patch',
template: '$MINOR',
}),
$NEXT_PATCH_VERSION_PATCH: splitSemVer({
...input,
inc: 'patch',
template: '$PATCH',
}),
$INPUT_VERSION: splitSemVer(input, 'inputVersion'),
$RESOLVED_VERSION: splitSemVer({
...input,
Expand Down
45 changes: 45 additions & 0 deletions lib/versions.js
Expand Up @@ -21,8 +21,53 @@ const splitSemVer = (input, versionKey = 'version') => {
const getTemplatableVersion = (input) => {
const templatableVersion = {
$NEXT_MAJOR_VERSION: splitSemVer({ ...input, inc: 'major' }),
$NEXT_MAJOR_VERSION_MAJOR: splitSemVer({
...input,
inc: 'major',
template: '$MAJOR',
}),
$NEXT_MAJOR_VERSION_MINOR: splitSemVer({
...input,
inc: 'major',
template: '$MINOR',
}),
$NEXT_MAJOR_VERSION_PATCH: splitSemVer({
...input,
inc: 'major',
template: '$PATCH',
}),
$NEXT_MINOR_VERSION: splitSemVer({ ...input, inc: 'minor' }),
$NEXT_MINOR_VERSION_MAJOR: splitSemVer({
...input,
inc: 'minor',
template: '$MAJOR',
}),
$NEXT_MINOR_VERSION_MINOR: splitSemVer({
...input,
inc: 'minor',
template: '$MINOR',
}),
$NEXT_MINOR_VERSION_PATCH: splitSemVer({
...input,
inc: 'minor',
template: '$PATCH',
}),
$NEXT_PATCH_VERSION: splitSemVer({ ...input, inc: 'patch' }),
$NEXT_PATCH_VERSION_MAJOR: splitSemVer({
...input,
inc: 'patch',
template: '$MAJOR',
}),
$NEXT_PATCH_VERSION_MINOR: splitSemVer({
...input,
inc: 'patch',
template: '$MINOR',
}),
$NEXT_PATCH_VERSION_PATCH: splitSemVer({
...input,
inc: 'patch',
template: '$PATCH',
}),
$INPUT_VERSION: splitSemVer(input, 'inputVersion'),
$RESOLVED_VERSION: splitSemVer({
...input,
Expand Down
@@ -1,4 +1,4 @@
template: Placeholder with example. Automatically calculated values are next major=$NEXT_MAJOR_VERSION, minor=$NEXT_MINOR_VERSION, patch=$NEXT_PATCH_VERSION
template: Placeholder with example. Automatically calculated values are next major=$NEXT_MAJOR_VERSION (major=$NEXT_MAJOR_VERSION_MAJOR, minor=$NEXT_MAJOR_VERSION_MINOR, patch=$NEXT_MAJOR_VERSION_PATCH), minor=$NEXT_MINOR_VERSION (major=$NEXT_MINOR_VERSION_MAJOR, minor=$NEXT_MINOR_VERSION_MINOR, patch=$NEXT_MINOR_VERSION_PATCH), patch=$NEXT_PATCH_VERSION (major=$NEXT_PATCH_VERSION_MAJOR, minor=$NEXT_PATCH_VERSION_MINOR, patch=$NEXT_PATCH_VERSION_PATCH)
name-template: 'v$NEXT_PATCH_VERSION (Code name: Placeholder)'
tag-template: v$NEXT_PATCH_VERSION
version-template: $MAJOR.$MINOR.$PATCH
@@ -1,4 +1,4 @@
template: Placeholder with example. Automatically calculated values are next major=$NEXT_MAJOR_VERSION, minor=$NEXT_MINOR_VERSION, patch=$NEXT_PATCH_VERSION
template: Placeholder with example. Automatically calculated values are next major=$NEXT_MAJOR_VERSION (major=$NEXT_MAJOR_VERSION_MAJOR, minor=$NEXT_MAJOR_VERSION_MINOR, patch=$NEXT_MAJOR_VERSION_PATCH), minor=$NEXT_MINOR_VERSION (major=$NEXT_MINOR_VERSION_MAJOR, minor=$NEXT_MINOR_VERSION_MINOR, patch=$NEXT_MINOR_VERSION_PATCH), patch=$NEXT_PATCH_VERSION (major=$NEXT_PATCH_VERSION_MAJOR, minor=$NEXT_PATCH_VERSION_MINOR, patch=$NEXT_PATCH_VERSION_PATCH)
name-template: 'v$NEXT_MINOR_VERSION (Code name: Placeholder)'
tag-template: v$NEXT_MINOR_VERSION
version-template: $MAJOR.$MINOR
@@ -1,4 +1,4 @@
template: Placeholder with example. Automatically calculated values are next major=$NEXT_MAJOR_VERSION, minor=$NEXT_MINOR_VERSION, patch=$NEXT_PATCH_VERSION
template: Placeholder with example. Automatically calculated values are next major=$NEXT_MAJOR_VERSION (major=$NEXT_MAJOR_VERSION_MAJOR, minor=$NEXT_MAJOR_VERSION_MINOR, patch=$NEXT_MAJOR_VERSION_PATCH), minor=$NEXT_MINOR_VERSION (major=$NEXT_MINOR_VERSION_MAJOR, minor=$NEXT_MINOR_VERSION_MINOR, patch=$NEXT_MINOR_VERSION_PATCH), patch=$NEXT_PATCH_VERSION (major=$NEXT_PATCH_VERSION_MAJOR, minor=$NEXT_PATCH_VERSION_MINOR, patch=$NEXT_PATCH_VERSION_PATCH)
name-template: 'v$NEXT_MAJOR_VERSION (Code name: Placeholder)'
tag-template: v$NEXT_MAJOR_VERSION
version-template: $MAJOR
2 changes: 1 addition & 1 deletion test/fixtures/config/config-with-next-versioning.yml
@@ -1,3 +1,3 @@
template: Placeholder with example. Automatically calculated values are next major=$NEXT_MAJOR_VERSION, minor=$NEXT_MINOR_VERSION, patch=$NEXT_PATCH_VERSION
template: Placeholder with example. Automatically calculated values are next major=$NEXT_MAJOR_VERSION (major=$NEXT_MAJOR_VERSION_MAJOR, minor=$NEXT_MAJOR_VERSION_MINOR, patch=$NEXT_MAJOR_VERSION_PATCH), minor=$NEXT_MINOR_VERSION (major=$NEXT_MINOR_VERSION_MAJOR, minor=$NEXT_MINOR_VERSION_MINOR, patch=$NEXT_MINOR_VERSION_PATCH), patch=$NEXT_PATCH_VERSION (major=$NEXT_PATCH_VERSION_MAJOR, minor=$NEXT_PATCH_VERSION_MINOR, patch=$NEXT_PATCH_VERSION_PATCH)
name-template: 'v$NEXT_PATCH_VERSION (Code name: Placeholder)'
tag-template: v$NEXT_PATCH_VERSION
8 changes: 4 additions & 4 deletions test/index.test.js
Expand Up @@ -429,7 +429,7 @@ describe('release-drafter', () => {
(body) => {
expect(body).toMatchInlineSnapshot(`
Object {
"body": "Placeholder with example. Automatically calculated values are next major=3.0.0, minor=2.1.0, patch=2.0.1",
"body": "Placeholder with example. Automatically calculated values are next major=3.0.0 (major=3, minor=0, patch=0), minor=2.1.0 (major=2, minor=1, patch=0), patch=2.0.1 (major=2, minor=0, patch=1)",
"draft": true,
"name": "v2.0.1 (Code name: Placeholder)",
"prerelease": false,
Expand Down Expand Up @@ -1170,7 +1170,7 @@ describe('release-drafter', () => {
(body) => {
expect(body).toMatchInlineSnapshot(`
Object {
"body": "Placeholder with example. Automatically calculated values are next major=3.0.0, minor=2.1.0, patch=2.0.1",
"body": "Placeholder with example. Automatically calculated values are next major=3.0.0 (major=3, minor=0, patch=0), minor=2.1.0 (major=2, minor=1, patch=0), patch=2.0.1 (major=2, minor=0, patch=1)",
"draft": true,
"name": "v2.0.1 (Code name: Placeholder)",
"prerelease": false,
Expand Down Expand Up @@ -1214,7 +1214,7 @@ describe('release-drafter', () => {
(body) => {
expect(body).toMatchInlineSnapshot(`
Object {
"body": "Placeholder with example. Automatically calculated values are next major=3.0, minor=2.1, patch=2.0",
"body": "Placeholder with example. Automatically calculated values are next major=3.0 (major=3, minor=0, patch=0), minor=2.1 (major=2, minor=1, patch=0), patch=2.0 (major=2, minor=0, patch=1)",
"draft": true,
"name": "v2.1 (Code name: Placeholder)",
"prerelease": false,
Expand Down Expand Up @@ -1258,7 +1258,7 @@ describe('release-drafter', () => {
(body) => {
expect(body).toMatchInlineSnapshot(`
Object {
"body": "Placeholder with example. Automatically calculated values are next major=3, minor=2, patch=2",
"body": "Placeholder with example. Automatically calculated values are next major=3 (major=3, minor=0, patch=0), minor=2 (major=2, minor=1, patch=0), patch=2 (major=2, minor=0, patch=1)",
"draft": true,
"name": "v3 (Code name: Placeholder)",
"prerelease": false,
Expand Down
152 changes: 136 additions & 16 deletions test/versions.test.js
Expand Up @@ -3,47 +3,167 @@ const each = require('jest-each').default

describe('versions', () => {
it('extracts a version-like string from the last tag', () => {
const versionInfo = getVersionInfo({
tag_name: 'v10.0.3',
name: 'Some release',
})
const versionInfo = getVersionInfo(
{
tag_name: 'v10.0.3',
name: 'Some release',
},
'$MAJOR.$MINOR.$PATCH'
)

expect(versionInfo.$NEXT_MAJOR_VERSION.version).toEqual('11.0.0')
expect(versionInfo.$NEXT_MAJOR_VERSION.template).toEqual(
'$MAJOR.$MINOR.$PATCH'
)
expect(versionInfo.$NEXT_MAJOR_VERSION_MAJOR.version).toEqual('11.0.0')
expect(versionInfo.$NEXT_MAJOR_VERSION_MAJOR.template).toEqual('$MAJOR')
expect(versionInfo.$NEXT_MAJOR_VERSION_MINOR.version).toEqual('11.0.0')
expect(versionInfo.$NEXT_MAJOR_VERSION_MINOR.template).toEqual('$MINOR')
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_MINOR_VERSION.template).toEqual(
'$MAJOR.$MINOR.$PATCH'
)
expect(versionInfo.$NEXT_MINOR_VERSION_MAJOR.version).toEqual('10.1.0')
expect(versionInfo.$NEXT_MINOR_VERSION_MAJOR.template).toEqual('$MAJOR')
expect(versionInfo.$NEXT_MINOR_VERSION_MINOR.version).toEqual('10.1.0')
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.template).toEqual(
'$MAJOR.$MINOR.$PATCH'
)
expect(versionInfo.$NEXT_PATCH_VERSION_MAJOR.version).toEqual('10.0.4')
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.template).toEqual('$MINOR')
expect(versionInfo.$NEXT_PATCH_VERSION_PATCH.version).toEqual('10.0.4')
expect(versionInfo.$NEXT_PATCH_VERSION_PATCH.template).toEqual('$PATCH')
})

it('extracts a version-like string from the last release name if the tag isnt a version', () => {
const versionInfo = getVersionInfo({
tag_name: 'notaproperversion',
name: '10.0.3',
})
const versionInfo = getVersionInfo(
{
tag_name: 'notaproperversion',
name: '10.0.3',
},
'$MAJOR.$MINOR.$PATCH'
)

expect(versionInfo.$NEXT_MAJOR_VERSION.version).toEqual('11.0.0')
expect(versionInfo.$NEXT_MAJOR_VERSION.template).toEqual(
'$MAJOR.$MINOR.$PATCH'
)
expect(versionInfo.$NEXT_MAJOR_VERSION_MAJOR.version).toEqual('11.0.0')
expect(versionInfo.$NEXT_MAJOR_VERSION_MAJOR.template).toEqual('$MAJOR')
expect(versionInfo.$NEXT_MAJOR_VERSION_MINOR.version).toEqual('11.0.0')
expect(versionInfo.$NEXT_MAJOR_VERSION_MINOR.template).toEqual('$MINOR')
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_MINOR_VERSION.template).toEqual(
'$MAJOR.$MINOR.$PATCH'
)
expect(versionInfo.$NEXT_MINOR_VERSION_MAJOR.version).toEqual('10.1.0')
expect(versionInfo.$NEXT_MINOR_VERSION_MAJOR.template).toEqual('$MAJOR')
expect(versionInfo.$NEXT_MINOR_VERSION_MINOR.version).toEqual('10.1.0')
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.template).toEqual(
'$MAJOR.$MINOR.$PATCH'
)
expect(versionInfo.$NEXT_PATCH_VERSION_MAJOR.version).toEqual('10.0.4')
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.template).toEqual('$MINOR')
expect(versionInfo.$NEXT_PATCH_VERSION_PATCH.version).toEqual('10.0.4')
expect(versionInfo.$NEXT_PATCH_VERSION_PATCH.template).toEqual('$PATCH')
})

it('preferences tags over release names', () => {
const versionInfo = getVersionInfo({
tag_name: '10.0.3',
name: '8.1.0',
})
const versionInfo = getVersionInfo(
{
tag_name: '10.0.3',
name: '8.1.0',
},
'$MAJOR.$MINOR.$PATCH'
)

expect(versionInfo.$NEXT_MAJOR_VERSION.version).toEqual('11.0.0')
expect(versionInfo.$NEXT_MAJOR_VERSION.template).toEqual(
'$MAJOR.$MINOR.$PATCH'
)
expect(versionInfo.$NEXT_MAJOR_VERSION_MAJOR.version).toEqual('11.0.0')
expect(versionInfo.$NEXT_MAJOR_VERSION_MAJOR.template).toEqual('$MAJOR')
expect(versionInfo.$NEXT_MAJOR_VERSION_MINOR.version).toEqual('11.0.0')
expect(versionInfo.$NEXT_MAJOR_VERSION_MINOR.template).toEqual('$MINOR')
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_MINOR_VERSION.template).toEqual(
'$MAJOR.$MINOR.$PATCH'
)
expect(versionInfo.$NEXT_MINOR_VERSION_MAJOR.version).toEqual('10.1.0')
expect(versionInfo.$NEXT_MINOR_VERSION_MAJOR.template).toEqual('$MAJOR')
expect(versionInfo.$NEXT_MINOR_VERSION_MINOR.version).toEqual('10.1.0')
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.template).toEqual(
'$MAJOR.$MINOR.$PATCH'
)
expect(versionInfo.$NEXT_PATCH_VERSION_MAJOR.version).toEqual('10.0.4')
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.template).toEqual('$MINOR')
expect(versionInfo.$NEXT_PATCH_VERSION_PATCH.version).toEqual('10.0.4')
expect(versionInfo.$NEXT_PATCH_VERSION_PATCH.template).toEqual('$PATCH')
})

it('handles alpha/beta releases', () => {
const versionInfo = getVersionInfo({
tag_name: 'v10.0.3-alpha',
name: 'Some release',
})
const versionInfo = getVersionInfo(
{
tag_name: 'v10.0.3-alpha',
name: 'Some release',
},
'$MAJOR.$MINOR.$PATCH'
)

expect(versionInfo.$NEXT_MAJOR_VERSION.version).toEqual('11.0.0')
expect(versionInfo.$NEXT_MAJOR_VERSION.template).toEqual(
'$MAJOR.$MINOR.$PATCH'
)
expect(versionInfo.$NEXT_MAJOR_VERSION_MAJOR.version).toEqual('11.0.0')
expect(versionInfo.$NEXT_MAJOR_VERSION_MAJOR.template).toEqual('$MAJOR')
expect(versionInfo.$NEXT_MAJOR_VERSION_MINOR.version).toEqual('11.0.0')
expect(versionInfo.$NEXT_MAJOR_VERSION_MINOR.template).toEqual('$MINOR')
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_MINOR_VERSION.template).toEqual(
'$MAJOR.$MINOR.$PATCH'
)
expect(versionInfo.$NEXT_MINOR_VERSION_MAJOR.version).toEqual('10.1.0')
expect(versionInfo.$NEXT_MINOR_VERSION_MAJOR.template).toEqual('$MAJOR')
expect(versionInfo.$NEXT_MINOR_VERSION_MINOR.version).toEqual('10.1.0')
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.template).toEqual(
'$MAJOR.$MINOR.$PATCH'
)
expect(versionInfo.$NEXT_PATCH_VERSION_MAJOR.version).toEqual('10.0.4')
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.template).toEqual('$MINOR')
expect(versionInfo.$NEXT_PATCH_VERSION_PATCH.version).toEqual('10.0.4')
expect(versionInfo.$NEXT_PATCH_VERSION_PATCH.template).toEqual('$PATCH')
})

it('returns undefined if no version was found in tag or name', () => {
Expand Down