Skip to content

Commit 31ad231

Browse files
committed
fix: match tag to tagFormat from the begining of the string
1 parent a8a07b7 commit 31ad231

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/get-last-release.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ module.exports = async (tagFormat, logger) => {
2828
// by replacing the `version` variable in the template by `(.+)`.
2929
// The `tagFormat` is compiled with space as the `version` as it's an invalid tag character,
3030
// so it's guaranteed to no be present in the `tagFormat`.
31-
const tagRegexp = escapeRegExp(template(tagFormat)({version: ' '})).replace(' ', '(.+)');
31+
const tagRegexp = `^${escapeRegExp(template(tagFormat)({version: ' '})).replace(' ', '(.+)')}`;
32+
3233
const tags = (await gitTags())
3334
.map(tag => ({gitTag: tag, version: (tag.match(tagRegexp) || new Array(2))[1]}))
3435
.filter(

test/get-last-release.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ test.serial('Get the highest tag in the history of the current branch', async t
6262
t.deepEqual(result, {gitHead: commits[0].hash, gitTag: 'v2.0.0', version: '2.0.0'});
6363
});
6464

65+
test.serial('Match the tag name from the begining of the string', async t => {
66+
// Create a git repository, set the current working directory at the root of the repo
67+
await gitRepo();
68+
const commits = await gitCommits(['First']);
69+
await gitTagVersion('prefix/v1.0.0');
70+
await gitTagVersion('prefix/v2.0.0');
71+
await gitTagVersion('other-prefix/v3.0.0');
72+
73+
const result = await getLastRelease(`prefix/v\${version}`, t.context.logger);
74+
75+
t.deepEqual(result, {gitHead: commits[0].hash, gitTag: 'prefix/v2.0.0', version: '2.0.0'});
76+
});
77+
6578
test.serial('Return empty object if no valid tag is found', async t => {
6679
// Create a git repository, set the current working directory at the root of the repo
6780
await gitRepo();

0 commit comments

Comments
 (0)