8000 Fix calculating `-otp-` major for Elixir by paulo-ferraz-oliveira · Pull Request #351 · erlef/setup-beam · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix calculating -otp- major for Elixir #351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ jobs:
uses: ./
with:
install-rebar: false
install-hex: false
version-file: test/.tool-versions
version-type: strict

Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ jobs:
fail-fast: false
matrix:
combo:
- otp-version: '<26'
elixir-version: '<1.17'
os: 'ubuntu-22.04'
- otp-version: 'master'
elixir-version: '> 0'
os: 'ubuntu-24.04'
- otp-version: 'master'
elixir-version: 'main'
os: 'ubuntu-24.04'
- otp-version: '27'
elixir-version: 'v1.17.0'
rebar3-version: '3.23'
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ jobs:
fail-fast: false
matrix:
combo:
- otp-version: '<26'
elixir-version: '<1.17'
os: 'ubuntu-22.04'
- otp-version: 'master'
elixir-version: '> 0'
os: 'ubuntu-24.04'
- otp-version: '27'
elixir-version: 'v1.17.0'
rebar3-version: '3.23'
Expand Down
86 changes: 59 additions & 27 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25890,9 +25890,11 @@ const _ = __nccwpck_require__(2356)

const MAX_HTTP_RETRIES = 3

main().catch((err) => {
core.setFailed(err.message)
})
if (process.env.NODE_ENV !== 'test') {
main().catch((err) => {
core.setFailed(err.message)
})
}

async function main() {
checkOtpArchitecture()
Expand All @@ -25908,15 +25910,14 @@ async function main() {
versions = parseVersionFile(versionFilePath)
}

const osVersion = getRunnerOSVersion()
const otpSpec = getInput('otp-version', true, 'erlang', versions)
const elixirSpec = getInput('elixir-version', false, 'elixir', versions)
const gleamSpec = getInput('gleam-version', false, 'gleam', versions)
const rebar3Spec = getInput('rebar3-version', false, 'rebar', versions)

if (otpSpec !== 'false') {
await installOTP(otpSpec, osVersion)
const elixirInstalled = await maybeInstallElixir(elixirSpec, otpSpec)
await installOTP(otpSpec)
const elixirInstalled = await maybeInstallElixir(elixirSpec)
if (elixirInstalled === true) {
const shouldMixRebar = getInput('install-rebar', false)
await mix(shouldMixRebar, 'rebar')
Expand All @@ -25936,7 +25937,8 @@ async function main() {
core.setOutput('setup-beam-version', setupBeamVersion)
}

async function installOTP(otpSpec, osVersion) {
async function installOTP(otpSpec) {
const osVersion = getRunnerOSVersion()
const otpVersion = await getOTPVersion(otpSpec, osVersion)
core.startGroup(
`Installing Erlang/OTP ${otpVersion} - built on ${getRunnerOSArchitecture()}/${osVersion}`,
Expand All @@ -25958,10 +25960,10 @@ async function installOTP(otpSpec, osVersion) {
return otpVersion
}

async function maybeInstallElixir(elixirSpec, otpSpec) {
async function maybeInstallElixir(elixirSpec) {
let installed = false
if (elixirSpec) {
const elixirVersion = await getElixirVersion(elixirSpec, otpSpec)
const elixirVersion = await getElixirVersion(elixirSpec)
core.startGroup(`Installing Elixir ${elixirVersion}`)
await doWithMirrors({
hexMirrors: hexMirrorsInput(),
Expand Down Expand Up @@ -26070,16 +26072,30 @@ function requestedVersionFor(tool, version, originListing, mirrors) {
const knownBranches = ['main', 'master', 'maint']
const nonSpecificVersions = ['nightly', 'latest']

async function getElixirVersion(exSpec0, otpVersion0) {
const otpVersion = otpVersion0.match(/^(?:OTP-)?(.+)$/)[1]
const regex = `^(\\d{1,3}|${knownBranches.join('|')}|${nonSpecificVersions.join('|')})?.*$`
let otpVersionMajor = otpVersion.match(new RegExp(regex))[1]

async function getElixirVersion(exSpec0) {
const otpSuffix = /-otp-(\d+)/
const userSuppliedOtp = exSpec0.match(otpSuffix)?.[1] ?? null
let otpVersionMajor = ''

if (userSuppliedOtp && isVersion(userSuppliedOtp)) {
otpVersionMajor = userSuppliedOtp
} else {
let cmd = 'erl'
if (process.platform === 'win32') {
cmd = 'erl.exe'
}
const args = [
'-noshell',
'-eval',
'io:format(erlang:system_info(otp_release)), halt().',
]
await exec(cmd, args, {
listeners: {
stdout: (data) => {
otpVersionMajor = data.toString()
},
},
})
}

const [otpVersionsForElixirMap, elixirVersions, originListing, hexMirrors] =
Expand All @@ -26094,17 +26110,29 @@ async function getElixirVersion(exSpec0, otpVersion0) {
)
}

const elixirVersionComp = otpVersionsForElixirMap[elixirVersionFromSpec]
if (
(elixirVersionComp && elixirVersionComp.includes(otpVersionMajor)) ||
!isVersion(otpVersionMajor)
) {
core.info(
`Using Elixir ${elixirVersionFromSpec} (built for Erlang/OTP ${otpVersionMajor})`,
)
} else {
let foundCombo = false
let otpVersionMajorIter = parseInt(otpVersionMajor)
let otpVersionsMajor = []
while (otpVersionMajorIter > otpVersionMajor - 3) {
otpVersionMajorIter += ''
otpVersionsMajor.push(otpVersionMajorIter)
const elixirVersionComp = otpVersionsForElixirMap[elixirVersionFromSpec]
if (
(elixirVersionComp && elixirVersionComp.includes(otpVersionMajorIter)) ||
!isVersion(otpVersionMajorIter)
) {
core.info(
`Using Elixir ${elixirVersionFromSpec} (built for Erlang/OTP ${otpVersionMajorIter})`,
)
foundCombo = true
break
}
otpVersionMajorIter = parseInt(otpVersionMajorIter) - 1
}

if (!foundCombo) {
throw new Error(
`Requested Elixir / Erlang/OTP version (${exSpec0} / ${otpVersion0}) not ` +
`Requested Elixir / Erlang/OTP version (${exSpec0} / tried ${otpVersionsMajor}) not ` +
'found in version list (did you check Compatibility between Elixir and Erlang/OTP?).' +
'Elixir and Erlang/OTP compatibility can be found at: ' +
'https://hexdocs.pm/elixir/compatibility-and-deprecations.html',
Expand All @@ -26113,8 +26141,8 @@ async function getElixirVersion(exSpec0, otpVersion0) {

let elixirVersionForDownload = elixirVersionFromSpec

if (isVersion(otpVersionMajor)) {
elixirVersionForDownload = `${elixirVersionFromSpec}-otp-${otpVersionMajor}`
if (isVersion(otpVersionMajorIter)) {
elixirVersionForDownload = `${elixirVersionFromSpec}-otp-${otpVersionMajorIter}`
}

return maybePrependWithV(elixirVersionForDownload)
Expand Down Expand Up @@ -27073,14 +27101,18 @@ function debugLoggingEnabled() {

module.exports = {
get,
getOTPVersion,
getElixirVersion,
getGleamVersion,
getOTPVersion,
getRebar3Version,
getVersionFromSpec,
githubAMDRunnerArchs,
githubARMRunnerArchs,
install,
installOTP,
maybeInstallElixir,
maybeInstallGleam,
maybeInstallRebar3,
parseVersionFile,
}

Expand Down
86 changes: 59 additions & 27 deletions src/setup-beam.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ const _ = require('lodash')

const MAX_HTTP_RETRIES = 3

main().catch((err) => {
core.setFailed(err.message)
})
if (process.env.NODE_ENV !== 'test') {
main().catch((err) => {
core.setFailed(err.message)
})
}

async function main() {
checkOtpArchitecture()
Expand All @@ -28,15 +30,14 @@ async function main() {
versions = parseVersionFile(versionFilePath)
}

const osVersion = getRunnerOSVersion()
const otpSpec = getInput('otp-version', true, 'erlang', versions)
const elixirSpec = getInput('elixir-version', false, 'elixir', versions)
const gleamSpec = getInput('gleam-version', false, 'gleam', versions)
const rebar3Spec = getInput('rebar3-version', false, 'rebar', versions)

if (otpSpec !== 'false') {
await installOTP(otpSpec, osVersion)
const elixirInstalled = await maybeInstallElixir(elixirSpec, otpSpec)
await installOTP(otpSpec)
const elixirInstalled = await maybeInstallElixir(elixirSpec)
if (elixirInstalled === true) {
const shouldMixRebar = getInput('install-rebar', false)
await mix(shouldMixRebar, 'rebar')
Expand All @@ -56,7 +57,8 @@ async function main() {
core.setOutput('setup-beam-version', setupBeamVersion)
}

async function installOTP(otpSpec, osVersion) {
async function installOTP(otpSpec) {
const osVersion = getRunnerOSVersion()
const otpVersion = await getOTPVersion(otpSpec, osVersion)
core.startGroup(
`Installing Erlang/OTP ${otpVersion} - built on ${getRunnerOSArchitecture()}/${osVersion}`,
Expand All @@ -78,10 +80,10 @@ async function installOTP(otpSpec, osVersion) {
return otpVersion
}

async function maybeInstallElixir(elixirSpec, otpSpec) {
async function maybeInstallElixir(elixirSpec) {
let installed = false
if (elixirSpec) {
const elixirVersion = await getElixirVersion(elixirSpec, otpSpec)
const elixirVersion = await getElixirVersion(elixirSpec)
core.startGroup(`Installing Elixir ${elixirVersion}`)
await doWithMirrors({
hexMirrors: hexMirrorsInput(),
Expand Down Expand Up @@ -195,16 +197,30 @@ function requestedVersionFor(tool, version, originListing, mirrors) {
const knownBranches = ['main', 'master', 'maint']
const nonSpecificVersions = ['nightly', 'latest']

async function getElixirVersion(exSpec0, otpVersion0) {
const otpVersion = otpVersion0.match(/^(?:OTP-)?(.+)$/)[1]
const regex = `^(\\d{1,3}|${knownBranches.join('|')}|${nonSpecificVersions.join('|')})?.*$`
let otpVersionMajor = otpVersion.match(new RegExp(regex))[1]

async function getElixirVersion(exSpec0) {
const otpSuffix = /-otp-(\d+)/
const userSuppliedOtp = exSpec0.match(otpSuffix)?.[1] ?? null
let otpVersionMajor = ''

if (userSuppliedOtp && isVersion(userSuppliedOtp)) {
otpVersionMajor = userSuppliedOtp
} else {
let cmd = 'erl'
if (process.platform === 'win32') {
cmd = 'erl.exe'
}
const args = [
'-noshell',
'-eval',
'io:format(erlang:system_info(otp_release)), halt().',
]
await exec(cmd, args, {
listeners: {
stdout: (data) => {
otpVersionMajor = data.toString()
},
},
})
}

const [otpVersionsForElixirMap, elixirVersions, originListing, hexMirrors] =
Expand All @@ -219,17 +235,29 @@ async function getElixirVersion(exSpec0, otpVersion0) {
)
}

const elixirVersionComp = otpVersionsForElixirMap[elixirVersionFromSpec]
if (
(elixirVersionComp && elixirVersionComp.includes(otpVersionMajor)) ||
!isVersion(otpVersionMajor)
) {
core.info(
`Using Elixir ${elixirVersionFromSpec} (built for Erlang/OTP ${otpVersionMajor})`,
)
} else {
let foundCombo = false
let otpVersionMajorIter = parseInt(otpVersionMajor)
let otpVersionsMajor = []
while (otpVersionMajorIter > otpVersionMajor - 3) {
otpVersionMajorIter += ''
otpVersionsMajor.push(otpVersionMajorIter)
const elixirVersionComp = otpVersionsForElixirMap[elixirVersionFromSpec]
if (
(elixirVersionComp && elixirVersionComp.includes(otpVersionMajorIter)) ||
!isVersion(otpVersionMajorIter)
) {
core.info(
`Using Elixir ${elixirVersionFromSpec} (built for Erlang/OTP ${otpVersionMajorIter})`,
)
foundCombo = true
break
}
otpVersionMajorIter = parseInt(otpVersionMajorIter) - 1
}

if (!foundCombo) {
throw new Error(
`Requested Elixir / Erlang/OTP version (${exSpec0} / ${otpVersion0}) not ` +
`Requested Elixir / Erlang/OTP version (${exSpec0} / tried ${otpVersionsMajor}) not ` +
'found in version list (did you check Compatibility between Elixir and Erlang/OTP?).' +
'Elixir and Erlang/OTP compatibility can be found at: ' +
'https://hexdocs.pm/elixir/compatibility-and-deprecations.html',
Expand All @@ -238,8 +266,8 @@ async function getElixirVersion(exSpec0, otpVersion0) {

let elixirVersionForDownload = elixirVersionFromSpec

if (isVersion(otpVersionMajor)) {
elixirVersionForDownload = `${elixirVersionFromSpec}-otp-${otpVersionMajor}`
if (isVersion(otpVersionMajorIter)) {
elixirVersionForDownload = `${elixirVersionFromSpec}-otp-${otpVersionMajorIter}`
}

return maybePrependWithV(elixirVersionForDownload)
Expand Down Expand Up @@ -1198,13 +1226,17 @@ function debugLoggingEnabled() {

module.exports = {
get,
getOTPVersion,
getElixirVersion,
getGleamVersion,
getOTPVersion,
getRebar3Version,
getVersionFromSpec,
githubAMDRunnerArchs,
githubARMRunnerArchs,
install,
installOTP,
maybeInstallElixir,
maybeInstallGleam,
maybeInstallRebar3,
parseVersionFile,
}
Loading
0