Merge pull request #10 from ericmj/emj/hex

8bdf2bb · Jonathan Clem · 2019-12-04 18:50

10 files +103 -237
Message
{commit_body(@commit)}

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
deleted script/build-versions
+0 −19
@@ -1,19 +0,0 @@
1 #!/usr/bin/env bash
2
3 set -eo pipefail
4
5 # Find all releases that are $major.$minor(.$patch)? (no branch versions or rcs)
6 curl -fs https://raw.githubusercontent.com/erlang/otp/master/otp_versions.table \
7 | cut -d: -f1 \
8 | cut -d- -f2 \
9 | awk '{$1=$1};1' \
10 | grep -E '^\d+\.\d+(?:\.\d+)?$' \
11 | sed -E 's/^([0-9]+\.[0-9]+)$/\1.0/g' \
12 > src/erlang-versions.txt
13
14 # Find all releases that are $major.$minor(.$patch)? (no rcs)
15 curl -fs https://api.github.com/repos/elixir-lang/elixir/releases \
16 | jq -r '.[].tag_name' \
17 | sed 's/^v//' \
18 | grep -v '-' \
19 > src/elixir-versions.txt
deleted src/elixir-versions.txt
+0 −24
@@ -1,24 +0,0 @@
1 1.9.4
2 1.9.3
3 1.9.2
4 1.9.1
5 1.9.0
6 1.8.2
7 1.8.1
8 1.8.0
9 1.7.4
10 1.7.3
11 1.7.2
12 1.7.1
13 1.7.0
14 1.6.6
15 1.6.5
16 1.6.4
17 1.6.3
18 1.6.2
19 1.6.1
20 1.6.0
21 1.5.3
22 1.5.2
23 1.5.1
24 1.5.0
deleted src/erlang-versions.txt
+0 −143
@@ -1,143 +0,0 @@
1 22.1.5
2 22.1.4
3 22.1.3
4 22.1.2
5 22.1.1
6 22.1
7 22.0.7
8 22.0.6
9 22.0.5
10 22.0.4
11 22.0.3
12 22.0.2
13 22.0.1
14 22.0.0
15 21.3.8
16 21.3.7
17 21.3.6
18 21.3.5
19 21.3.4
20 21.3.3
21 21.3.2
22 21.3.1
23 21.3.0
24 21.2.7
25 21.2.6
26 21.2.5
27 21.2.4
28 21.2.3
29 21.2.2
30 21.2.1
31 21.2.0
32 21.1.4
33 21.1.3
34 21.1.2
35 21.1.1
36 21.1.0
37 21.0.9
38 21.0.8
39 21.0.7
40 21.0.6
41 21.0.5
42 21.0.4
43 21.0.3
44 21.0.2
45 21.0.1
46 21.0.0
47 20.3.8
48 20.3.7
49 20.3.6
50 20.3.5
51 20.3.4
52 20.3.3
53 20.3.2
54 20.3.1
55 20.3.0
56 20.2.4
57 20.2.3
58 20.2.2
59 20.2.1
60 20.2.0
61 20.1.7
62 20.1.6
63 20.1.5
64 20.1.4
65 20.1.3
66 20.1.2
67 20.1.1
68 20.1.0
69 20.0.5
70 20.0.4
71 20.0.3
72 20.0.2
73 20.0.1
74 20.0.0
75 19.3.6
76 19.3.5
77 19.3.4
78 19.3.3
79 19.3.2
80 19.3.1
81 19.3.0
82 19.2.3
83 19.2.2
84 19.2.1
85 19.2.0
86 19.1.6
87 19.1.5
88 19.1.4
89 19.1.3
90 19.1.2
91 19.1.1
92 19.1.0
93 19.0.7
94 19.0.6
95 19.0.5
96 19.0.4
97 19.0.3
98 19.0.2
99 19.0.1
100 19.0.0
101 18.3.4
102 18.3.3
103 18.3.2
104 18.3.1
105 18.3.0
106 18.2.4
107 18.2.3
108 18.2.2
109 18.2.1
110 18.2.0
111 18.1.5
112 18.1.4
113 18.1.3
114 18.1.2
115 18.1.1
116 18.1.0
117 18.0.3
118 18.0.2
119 18.0.1
120 18.0.0
121 17.5.6
122 17.5.5
123 17.5.4
124 17.5.3
125 17.5.2
126 17.5.1
127 17.5.0
128 17.4.1
129 17.4.0
130 17.3.4
131 17.3.3
132 17.3.2
133 17.3.1
134 17.3.0
135 17.2.2
136 17.2.1
137 17.2.0
138 17.1.2
139 17.1.1
140 17.1.0
141 17.0.2
142 17.0.1
143 17.0.0
added src/install-elixir
+8 −0
@@ -0,0 +1,8 @@
1 +#!/bin/bash
2 +
3 +set -eo pipefail
4 +
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 +echo "::add-path::$(pwd)/.setup-elixir/elixir/bin"
deleted src/install-elixir-ubuntu
+0 −13
@@ -1,13 +0,0 @@
1 #!/bin/bash
2
3 set -eo pipefail
4
5 release=$(cat /etc/os-release | grep UBUNTU_CODENAME | cut -d= -f2)
6 version=$1
7 arch=$2
8 file=elixir_$version-1~ubuntu~$release\_$arch.deb
9
10 cd /tmp
11
12 wget https://packages.erlang-solutions.com/erlang/debian/pool/$file
13 sudo dpkg -i $file
added src/install-otp
+10 −0
@@ -0,0 +1,10 @@
1 +#!/bin/bash
2 +
3 +set -eo pipefail
4 +
5 +wget -q -O otp.tar.gz https://repo.hex.pm/builds/otp/ubuntu-14.04/OTP-${1}.tar.gz
6 +mkdir -p .setup-elixir/otp
7 +tar zxf otp.tar.gz -C .setup-elixir/otp --strip-components=1
8 +rm otp.tar.gz
9 +.setup-elixir/otp/Install -minimal $(pwd)/.setup-elixir/otp
10 +echo "::add-path::$(pwd)/.setup-elixir/otp/bin"
deleted src/install-otp-ubuntu
+0 −16
@@ -1,16 +0,0 @@
1 #!/bin/bash
2
3 set -eo pipefail
4
5 release=$(lsb_release -cs)
6 version=$1
7 file=esl-erlang_$version-1~ubuntu~$release\_amd64.deb
8
9 sudo apt-get install -y libwxbase3.0-0v5
10 sudo apt-get install -y libwxgtk3.0-0v5
11 sudo apt-get install -y libsctp1
12
13 cd /tmp
14
15 wget https://packages.erlang-solutions.com/erlang/debian/pool/$file
16 sudo dpkg -i $file
modified src/installer.js
+5 −7
@@ -8,14 +8,12 @@ module.exports = {installElixir, installOTP}
8 8 * Install Elixir.
9 9 *
10 10 * @param {string} version
11 * @param {string} arch
11 + * @param {string} otpMajor
12 12 */
13 async function installElixir(version) {
14 let arch = 'all'
15 if (semver.gt('1.9.0', version)) arch = 'amd64'
16
13 +async function installElixir(version, otpMajor) {
17 14 if (process.platform === 'linux') {
18 await exec(path.join(__dirname, 'install-elixir-ubuntu'), [version, arch])
15 + const otpString = otpMajor ? `-otp-${otpMajor}` : ''
16 + await exec(path.join(__dirname, 'install-elixir'), [version, otpString])
19 17 }
20 18 }
21 19
@@ -26,7 +24,7 @@ async function installElixir(version) {
26 24 */
27 25 async function installOTP(version) {
28 26 if (process.platform === 'linux') {
29 await exec(path.join(__dirname, 'install-otp-ubuntu'), [version])
27 + await exec(path.join(__dirname, 'install-otp'), [version])
30 28 return
31 29 }
32 30
modified src/setup-elixir.js
+77 −15
@@ -1,9 +1,9 @@
1 1 const core = require('@actions/core')
2 2 const {exec} = require('@actions/exec')
3 3 const {installElixir, installOTP} = require('./installer')
4 const {readFile} = require('fs').promises
5 4 const path = require('path')
6 5 const semver = require('semver')
6 +const https = require('https')
7 7
8 8 main().catch(err => {
9 9 core.setFailed(err.message)
@@ -14,14 +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 = await getVersion(
18 otpSpec,
19 path.join(__dirname, 'erlang-versions.txt')
20 )
21 const elixirVersion = await getVersion(
22 elixirSpec,
23 path.join(__dirname, 'elixir-versions.txt')
24 )
17 + const otpVersion = await getOtpVersion(otpSpec)
18 + const [elixirVersion, otpMajor] = await getElixirVersion(elixirSpec, otpVersion)
25 19
26 20 let installHex = core.getInput('install-hex')
27 21 installHex = installHex == null ? true : installHex
@@ -33,9 +27,10 @@ async function main() {
33 27 console.log(`##[endgroup]`)
34 28
35 29 console.log(`##[group]Installing Elixir ${elixirVersion}`)
36 await installElixir(elixirVersion)
30 + await installElixir(elixirVersion, otpMajor)
37 31 console.log(`##[endgroup]`)
38 32
33 + process.env.PATH = `${process.cwd()}/.setup-elixir/elixir/bin:${process.env.PATH}`
39 34 if (installRebar) await exec('mix local.rebar --force')
40 35 if (installHex) await exec('mix local.hex --force')
41 36
@@ -50,9 +45,76 @@ function checkPlatform() {
50 45 )
51 46 }
52 47
53 async function getVersion(spec, versionFile) {
54 const range = semver.validRange(spec)
55 const versions = (await readFile(versionFile)).toString().split('\n')
56 const version = semver.maxSatisfying(versions, range)
57 return version || spec
48 +async function getOtpVersion(spec) {
49 + return getVersionFromSpec(spec, await getOtpVersions()) || spec
50 +}
51 +
52 +async function getElixirVersion(spec, otpVersion) {
53 + const versions = await getElixirVersions()
54 + const semverRegex = /^v(\d+\.\d+\.\d+)/
55 +
56 + const semverVersions =
57 + Array.from(versions.keys())
58 + .filter(str => str.match(semverRegex))
59 + .map(str => str.match(semverRegex)[1])
60 +
61 + const version = getVersionFromSpec(spec, semverVersions)
62 + const gitRef = version ? `v${version}` : spec
63 + const [otpMajor] = otpVersion.match(/^\d+/)
64 +
65 + if (versions.get(gitRef).includes(otpMajor)) {
66 + return [gitRef, otpMajor]
67 + } else {
68 + return [gitRef, null]
69 + }
70 +}
71 +
72 +function getVersionFromSpec(spec, versions) {
73 + if (versions.includes(spec)) {
74 + return spec;
75 + } else {
76 + const range = semver.validRange(spec)
77 + return semver.maxSatisfying(versions, range)
78 + }
79 +}
80 +
81 +async function getOtpVersions() {
82 + const result = await get("https://raw.githubusercontent.com/erlang/otp/master/otp_versions.table")
83 +
84 + return result.trim().split('\n').map(line => {
85 + const [_, version] = line.match(/^OTP-([\.\d]+)/)
86 + return version
87 + })
88 +}
89 +
90 +async function getElixirVersions() {
91 + const result = await get("https://repo.hex.pm/builds/elixir/builds.txt")
92 + const map = new Map()
93 +
94 + result.trim().split('\n').forEach(line => {
95 + const match = line.match(/^(v\d+\.\d+\.\d+)-otp-(\d+)/) || line.match(/^([^-]+)-otp-(\d+)/)
96 +
97 + if (match) {
98 + const [_, version, otp] = match
99 + const array = (map.get(version) || [])
100 + array.push(otp)
101 + map.set(version, array)
102 + }
103 + })
104 +
105 + return map
106 +}
107 +
108 +function get(url) {
109 + return new Promise((resolve, reject) => {
110 + const req = https.get(url)
111 +
112 + req.on('response', res => {
113 + let data = ''
114 + res.on('data', (chunk) => { data += chunk })
115 + res.on('end', () => { resolve(data) })
116 + })
117 +
118 + req.on('error', err => { reject(err) })
119 + })
58 120 }

Parents: 1a3c640 fa3dc4b