Add support for latest release (#269)

This commit is contained in:
Benjamin Schultzer
2024-06-15 11:18:03 -04:00
committed by GitHub
parent 9ac0f7c54b
commit 6ed3c523c4
14 changed files with 85158 additions and 833 deletions
+114 -4
View File
@@ -14,6 +14,48 @@ const core = require('@actions/core')
const setupBeam = require('../src/setup-beam')
const { problemMatcher } = require('../matchers/elixir-matchers.json')
const matrix = {
otp: {
'ubuntu-18.04': parseBuild('test/otp/ubuntu-18.04/builds.txt'),
'ubuntu-20.04': parseBuild('test/otp/ubuntu-20.04/builds.txt'),
'ubuntu-22.04': parseBuild('test/otp/ubuntu-22.04/builds.txt'),
'ubuntu-24.04': parseBuild('test/otp/ubuntu-24.04/builds.txt'),
windows: parseReleases('test/otp/releases.json'),
},
elixir: parseBuild('test/elixir/builds.txt'),
gleam: parseReleases('test/gleam/releases.json'),
rebar3: parseReleases('test/rebar3/releases.json'),
}
function parseBuild(version) {
let versions = {}
fs.readFileSync(path.join(process.cwd(), version), 'utf8')
.trim()
.split('\n')
.forEach((line) => (versions[line.split(' ')[0]] = line.split(' ')[0]))
return versions
}
function parseReleases(version) {
let versions = {}
let data = fs.readFileSync(path.join(process.cwd(), version), 'utf8')
let json = JSON.parse(data)
if (version.includes('otp')) {
json
.map((x) => x.assets)
.flat()
.filter((x) => x.name.match(/^otp_win64_.*.exe$/))
.forEach((x) => {
let v = x.name.match(/^otp_win64_(.*).exe$/)[1]
versions[v] = v
})
return versions
} else {
json.map((x) => (versions[x.tag_name] = x.tag_name))
return versions
}
}
async function all() {
await testFailInstallOTP()
await testFailInstallElixir()
@@ -302,7 +344,6 @@ async function testElixirVersions() {
got = await setupBeam.getElixirVersion(spec, otpVersion)
assert.deepStrictEqual(got, expected)
simulateInput('version-type', before)
simulateInput('hexpm-mirrors', hexMirrors, { multiline: true })
}
@@ -395,7 +436,7 @@ async function testGetVersionFromSpec() {
'12.1.2.3',
'12.1.2.3.0',
]
const versions = {}
let versions = {}
versions0.forEach((version) => {
versions[version] = version
})
@@ -526,6 +567,76 @@ async function testGetVersionFromSpec() {
got = setupBeam.getVersionFromSpec(spec, versions)
assert.deepStrictEqual(got, expected)
simulateInput('version-type', before)
spec = 'latest'
expected = '24.0'
got = setupBeam.getVersionFromSpec(spec, versions)
assert.deepStrictEqual(got, expected)
versions = {
'27.0.0-rc3': '27.0.0-rc3',
'27.0.0-rc2': '27.0.0-rc2',
}
spec = 'latest'
expected = '27.0.0-rc3'
got = setupBeam.getVersionFromSpec(spec, versions)
assert.deepStrictEqual(got, expected)
versions = {
'27.0.0-rc3': '27.0.0-rc3',
'27.0.0-rc2': '27.0.0-rc2',
'27.0.0': '27.0.0',
}
spec = 'latest'
expected = '27.0.0'
got = setupBeam.getVersionFromSpec(spec, versions)
assert.deepStrictEqual(got, expected)
versions = { '25.3.2.8': '25.3.2.8', '25.3.2.12': '25.3.2.12' }
spec = 'latest'
expected = '25.3.2.12'
got = setupBeam.getVersionFromSpec(spec, versions)
assert.deepStrictEqual(got, expected)
spec = 'latest'
expected = 'OTP-26.2.1'
got = setupBeam.getVersionFromSpec(spec, matrix.otp['ubuntu-18.04'])
assert.deepStrictEqual(got, expected)
spec = 'latest'
expected = 'OTP-27.0-rc3'
got = setupBeam.getVersionFromSpec(spec, matrix.otp['ubuntu-20.04'])
assert.deepStrictEqual(got, expected)
spec = 'latest'
expected = 'OTP-27.0-rc3'
got = setupBeam.getVersionFromSpec(spec, matrix.otp['ubuntu-22.04'])
assert.deepStrictEqual(got, expected)
spec = 'latest'
expected = 'OTP-27.0'
got = setupBeam.getVersionFromSpec(spec, matrix.otp['ubuntu-24.04'])
assert.deepStrictEqual(got, expected)
spec = 'latest'
expected = '27.0-rc3'
got = setupBeam.getVersionFromSpec(spec, matrix.otp.windows)
assert.deepStrictEqual(got, expected)
spec = 'latest'
expected = 'v1.16.2'
got = setupBeam.getVersionFromSpec(spec, matrix.elixir)
assert.deepStrictEqual(got, expected)
spec = 'latest'
expected = 'v1.1.0'
got = setupBeam.getVersionFromSpec(spec, matrix.gleam)
assert.deepStrictEqual(got, expected)
spec = 'latest'
expected = '3.23.0'
got = setupBeam.getVersionFromSpec(spec, matrix.rebar3)
assert.deepStrictEqual(got, expected)
}
async function testParseVersionFile() {
@@ -542,8 +653,7 @@ async function testParseVersionFile() {
erlang ref:v${erlang}# comment, no space, and ref:v
elixir ref:${elixir} # comment, with space and ref:
not-gleam 0.23 # not picked up
gleam ${gleam}
rebar ${rebar3}`
gleam ${gleam} \nrebar ${rebar3}`
const filename = 'test/.tool-versions'
fs.writeFileSync(filename, toolVersions)
process.env.GITHUB_WORKSPACE = ''