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

Expand vars in tag and name inputs #1049

Merged
merged 3 commits into from Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions dist/index.js
Expand Up @@ -129344,12 +129344,16 @@ const generateReleaseInfo = ({

if (tag === undefined) {
tag = versionInfo ? template(config['tag-template'] || '', versionInfo) : ''
} else if (versionInfo) {
tag = template(tag, versionInfo)
}

if (name === undefined) {
name = versionInfo
? template(config['name-template'] || '', versionInfo)
: ''
} else if (versionInfo) {
name = template(name, versionInfo)
}

if (commitish === undefined) {
Expand Down
4 changes: 4 additions & 0 deletions lib/releases.js
Expand Up @@ -306,12 +306,16 @@ const generateReleaseInfo = ({

if (tag === undefined) {
tag = versionInfo ? template(config['tag-template'] || '', versionInfo) : ''
} else if (versionInfo) {
tag = template(tag, versionInfo)
}

if (name === undefined) {
name = versionInfo
? template(config['name-template'] || '', versionInfo)
: ''
} else if (versionInfo) {
name = template(name, versionInfo)
}

if (commitish === undefined) {
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/config/config-with-name-and-tag-template.yml
@@ -0,0 +1,3 @@
template: Placeholder with example. Automatically calculated values based on previous releases are next major=$NEXT_MAJOR_VERSION, minor=$NEXT_MINOR_VERSION, patch=$NEXT_PATCH_VERSION.
name-template: 'v1.2.3 (Code name: Hello World)'
tag-template: v3.4.5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? Could we use some $RESOLVED_VERSION so at least the test looks sane 😓 I cannot handle that your getting one version in name and a different in tag.

34 changes: 34 additions & 0 deletions test/index.test.js
Expand Up @@ -2149,6 +2149,23 @@ describe('release-drafter', () => {
})
})

describe('with just the tag containing variables', () => {
it('gets the version from the tag and expands variables in it', async () => {
return overridesTest(
{
tag: 'v$RESOLVED_VERSION-beta',
configName: 'config-with-name-and-tag-template.yml',
},
{
body: `Placeholder with example. Automatically calculated values based on previous releases are next major=3.0.0, minor=2.1.0, patch=2.0.1.`,
draft: true,
name: 'v1.2.3 (Code name: Hello World)',
tag_name: 'v2.0.1-beta',
}
)
})
})

describe('with just the name', () => {
it('gets the version from the name and forces using the name', async () => {
return overridesTest(
Expand All @@ -2163,6 +2180,23 @@ describe('release-drafter', () => {
})
})

describe('with just the name containing variables', () => {
it('gets the version from the name and expands variables in it', async () => {
return overridesTest(
{
name: 'v$RESOLVED_VERSION-beta (Code name: Mega Unicorn)',
configName: 'config-with-name-and-tag-template.yml',
},
{
body: `Placeholder with example. Automatically calculated values based on previous releases are next major=3.0.0, minor=2.1.0, patch=2.0.1.`,
draft: true,
name: 'v2.0.1-beta (Code name: Mega Unicorn)',
tag_name: 'v3.4.5',
}
)
})
})

describe('with publish: true', () => {
it('immediately publishes the created draft', async () => {
return overridesTest(
Expand Down