From ab54450bc390992010e646e6603977deef05cfae Mon Sep 17 00:00:00 2001 From: Simon Gerber Date: Mon, 6 Nov 2023 14:07:09 +0100 Subject: [PATCH] Switch `latestTag()` to discard all tags except for full SemVer tags We use the regex `^v\d+\.\d+\.\d+$` to only keep fully qualified SemVer tags when finding the newest tag. This ensures that the action also works on repos which have major-version tags. --- __tests__/version.test.ts | 3 ++- dist/index.js | 2 +- src/version.ts | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/__tests__/version.test.ts b/__tests__/version.test.ts index 05a09e0..e645513 100644 --- a/__tests__/version.test.ts +++ b/__tests__/version.test.ts @@ -56,7 +56,8 @@ describe('latestTag', () => { 'v1.0.0', 'v1.2.2', 'foo-v1.0.0', - 'bar' + 'bar', + 'v1' ) getOctokitMock.mockImplementation(clientMock.mockFn) diff --git a/dist/index.js b/dist/index.js index 4291209..2967eec 100644 --- a/dist/index.js +++ b/dist/index.js @@ -33530,7 +33530,7 @@ async function latestTag() { const tags = tagsResp .map(({ name }) => name) .filter(tag => { - return tag.startsWith('v'); + return /^v\d+\.\d+\.\d+$/.test(tag); }) .sort(semver_1.rcompare); const latest = tags.length === 0 ? 'v0.0.0' : tags[0]; diff --git a/src/version.ts b/src/version.ts index d938f24..a841fce 100644 --- a/src/version.ts +++ b/src/version.ts @@ -13,7 +13,7 @@ export async function latestTag(): Promise { const tags = tagsResp .map(({ name }) => name) .filter(tag => { - return tag.startsWith('v') + return /^v\d+\.\d+\.\d+$/.test(tag) }) .sort(rcompare)