@@ -25890,9 +25890,11 @@ const _ = __nccwpck_require__(2356)
2589025890
2589125891const MAX_HTTP_RETRIES = 3
2589225892
25893- main().catch((err) => {
25894- core.setFailed(err.message)
25895- })
25893+ if (process.env.NODE_ENV !== 'test') {
25894+ main().catch((err) => {
25895+ core.setFailed(err.message)
25896+ })
25897+ }
2589625898
2589725899async function main() {
2589825900 checkOtpArchitecture()
@@ -25908,15 +25910,14 @@ async function main() {
2590825910 versions = parseVersionFile(versionFilePath)
2590925911 }
2591025912
25911- const osVersion = getRunnerOSVersion()
2591225913 const otpSpec = getInput('otp-version', true, 'erlang', versions)
2591325914 const elixirSpec = getInput('elixir-version', false, 'elixir', versions)
2591425915 const gleamSpec = getInput('gleam-version', false, 'gleam', versions)
2591525916 const rebar3Spec = getInput('rebar3-version', false, 'rebar', versions)
2591625917
2591725918 if (otpSpec !== 'false') {
25918- await installOTP(otpSpec, osVersion )
25919- const elixirInstalled = await maybeInstallElixir(elixirSpec, otpSpec )
25919+ await installOTP(otpSpec)
25920+ const elixirInstalled = await maybeInstallElixir(elixirSpec)
2592025921 if (elixirInstalled === true) {
2592125922 const shouldMixRebar = getInput('install-rebar', false)
2592225923 await mix(shouldMixRebar, 'rebar')
@@ -25936,7 +25937,8 @@ async function main() {
2593625937 core.setOutput('setup-beam-version', setupBeamVersion)
2593725938}
2593825939
25939- async function installOTP(otpSpec, osVersion) {
25940+ async function installOTP(otpSpec) {
25941+ const osVersion = getRunnerOSVersion()
2594025942 const otpVersion = await getOTPVersion(otpSpec, osVersion)
2594125943 core.startGroup(
2594225944 `Installing Erlang/OTP ${otpVersion} - built on ${getRunnerOSArchitecture()}/${osVersion}`,
@@ -25958,10 +25960,10 @@ async function installOTP(otpSpec, osVersion) {
2595825960 return otpVersion
2595925961}
2596025962
25961- async function maybeInstallElixir(elixirSpec, otpSpec ) {
25963+ async function maybeInstallElixir(elixirSpec) {
2596225964 let installed = false
2596325965 if (elixirSpec) {
25964- const elixirVersion = await getElixirVersion(elixirSpec, otpSpec )
25966+ const elixirVersion = await getElixirVersion(elixirSpec)
2596525967 core.startGroup(`Installing Elixir ${elixirVersion}`)
2596625968 await doWithMirrors({
2596725969 hexMirrors: hexMirrorsInput(),
@@ -26070,16 +26072,30 @@ function requestedVersionFor(tool, version, originListing, mirrors) {
2607026072const knownBranches = ['main', 'master', 'maint']
2607126073const nonSpecificVersions = ['nightly', 'latest']
2607226074
26073- async function getElixirVersion(exSpec0, otpVersion0) {
26074- const otpVersion = otpVersion0.match(/^(?:OTP-)?(.+)$/)[1]
26075- const regex = `^(\\d{1,3}|${knownBranches.join('|')}|${nonSpecificVersions.join('|')})?.*$`
26076- let otpVersionMajor = otpVersion.match(new RegExp(regex))[1]
26077-
26075+ async function getElixirVersion(exSpec0) {
2607826076 const otpSuffix = /-otp-(\d+)/
2607926077 const userSuppliedOtp = exSpec0.match(otpSuffix)?.[1] ?? null
26078+ let otpVersionMajor = ''
2608026079
2608126080 if (userSuppliedOtp && isVersion(userSuppliedOtp)) {
2608226081 otpVersionMajor = userSuppliedOtp
26082+ } else {
26083+ let cmd = 'erl'
26084+ if (process.platform === 'win32') {
26085+ cmd = 'erl.exe'
26086+ }
26087+ const args = [
26088+ '-noshell',
26089+ '-eval',
26090+ 'io:format(erlang:system_info(otp_release)), halt().',
26091+ ]
26092+ await exec(cmd, args, {
26093+ listeners: {
26094+ stdout: (data) => {
26095+ otpVersionMajor = data.toString()
26096+ },
26097+ },
26098+ })
2608326099 }
2608426100
2608526101 const [otpVersionsForElixirMap, elixirVersions, originListing, hexMirrors] =
@@ -26094,17 +26110,29 @@ async function getElixirVersion(exSpec0, otpVersion0) {
2609426110 )
2609526111 }
2609626112
26097- const elixirVersionComp = otpVersionsForElixirMap[elixirVersionFromSpec]
26098- if (
26099- (elixirVersionComp && elixirVersionComp.includes(otpVersionMajor)) ||
26100- !isVersion(otpVersionMajor)
26101- ) {
26102- core.info(
26103- `Using Elixir ${elixirVersionFromSpec} (built for Erlang/OTP ${otpVersionMajor})`,
26104- )
26105- } else {
26113+ let foundCombo = false
26114+ let otpVersionMajorIter = parseInt(otpVersionMajor)
26115+ let otpVersionsMajor = []
26116+ while (otpVersionMajorIter > otpVersionMajor - 3) {
26117+ otpVersionMajorIter += ''
26118+ otpVersionsMajor.push(otpVersionMajorIter)
26119+ const elixirVersionComp = otpVersionsForElixirMap[elixirVersionFromSpec]
26120+ if (
26121+ (elixirVersionComp && elixirVersionComp.includes(otpVersionMajorIter)) ||
26122+ !isVersion(otpVersionMajorIter)
26123+ ) {
26124+ core.info(
26125+ `Using Elixir ${elixirVersionFromSpec} (built for Erlang/OTP ${otpVersionMajorIter})`,
26126+ )
26127+ foundCombo = true
26128+ break
26129+ }
26130+ otpVersionMajorIter = parseInt(otpVersionMajorIter) - 1
26131+ }
26132+
26133+ if (!foundCombo) {
2610626134 throw new Error(
26107- `Requested Elixir / Erlang/OTP version (${exSpec0} / ${otpVersion0 }) not ` +
26135+ `Requested Elixir / Erlang/OTP version (${exSpec0} / tried ${otpVersionsMajor }) not ` +
2610826136 'found in version list (did you check Compatibility between Elixir and Erlang/OTP?).' +
2610926137 'Elixir and Erlang/OTP compatibility can be found at: ' +
2611026138 'https://hexdocs.pm/elixir/compatibility-and-deprecations.html',
@@ -26113,8 +26141,8 @@ async function getElixirVersion(exSpec0, otpVersion0) {
2611326141
2611426142 let elixirVersionForDownload = elixirVersionFromSpec
2611526143
26116- if (isVersion(otpVersionMajor )) {
26117- elixirVersionForDownload = `${elixirVersionFromSpec}-otp-${otpVersionMajor }`
26144+ if (isVersion(otpVersionMajorIter )) {
26145+ elixirVersionForDownload = `${elixirVersionFromSpec}-otp-${otpVersionMajorIter }`
2611826146 }
2611926147
2612026148 return maybePrependWithV(elixirVersionForDownload)
@@ -27073,14 +27101,18 @@ function debugLoggingEnabled() {
2707327101
2707427102module.exports = {
2707527103 get,
27076- getOTPVersion,
2707727104 getElixirVersion,
2707827105 getGleamVersion,
27106+ getOTPVersion,
2707927107 getRebar3Version,
2708027108 getVersionFromSpec,
2708127109 githubAMDRunnerArchs,
2708227110 githubARMRunnerArchs,
2708327111 install,
27112+ installOTP,
27113+ maybeInstallElixir,
27114+ maybeInstallGleam,
27115+ maybeInstallRebar3,
2708427116 parseVersionFile,
2708527117}
2708627118
0 commit comments