Skip to content

Commit

Permalink
fix: exclude prereleases from version retrived by getLastRelease
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg authored and gr2m committed Mar 8, 2018
1 parent e5a73d8 commit e4618a2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/get-last-release.js
Expand Up @@ -33,7 +33,9 @@ module.exports = async (tagFormat, logger) => {
.map(tag => {
return {gitTag: tag, version: (tag.match(tagRegexp) || new Array(2))[1]};
})
.filter(tag => tag.version && semver.valid(semver.clean(tag.version)))
.filter(
tag => tag.version && semver.valid(semver.clean(tag.version)) && !semver.prerelease(semver.clean(tag.version))
)
.sort((a, b) => semver.rcompare(a.version, b.version));

debug('found tags: %o', tags);
Expand Down
11 changes: 10 additions & 1 deletion test/get-last-release.test.js
Expand Up @@ -17,7 +17,7 @@ test.afterEach.always(() => {
process.chdir(cwd);
});

test.serial('Get the highest valid tag', async t => {
test.serial('Get the highest non-prerelease valid tag', async t => {
// Create a git repository, set the current working directory at the root of the repo
await gitRepo();
// Create some commits and tags
Expand All @@ -29,6 +29,8 @@ test.serial('Get the highest valid tag', async t => {
await gitTagVersion('v1.0.0');
await gitCommits(['Fourth']);
await gitTagVersion('v3.0');
await gitCommits(['Fifth']);
await gitTagVersion('v3.0.0-beta.1');

const result = await getLastRelease(`v\${version}`, t.context.logger);

Expand Down Expand Up @@ -117,4 +119,11 @@ test.serial('Get the highest valid tag corresponding to the "tagFormat"', async
gitTag: '2.0.0-1.0.0-bar.1',
version: '1.0.0',
});

await gitTagVersion('3.0.0-bar.1');
t.deepEqual(await getLastRelease(`\${version}-bar.1`, t.context.logger), {
gitHead,
gitTag: '3.0.0-bar.1',
version: '3.0.0',
});
});

0 comments on commit e4618a2

Please sign in to comment.