Skip to content

Commit 0bd4f31

Browse files
committed
Support hotfix versions
Closes gh-50
1 parent 9d62bfb commit 0bd4f31

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

lib/latest-version-extension.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const TagSemVerRx = /^v?(\d+)\.(\d+)\.(\d+)(?:-(RC|M)(\d+))?$/
3+
const TagSemVerRx = /^v?(\d+)\.(\d+)\.(\d+)(?:\.(\d+))?(?:-(RC|M)(\d+))?$/
44

55
const { name: packageName } = require('#package')
66
/**
@@ -21,7 +21,6 @@ module.exports.register = function ({ playbook }) {
2121
.filter((a) => a.origins[0].tag)
2222
.sort((a, b) => compareSemVerAscending(componentRefname(a), componentRefname(b)))
2323
.reverse()
24-
2524
for (const componentVersionBucket of tags) {
2625
const { name: componentName } = componentVersionBucket
2726
if (!componentToGenerationMapping.has(componentName)) {
@@ -71,7 +70,7 @@ function compareSemVerAscending (lhs, rhs) {
7170
for (const [index, leftPart] of lhsParts.entries()) {
7271
const rightPart = rhsParts[index]
7372
if (leftPart !== rightPart) {
74-
if (index !== 3) {
73+
if (index !== lhsParts.length - 2) {
7574
return Number(leftPart) - Number(rightPart)
7675
}
7776
return leftPart < rightPart ? -1 : 1
@@ -80,13 +79,32 @@ function compareSemVerAscending (lhs, rhs) {
8079
return 0
8180
}
8281

82+
/**
83+
* Returns an array of the parsed version [int major, int minor, int patch, int hotfix, String type, int typeVersion].
84+
*
85+
* If hotfix is undefined, it is explicitly replaced with -1 to ensure proper sorting.
86+
*
87+
* The type is either M (milestones), RC (release candidates), or Z (explicitly replaced for releases to ensure proper
88+
* sorting of releases).
89+
*
90+
* The type version is the count of the type. If it is undefined (only releases), then it remains undefined since
91+
* this comparison is unnecessary.
92+
*
93+
* @param version the version in the format of a tag (e.g. v1.0.0-M1 v1.0.0-RC1 v1.0.0 v1.0.1 v1.0.1.1). The v prefix is
94+
* optional, so v1.0.0 and 1.0.0 are treated the same.
95+
* @returns an array of the parsed version used for comparison.
96+
*/
8397
function extractVersionParts (version) {
8498
const match = version.match(TagSemVerRx)
8599
if (!match) {
86100
throw new Error(`Cannot parse version = ${version} with regex ${TagSemVerRx}`)
87101
}
88102
const result = Array.from(match)
89103
result.splice(0, 1)
104+
const hotfixIndex = result.length - 3
105+
if (result[hotfixIndex] === undefined) {
106+
result[hotfixIndex] = -1
107+
}
90108
const milestoneRcIndex = result.length - 2
91109
if (result[milestoneRcIndex] === undefined) {
92110
result[milestoneRcIndex] = 'Z'

test/latest-version-extension-test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ describe('latest-version-extension', () => {
145145
expect(refnames).to.eql(['5.6.10'])
146146
})
147147

148+
it('handles hotfixes tags', async () => {
149+
contentAggregate = [createTag('5.6.8.1'), createTag('5.6.8'), createTag('5.6.8.2')]
150+
const refnames = await mapContentAggregateToRefname()
151+
expect(refnames).to.eql(['5.6.8.2'])
152+
})
153+
148154
it('handles tags prefixed with v', async () => {
149155
contentAggregate = [createTag('v6.0.1'), createTag('v6.0.0')]
150156
const refnames = await mapContentAggregateToRefname()
@@ -206,7 +212,7 @@ describe('latest-version-extension', () => {
206212
it('handles invalid version format with proper message', async () => {
207213
contentAggregate = [createTag('6.0.0-M3-m')]
208214
expect(await trapAsyncError(runContentAggregate)).to.throw(
209-
'Cannot parse version = 6.0.0-M3-m with regex /^v?(\\d+)\\.(\\d+)\\.(\\d+)(?:-(RC|M)(\\d+))?$/'
215+
'Cannot parse version = 6.0.0-M3-m with regex /^v?(\\d+)\\.(\\d+)\\.(\\d+)(?:\\.(\\d+))?(?:-(RC|M)(\\d+))?$/'
210216
)
211217
})
212218
})

0 commit comments

Comments
 (0)