Support elixir branches

71a9eee · Eric Meadows-Jönsson · 2019-11-17 23:03

4 files +30 -16

Files changed

modified .github/workflows/test.yml
+3 −0
@@ -18,6 +18,9 @@ jobs:
18 18 # Semver ranges
19 19 - otp-version: 21.x
20 20 elixir-version: <1.9.1
21 + # Branches
22 + - otp-version: 22.0
23 + elixir-version: master
21 24 steps:
22 25 - uses: actions/checkout@v1.0.0
23 26 - name: Use actions/setup-elixir
modified src/install-elixir
+3 −3
@@ -2,7 +2,7 @@
2 2
3 3 set -eo pipefail
4 4
5 wget -q https://repo.hex.pm/builds/elixir/v${1}-otp-${2}.zip
6 unzip -d .setup-elixir/elixir v${1}-otp-${2}.zip
7 rm v${1}-otp-${2}.zip
5 +wget -q https://repo.hex.pm/builds/elixir/${1}${2}.zip
6 +unzip -d .setup-elixir/elixir ${1}${2}.zip
7 +rm ${1}${2}.zip
8 8 echo "::add-path::$(pwd)/.setup-elixir/elixir/bin"
modified src/installer.js
+2 −1
@@ -12,7 +12,8 @@ module.exports = {installElixir, installOTP}
12 12 */
13 13 async function installElixir(version, otpMajor) {
14 14 if (process.platform === 'linux') {
15 await exec(path.join(__dirname, 'install-elixir'), [version, otpMajor])
15 + const otpString = otpMajor ? `-otp-${otpMajor}` : ''
16 + await exec(path.join(__dirname, 'install-elixir'), [version, otpString])
16 17 }
17 18 }
18 19
modified src/setup-elixir.js
+22 −12
@@ -14,8 +14,8 @@ async function main() {
14 14
15 15 const otpSpec = core.getInput('otp-version', {required: true})
16 16 const elixirSpec = core.getInput('elixir-version', {required: true})
17 const otpVersion = getVersionFromSpec(otpSpec, await getOtpVersions())
18 const [elixirVersion, otpMajor] = getElixirVersion(elixirSpec, await getElixirVersions(), otpVersion)
17 + const otpVersion = await getOtpVersion(otpSpec)
18 + const [elixirVersion, otpMajor] = await getElixirVersion(elixirSpec, otpVersion)
19 19
20 20 let installHex = core.getInput('install-hex')
21 21 installHex = installHex == null ? true : installHex
@@ -42,23 +42,33 @@ function checkPlatform() {
42 42 )
43 43 }
44 44
45 function getElixirVersion(spec, versions, otpVersion) {
46 const version = getVersionFromSpec(spec, Array.from(versions.keys()))
45 +async function getOtpVersion(spec) {
46 + return getVersionFromSpec(spec, await getOtpVersions()) || spec
47 +}
48 +
49 +async function getElixirVersion(spec, otpVersion) {
50 + const versions = await getElixirVersions()
51 + const semverRegex = /^v(\d+\.\d+\.\d+)/
52 +
53 + const semverVersions =
54 + Array.from(versions.keys())
55 + .filter(str => str.match(semverRegex))
56 + .map(str => str.match(semverRegex)[1])
57 +
58 + const version = getVersionFromSpec(spec, semverVersions)
59 + const gitRef = version ? `v${version}` : spec
47 60 const [otpMajor] = otpVersion.match(/^\d+/)
48 61
49 if (versions.get(version).includes(otpMajor)) {
50 return [version, otpMajor]
62 + if (versions.get(gitRef).includes(otpMajor)) {
63 + return [gitRef, otpMajor]
51 64 } else {
52 throw new Error(
53 `Elixir ${version} and OTP ${otpVersion} are incompatible`
54 )
65 + return [gitRef, null]
55 66 }
56 67 }
57 68
58 69 function getVersionFromSpec(spec, versions) {
59 70 const range = semver.validRange(spec)
60 const version = semver.maxSatisfying(versions, range)
61 return version || spec
71 + return semver.maxSatisfying(versions, range)
62 72 }
63 73
64 74 async function getOtpVersions() {
@@ -75,7 +85,7 @@ async function getElixirVersions() {
75 85 const map = new Map()
76 86
77 87 result.trim().split('\n').forEach(line => {
78 const match = line.match(/^v(\d+\.\d+\.\d+)-otp-(\d+)/)
88 + const match = line.match(/^(v\d+\.\d+\.\d+)-otp-(\d+)/) || line.match(/^([^-]+)-otp-(\d+)/)
79 89
80 90 if (match) {
81 91 const [_, version, otp] = match

Parents: 14bacb3