Install from hex

14bacb3 · Eric Meadows-Jönsson · 2019-11-17 20:07

11 files +82 -234

Files changed

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/v${1}-otp-${2}.zip
6 +unzip -d .setup-elixir/elixir v${1}-otp-${2}.zip
7 +rm v${1}-otp-${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
+4 −7
@@ -8,14 +8,11 @@ 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 + await exec(path.join(__dirname, 'install-elixir'), [version, otpMajor])
19 16 }
20 17 }
21 18
@@ -26,7 +23,7 @@ async function installElixir(version) {
26 23 */
27 24 async function installOTP(version) {
28 25 if (process.platform === 'linux') {
29 − await exec(path.join(__dirname, 'install-otp-ubuntu'), [version])
26 + await exec(path.join(__dirname, 'install-otp'), [version])
30 27 return
31 28 }
32 29
modified src/setup-elixir.js
+60 −12
@@ -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 = getVersionFromSpec(otpSpec, await getOtpVersions())
18 + const [elixirVersion, otpMajor] = getElixirVersion(elixirSpec, await getElixirVersions(), 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 }
@@ -47,9 +42,62 @@ function checkPlatform() {
47 42 )
48 43 }
49 44
50 −async function getVersion(spec, versionFile) {
45 +function getElixirVersion(spec, versions, otpVersion) {
46 + const version = getVersionFromSpec(spec, Array.from(versions.keys()))
47 + const [otpMajor] = otpVersion.match(/^\d+/)
48 +
49 + if (versions.get(version).includes(otpMajor)) {
50 + return [version, otpMajor]
51 + } else {
52 + throw new Error(
53 + `Elixir ${version} and OTP ${otpVersion} are incompatible`
54 + )
55 + }
56 +}
57 +
58 +function getVersionFromSpec(spec, versions) {
51 59 const range = semver.validRange(spec)
52 − const versions = (await readFile(versionFile)).toString().split('\n')
53 60 const version = semver.maxSatisfying(versions, range)
54 61 return version || spec
55 62 }
63 +
64 +async function getOtpVersions() {
65 + const result = await get("https://raw.githubusercontent.com/erlang/otp/master/otp_versions.table")
66 +
67 + return result.trim().split('\n').map(line => {
68 + const [_, version] = line.match(/^OTP-([\.\d]+)/)
69 + return version
70 + })
71 +}
72 +
73 +async function getElixirVersions() {
74 + const result = await get("https://repo.hex.pm/builds/elixir/builds.txt")
75 + const map = new Map()
76 +
77 + result.trim().split('\n').forEach(line => {
78 + const match = line.match(/^v(\d+\.\d+\.\d+)-otp-(\d+)/)
79 +
80 + if (match) {
81 + const [_, version, otp] = match
82 + const array = (map.get(version) || [])
83 + array.push(otp)
84 + map.set(version, array)
85 + }
86 + })
87 +
88 + return map
89 +}
90 +
91 +function get(url) {
92 + return new Promise((resolve, reject) => {
93 + const req = https.get(url)
94 +
95 + req.on('response', res => {
96 + let data = ''
97 + res.on('data', (chunk) => { data += chunk })
98 + res.on('end', () => { resolve(data) })
99 + })
100 +
101 + req.on('error', err => { reject(err) })
102 + })
103 +}

Parents: ca25180