Skip to content

Commit b676b81

Browse files
Handle strict, rc, known or known-ver the same way
1. when obtaining for the list 2. when comparing as input 3. when comparing to input (range)
1 parent 1d7ca11 commit b676b81

File tree

3 files changed

+45
-46
lines changed

3 files changed

+45
-46
lines changed

dist/index.js

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26336,6 +26336,15 @@ function parseVersion(v) {
2633626336
return semver.coerce(v, { includePrerelease: true, loose: true })
2633726337
}
2633826338

26339+
function isStrictRCOrKnown(spec) {
26340+
return (
26341+
isStrictVersion() ||
26342+
isRC(spec) ||
26343+
isKnownBranch(spec) ||
26344+
isKnownVerBranch(spec)
26345+
)
26346+
}
26347+
2633926348
function getVersionFromSpec(spec0, versions0) {
2634026349
let latest
2634126350
Object.keys(versions0).forEach((v) => {
@@ -26349,17 +26358,8 @@ function getVersionFromSpec(spec0, versions0) {
2634926358
const altVersions = {}
2635026359
Object.entries(versions0).forEach(([version, altVersion]) => {
2635126360
let coerced
26352-
if (
26353-
isStrictVersion() ||
26354-
isRC(version) ||
26355-
isKnownBranch(spec0) ||
26356-
isKnownVerBranch(spec0)
26357-
) {
26358-
// If
26359-
// - `version-type: strict`, or
26360-
// - version is RC, or
26361-
// - version is from a known branch,
26362-
// we just try to remove a potential initial v
26361+
if (isStrictRCOrKnown(spec)) {
26362+
// We just try to remove a potential initial v
2636326363
coerced = maybeRemoveVPrefix(version)
2636426364
} else {
2636526365
// Otherwise, we place the version into a version bucket
@@ -26376,18 +26376,9 @@ function getVersionFromSpec(spec0, versions0) {
2637626376
const rangeMax = semver.maxSatisfying(versions, rangeForMax)
2637726377
let version = null
2637826378

26379-
if (
26380-
isStrictVersion() ||
26381-
isRC(spec0) ||
26382-
isKnownBranch(spec0) ||
26383-
isKnownVerBranch(spec0)
26384-
) {
26379+
if (isStrictRCOrKnown(spec)) {
2638526380
if (versions0[spec]) {
26386-
// If
26387-
// - `version-type: strict`, or
26388-
// - version is RC, or
26389-
// - version is from a known branch,
26390-
// we obtain it directly
26381+
// We obtain it directly
2639126382
version = versions0[spec]
2639226383
}
2639326384
} else if (spec0 === 'latest') {
@@ -26396,10 +26387,16 @@ function getVersionFromSpec(spec0, versions0) {
2639626387
// Otherwise, we compare alt. versions' semver ranges to this version, from highest to lowest
2639726388
const thatVersion = spec
2639826389
const thatVersionAbc = versionAbc(thatVersion)
26399-
const thatVersionAbcRange = semver.validRange(thatVersionAbc)
26390+
const thatVersionAbcRange = thatVersionAbc
26391+
? undefined
26392+
: semver.validRange(thatVersionAbc)
2640026393

2640126394
versions = altVersions[rangeMax]
2640226395
for (let i = versions.length - 1; i >= 0; i -= 1) {
26396+
if (isStrictRCOrKnown(spec)) {
26397+
// We move on, skipping this version for comparison
26398+
continue
26399+
}
2640326400
const thisVersion = versions[i]
2640426401
const thisVersionAbc = versionAbc(thisVersion)
2640526402
const thisVersionAbcRange = semver.validRange(thisVersionAbc)

src/setup-beam.js

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,15 @@ function parseVersion(v) {
461461
return semver.coerce(v, { includePrerelease: true, loose: true })
462462
}
463463

464+
function isStrictRCOrKnown(spec) {
465+
return (
466+
isStrictVersion() ||
467+
isRC(spec) ||
468+
isKnownBranch(spec) ||
469+
isKnownVerBranch(spec)
470+
)
471+
}
472+
464473
function getVersionFromSpec(spec0, versions0) {
465474
let latest
466475
Object.keys(versions0).forEach((v) => {
@@ -474,17 +483,8 @@ function getVersionFromSpec(spec0, versions0) {
474483
const altVersions = {}
475484
Object.entries(versions0).forEach(([version, altVersion]) => {
476485
let coerced
477-
if (
478-
isStrictVersion() ||
479-
isRC(version) ||
480-
isKnownBranch(spec0) ||
481-
isKnownVerBranch(spec0)
482-
) {
483-
// If
484-
// - `version-type: strict`, or
485-
// - version is RC, or
486-
// - version is from a known branch,
487-
// we just try to remove a potential initial v
486+
if (isStrictRCOrKnown(spec)) {
487+
// We just try to remove a potential initial v
488488
coerced = maybeRemoveVPrefix(version)
489489
} else {
490490
// Otherwise, we place the version into a version bucket
@@ -501,18 +501,9 @@ function getVersionFromSpec(spec0, versions0) {
501501
const rangeMax = semver.maxSatisfying(versions, rangeForMax)
502502
let version = null
503503

504-
if (
505-
isStrictVersion() ||
506-
isRC(spec0) ||
507-
isKnownBranch(spec0) ||
508-
isKnownVerBranch(spec0)
509-
) {
504+
if (isStrictRCOrKnown(spec)) {
510505
if (versions0[spec]) {
511-
// If
512-
// - `version-type: strict`, or
513-
// - version is RC, or
514-
// - version is from a known branch,
515-
// we obtain it directly
506+
// We obtain it directly
516507
version = versions0[spec]
517508
}
518509
} else if (spec0 === 'latest') {
@@ -521,10 +512,16 @@ function getVersionFromSpec(spec0, versions0) {
521512
// Otherwise, we compare alt. versions' semver ranges to this version, from highest to lowest
522513
const thatVersion = spec
523514
const thatVersionAbc = versionAbc(thatVersion)
524-
const thatVersionAbcRange = semver.validRange(thatVersionAbc)
515+
const thatVersionAbcRange = thatVersionAbc
516+
? undefined
517+
: semver.validRange(thatVersionAbc)
525518

526519
versions = altVersions[rangeMax]
527520
for (let i = versions.length - 1; i >= 0; i -= 1) {
521+
if (isStrictRCOrKnown(spec)) {
522+
// We move on, skipping this version for comparison
523+
continue
524+
}
528525
const thisVersion = versions[i]
529526
const thisVersionAbc = versionAbc(thisVersion)
530527
const thisVersionAbcRange = semver.validRange(thisVersionAbc)

test/setup-beam.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,11 @@ describe('.getVersionFromSpec(_)', () => {
885885
got = setupBeam.getVersionFromSpec(spec, matrix.otp['ubuntu-24.04'])
886886
assert.deepStrictEqual(got, expected)
887887

888+
spec = 'maint-27'
889+
expected = 'maint-27'
890+
got = setupBeam.getVersionFromSpec(spec, matrix.otp['ubuntu-24.04'])
891+
assert.deepStrictEqual(got, expected)
892+
888893
// range > 0 excludes -rc...
889894
spec = '> 0'
890895
expected = 'OTP-27.0'

0 commit comments

Comments
 (0)