Skip to content

Commit 6a38171

Browse files
Test for updated doc. on latest / ranges / -rc (#349)
* Set the expectations * Reason on the past * Also allow for removal of OTP- in comparison to RC * Test it on what makes sense * For known elements don't compare with ranges * Don't put maint-27 alongside 27 in the initial map * Generate the dist * Revisit the whole latest vs. rc- vs. strict definition
1 parent 75edbb8 commit 6a38171

File tree

4 files changed

+65
-17
lines changed

4 files changed

+65
-17
lines changed

README.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,25 @@ end up being parsed as `23`, which is not equivalent.
5353

5454
#### Pre-release versions
5555

56-
For pre-release versions, such as `v1.11.0-rc.0`, use the full version
57-
specifier (`v1.11.0-rc.0`) and set option `version-type` to `strict`. Pre-release versions are
58-
opt-in, so `1.11.x` will not match a pre-release.
56+
To use a pre-release version such as `v1.11.0-rc.0`, specify the exact version
57+
(`v1.11.0-rc.0`) and set `version-type` to `strict`.
58+
Note that pre-release versions are opt-in by default.
59+
Patterns like `1.11.x` do not include pre-release versions unless `latest` is specified.
5960

6061
#### "Latest" versions
6162

62-
Set a tool's version to `latest` to retrieve the latest version of a given tool.
63-
The latest version is (locally) calculated by the action based on the (retrieved) versions
64-
it knows (**note**: it is not the same as [GitHub considers it](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository)
65-
and some repositories might propose).
63+
To retrieve the most recent available version of a tool, set the version to `latest`.
64+
This may include pre-release versions such as release candidates.
6665

67-
If in doubt do a test run and compare the obtained release with the one you were expecting to
68-
be the latest.
66+
If you want to target only the latest stable release and exclude pre-releases, use a
67+
version range like `> 0` instead.
68+
69+
Note that the `latest` version is determined locally by the action based on the versions it
70+
has retrieved. This may differ from how [GitHub defines "latest"](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository),
71+
and some repositories may present different interpretations.
72+
73+
If you're unsure, perform a test run and compare the resolved version against the version you
74+
expect to be considered the latest.
6975

7076
### Compatibility between Operating System and Erlang/OTP
7177

dist/index.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26323,6 +26323,7 @@ function validVersion(v) {
2632326323
v.match(
2632426324
new RegExp(`${knownBranches.join('|')}|${nonSpecificVersions.join('|')}`),
2632526325
) == null &&
26326+
// these ones are for rebar3, which has alpha and beta releases
2632626327
!v.startsWith('a') &&
2632726328
!v.startsWith('b')
2632826329
)
@@ -26349,7 +26350,12 @@ function getVersionFromSpec(spec0, versions0) {
2634926350
const altVersions = {}
2635026351
Object.entries(versions0).forEach(([version, altVersion]) => {
2635126352
let coerced
26352-
if (isStrictVersion() || isRC(version)) {
26353+
if (
26354+
isStrictVersion() ||
26355+
isRC(version) ||
26356+
isKnownBranch(version) ||
26357+
isKnownVerBranch(version)
26358+
) {
2635326359
// If `version-type: strict` or version is RC, we just try to remove a potential initial v
2635426360
coerced = maybeRemoveVPrefix(version)
2635526361
} else {
@@ -26367,9 +26373,14 @@ function getVersionFromSpec(spec0, versions0) {
2636726373
const rangeMax = semver.maxSatisfying(versions, rangeForMax)
2636826374
let version = null
2636926375

26370-
if (isStrictVersion() || isRC(spec0) || isKnownBranch(spec0)) {
26376+
if (
26377+
isStrictVersion() ||
26378+
isRC(spec0) ||
26379+
isKnownBranch(spec0) ||
26380+
isKnownVerBranch(spec0)
26381+
) {
2637126382
if (versions0[spec]) {
26372-
// If `version-type: strict` or version is RC, we obtain it directly
26383+
// We obtain it directly
2637326384
version = versions0[spec]
2637426385
}
2637526386
} else if (spec0 === 'latest') {
@@ -26592,7 +26603,7 @@ function xyzAbcVersion(pref, suf) {
2659226603
// https://www.erlang.org/doc/system_principles/versions.html
2659326604
const dd = '\\.?(\\d+)?'
2659426605
return new RegExp(
26595-
`${pref}v?(\\d+)${dd}${dd}${dd}${dd}${dd}(?:-rc\\.?\\d+)?(?:-otp-\\d+)?${suf}`,
26606+
`${pref}(?:OTP-)?v?(\\d+)${dd}${dd}${dd}${dd}${dd}(?:-rc\\.?\\d+)?(?:-otp-\\d+)?${suf}`,
2659626607
)
2659726608
}
2659826609

src/setup-beam.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ function validVersion(v) {
448448
v.match(
449449
new RegExp(`${knownBranches.join('|')}|${nonSpecificVersions.join('|')}`),
450450
) == null &&
451+
// these ones are for rebar3, which has alpha and beta releases
451452
!v.startsWith('a') &&
452453
!v.startsWith('b')
453454
)
@@ -474,7 +475,12 @@ function getVersionFromSpec(spec0, versions0) {
474475
const altVersions = {}
475476
Object.entries(versions0).forEach(([version, altVersion]) => {
476477
let coerced
477-
if (isStrictVersion() || isRC(version)) {
478+
if (
479+
isStrictVersion() ||
480+
isRC(version) ||
481+
isKnownBranch(version) ||
482+
isKnownVerBranch(version)
483+
) {
478484
// If `version-type: strict` or version is RC, we just try to remove a potential initial v
479485
coerced = maybeRemoveVPrefix(version)
480486
} else {
@@ -492,9 +498,14 @@ function getVersionFromSpec(spec0, versions0) {
492498
const rangeMax = semver.maxSatisfying(versions, rangeForMax)
493499
let version = null
494500

495-
if (isStrictVersion() || isRC(spec0) || isKnownBranch(spec0)) {
501+
if (
502+
isStrictVersion() ||
503+
isRC(spec0) ||
504+
isKnownBranch(spec0) ||
505+
isKnownVerBranch(spec0)
506+
) {
496507
if (versions0[spec]) {
497-
// If `version-type: strict` or version is RC, we obtain it directly
508+
// We obtain it directly
498509
version = versions0[spec]
499510
}
500511
} else if (spec0 === 'latest') {
@@ -717,7 +728,7 @@ function xyzAbcVersion(pref, suf) {
717728
// https://www.erlang.org/doc/system_principles/versions.html
718729
const dd = '\\.?(\\d+)?'
719730
return new RegExp(
720-
`${pref}v?(\\d+)${dd}${dd}${dd}${dd}${dd}(?:-rc\\.?\\d+)?(?:-otp-\\d+)?${suf}`,
731+
`${pref}(?:OTP-)?v?(\\d+)${dd}${dd}${dd}${dd}${dd}(?:-rc\\.?\\d+)?(?:-otp-\\d+)?${suf}`,
721732
)
722733
}
723734

test/setup-beam.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,11 +875,31 @@ describe('.getVersionFromSpec(_)', () => {
875875
got = setupBeam.getVersionFromSpec(spec, matrix.otp['ubuntu-20.04'])
876876
assert.deepStrictEqual(got, expected)
877877

878+
spec = 'maint-24'
879+
expected = 'maint-24'
880+
got = setupBeam.getVersionFromSpec(spec, matrix.otp['ubuntu-22.04'])
881+
assert.deepStrictEqual(got, expected)
882+
883+
spec = '> 0'
884+
expected = 'OTP-26.2.5'
885+
got = setupBeam.getVersionFromSpec(spec, matrix.otp['ubuntu-22.04'])
886+
assert.deepStrictEqual(got, expected)
887+
878888
spec = 'latest'
879889
expected = 'OTP-27.0-rc3'
880890
got = setupBeam.getVersionFromSpec(spec, matrix.otp['ubuntu-22.04'])
881891
assert.deepStrictEqual(got, expected)
882892

893+
spec = 'maint-26'
894+
expected = 'maint-26'
895+
got = setupBeam.getVersionFromSpec(spec, matrix.otp['ubuntu-22.04'])
896+
assert.deepStrictEqual(got, expected)
897+
898+
spec = '> 0'
899+
expected = 'OTP-27.0'
900+
got = setupBeam.getVersionFromSpec(spec, matrix.otp['ubuntu-24.04'])
901+
assert.deepStrictEqual(got, expected)
902+
883903
spec = 'latest'
884904
expected = 'OTP-27.0'
885905
got = setupBeam.getVersionFromSpec(spec, matrix.otp['ubuntu-24.04'])

0 commit comments

Comments
 (0)