From 71a9eee041935c78a267f96a76ee9121d15b06a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Meadows-J=C3=B6nsson?= Date: Sun, 17 Nov 2019 23:40:55 +0100 Subject: [PATCH] Support elixir branches --- .github/workflows/test.yml | 3 +++ src/install-elixir | 6 +++--- src/installer.js | 3 ++- src/setup-elixir.js | 34 ++++++++++++++++++++++------------ 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2bb4c25..f09163b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,6 +18,9 @@ jobs: # Semver ranges - otp-version: 21.x elixir-version: <1.9.1 + # Branches + - otp-version: 22.0 + elixir-version: master steps: - uses: actions/checkout@v1.0.0 - name: Use actions/setup-elixir diff --git a/src/install-elixir b/src/install-elixir index f767922..8fc616c 100755 --- a/src/install-elixir +++ b/src/install-elixir @@ -2,7 +2,7 @@ set -eo pipefail -wget -q https://repo.hex.pm/builds/elixir/v${1}-otp-${2}.zip -unzip -d .setup-elixir/elixir v${1}-otp-${2}.zip -rm v${1}-otp-${2}.zip +wget -q https://repo.hex.pm/builds/elixir/${1}${2}.zip +unzip -d .setup-elixir/elixir ${1}${2}.zip +rm ${1}${2}.zip echo "::add-path::$(pwd)/.setup-elixir/elixir/bin" diff --git a/src/installer.js b/src/installer.js index 9b2bc51..7a55dbf 100644 --- a/src/installer.js +++ b/src/installer.js @@ -12,7 +12,8 @@ module.exports = {installElixir, installOTP} */ async function installElixir(version, otpMajor) { if (process.platform === 'linux') { - await exec(path.join(__dirname, 'install-elixir'), [version, otpMajor]) + const otpString = otpMajor ? `-otp-${otpMajor}` : '' + await exec(path.join(__dirname, 'install-elixir'), [version, otpString]) } } diff --git a/src/setup-elixir.js b/src/setup-elixir.js index ba85c13..24e0b68 100644 --- a/src/setup-elixir.js +++ b/src/setup-elixir.js @@ -14,8 +14,8 @@ async function main() { const otpSpec = core.getInput('otp-version', {required: true}) const elixirSpec = core.getInput('elixir-version', {required: true}) - const otpVersion = getVersionFromSpec(otpSpec, await getOtpVersions()) - const [elixirVersion, otpMajor] = getElixirVersion(elixirSpec, await getElixirVersions(), otpVersion) + const otpVersion = await getOtpVersion(otpSpec) + const [elixirVersion, otpMajor] = await getElixirVersion(elixirSpec, otpVersion) let installHex = core.getInput('install-hex') installHex = installHex == null ? true : installHex @@ -42,23 +42,33 @@ function checkPlatform() { ) } -function getElixirVersion(spec, versions, otpVersion) { - const version = getVersionFromSpec(spec, Array.from(versions.keys())) +async function getOtpVersion(spec) { + return getVersionFromSpec(spec, await getOtpVersions()) || spec +} + +async function getElixirVersion(spec, otpVersion) { + const versions = await getElixirVersions() + const semverRegex = /^v(\d+\.\d+\.\d+)/ + + const semverVersions = + Array.from(versions.keys()) + .filter(str => str.match(semverRegex)) + .map(str => str.match(semverRegex)[1]) + + const version = getVersionFromSpec(spec, semverVersions) + const gitRef = version ? `v${version}` : spec const [otpMajor] = otpVersion.match(/^\d+/) - if (versions.get(version).includes(otpMajor)) { - return [version, otpMajor] + if (versions.get(gitRef).includes(otpMajor)) { + return [gitRef, otpMajor] } else { - throw new Error( - `Elixir ${version} and OTP ${otpVersion} are incompatible` - ) + return [gitRef, null] } } function getVersionFromSpec(spec, versions) { const range = semver.validRange(spec) - const version = semver.maxSatisfying(versions, range) - return version || spec + return semver.maxSatisfying(versions, range) } async function getOtpVersions() { @@ -75,7 +85,7 @@ async function getElixirVersions() { const map = new Map() result.trim().split('\n').forEach(line => { - const match = line.match(/^v(\d+\.\d+\.\d+)-otp-(\d+)/) + const match = line.match(/^(v\d+\.\d+\.\d+)-otp-(\d+)/) || line.match(/^([^-]+)-otp-(\d+)/) if (match) { const [_, version, otp] = match