Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
67712d1715 | ||
|
|
1aaf342d27 | ||
|
|
6cbe4330ba | ||
|
|
033ba30590 | ||
|
|
3f153648ab | ||
|
|
05577888e7 | ||
|
|
064e705074 | ||
|
|
d06444e488 | ||
|
|
5b8160c641 | ||
|
|
ef8325c843 | ||
|
|
378f6784ad | ||
|
|
06ccede309 | ||
|
|
3a6105a934 | ||
|
|
65a119e15f | ||
|
|
ec4e5f880d | ||
|
|
811b4b88e8 | ||
|
|
8a6d70bfc0 | ||
|
|
8bdf2bbb33 | ||
|
|
fa3dc4b442 | ||
|
|
a12d5327a9 | ||
|
|
71a9eee041 | ||
|
|
14bacb3367 | ||
|
|
ec8659d099 | ||
|
|
8d90281adf |
3
.github/workflows/test.yml
vendored
3
.github/workflows/test.yml
vendored
@@ -18,6 +18,9 @@ jobs:
|
|||||||
# Semver ranges
|
# Semver ranges
|
||||||
- otp-version: 21.x
|
- otp-version: 21.x
|
||||||
elixir-version: <1.9.1
|
elixir-version: <1.9.1
|
||||||
|
# Branches
|
||||||
|
- otp-version: 22.0
|
||||||
|
elixir-version: master
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1.0.0
|
- uses: actions/checkout@v1.0.0
|
||||||
- name: Use actions/setup-elixir
|
- name: Use actions/setup-elixir
|
||||||
|
|||||||
@@ -55,10 +55,11 @@ further defined and clarified by project maintainers.
|
|||||||
## Enforcement
|
## Enforcement
|
||||||
|
|
||||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||||
reported by contacting the project team at [INSERT EMAIL ADDRESS]. All
|
reported by contacting the project team at
|
||||||
complaints will be reviewed and investigated and will result in a response that
|
[support@github.com](mailto:support@github.com). All complaints will be
|
||||||
is deemed necessary and appropriate to the circumstances. The project team is
|
reviewed and investigated and will result in a response that is deemed
|
||||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
necessary and appropriate to the circumstances. The project team is obligated
|
||||||
|
to maintain confidentiality with regard to the reporter of an incident.
|
||||||
Further details of specific enforcement policies may be posted separately.
|
Further details of specific enforcement policies may be posted separately.
|
||||||
|
|
||||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||||
|
|||||||
64
README.md
64
README.md
@@ -3,7 +3,8 @@
|
|||||||
[](https://github.com/actions/setup-elixir/actions)
|
[](https://github.com/actions/setup-elixir/actions)
|
||||||
[](https://github.com/actions/setup-elixir/actions)
|
[](https://github.com/actions/setup-elixir/actions)
|
||||||
|
|
||||||
This actions sets up an Elixir environment for use in Actions by:
|
This action sets up an Elixir environment for use in a GitHub Actions
|
||||||
|
workflow by:
|
||||||
|
|
||||||
- Installing OTP
|
- Installing OTP
|
||||||
- Installing Elixir
|
- Installing Elixir
|
||||||
@@ -16,9 +17,9 @@ See [action.yml](action.yml).
|
|||||||
|
|
||||||
**Note** The OTP release version specification is [relatively
|
**Note** The OTP release version specification is [relatively
|
||||||
complex](http://erlang.org/doc/system_principles/versions.html#version-scheme).
|
complex](http://erlang.org/doc/system_principles/versions.html#version-scheme).
|
||||||
For best results, the current recommendation is to use a full exact version
|
For best results, we recommend specifying exact OTP and Elixir versions.
|
||||||
spec from the list available from [Erlang
|
However, values like `22.x` are also accepted, and we attempt to resolve them
|
||||||
Solutions](https://www.erlang-solutions.com/resources/download.html).
|
according to semantic versioning rules.
|
||||||
|
|
||||||
### Basic example
|
### Basic example
|
||||||
|
|
||||||
@@ -29,11 +30,11 @@ jobs:
|
|||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1.0.0
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-elixir@v1.1.0
|
- uses: actions/setup-elixir@v1
|
||||||
with:
|
with:
|
||||||
otp-version: 22.x
|
otp-version: 22.2
|
||||||
elixir-version: 1.9.x
|
elixir-version: 1.9.4
|
||||||
- run: mix deps.get
|
- run: mix deps.get
|
||||||
- run: mix test
|
- run: mix test
|
||||||
```
|
```
|
||||||
@@ -49,11 +50,11 @@ jobs:
|
|||||||
name: OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
|
name: OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
otp: [20.x, 21.x, 22.x]
|
otp: [20.3, 21.3, 22.2]
|
||||||
elixir: [1.8.x, 1.9.x]
|
elixir: [1.8.2, 1.9.4]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1.0.0
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-elixir@v1.1.0
|
- uses: actions/setup-elixir@v1
|
||||||
with:
|
with:
|
||||||
otp-version: ${{matrix.otp}}
|
otp-version: ${{matrix.otp}}
|
||||||
elixir-version: ${{matrix.elixir}}
|
elixir-version: ${{matrix.elixir}}
|
||||||
@@ -74,6 +75,8 @@ jobs:
|
|||||||
db:
|
db:
|
||||||
image: postgres:11
|
image: postgres:11
|
||||||
ports: ['5432:5432']
|
ports: ['5432:5432']
|
||||||
|
env:
|
||||||
|
POSTGRES_PASSWORD: postgres
|
||||||
options: >-
|
options: >-
|
||||||
--health-cmd pg_isready
|
--health-cmd pg_isready
|
||||||
--health-interval 10s
|
--health-interval 10s
|
||||||
@@ -81,15 +84,44 @@ jobs:
|
|||||||
--health-retries 5
|
--health-retries 5
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1.0.0
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-elixir@v1.1.0
|
- uses: actions/setup-elixir@v1
|
||||||
with:
|
with:
|
||||||
otp-version: 22.x
|
otp-version: 22.2
|
||||||
elixir-version: 1.9.x
|
elixir-version: 1.9.4
|
||||||
- run: mix deps.get
|
- run: mix deps.get
|
||||||
- run: mix test
|
- run: mix test
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Authenticating with Postgres in Phoenix
|
||||||
|
|
||||||
|
When using the Phoenix example above, the `postgres` container has some
|
||||||
|
default authentication set up. Specifically, it expects a username of
|
||||||
|
"postgres", and a password of "postgres". It will be available at
|
||||||
|
`localhost:5432`.
|
||||||
|
|
||||||
|
The simplest way of setting these auth values in CI is by checking for the
|
||||||
|
`GITHUB_ACTIONS` environment variable that is set in all workflows:
|
||||||
|
|
||||||
|
```elixir
|
||||||
|
# config/test.exs
|
||||||
|
|
||||||
|
use Mix.Config
|
||||||
|
|
||||||
|
# Configure the database for local testing
|
||||||
|
config :app, App.Repo,
|
||||||
|
database: "my_app_test",
|
||||||
|
hostname: "localhost",
|
||||||
|
pool: Ecto.Adapters.SQL.Sandbox
|
||||||
|
|
||||||
|
# Configure the database for GitHub Actions
|
||||||
|
if System.get_env("GITHUB_ACTIONS") do
|
||||||
|
config :app, App.Repo,
|
||||||
|
username: "postgres",
|
||||||
|
password: "postgres"
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
The scripts and documentation in this project are released under the [MIT license](LICENSE.md).
|
The scripts and documentation in this project are released under the [MIT license](LICENSE.md).
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: Setup Elixir
|
name: Setup Elixir
|
||||||
description: Set up an Elixir/OTP environment and add it to the PATH
|
description: Set up a specific version of OTP and Elixir and add the command-line tools to the PATH
|
||||||
author: GitHub
|
author: GitHub
|
||||||
branding:
|
branding:
|
||||||
color: blue
|
color: blue
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -eo pipefail
|
|
||||||
|
|
||||||
# Find all releases that are $major.$minor(.$patch)? (no branch versions or rcs)
|
|
||||||
curl -fs https://raw.githubusercontent.com/erlang/otp/master/otp_versions.table \
|
|
||||||
| cut -d: -f1 \
|
|
||||||
| cut -d- -f2 \
|
|
||||||
| awk '{$1=$1};1' \
|
|
||||||
| grep -E '^\d+\.\d+(?:\.\d+)?$' \
|
|
||||||
| sed -E 's/^([0-9]+\.[0-9]+)$/\1.0/g' \
|
|
||||||
> src/erlang-versions.txt
|
|
||||||
|
|
||||||
# Find all releases that are $major.$minor(.$patch)? (no rcs)
|
|
||||||
curl -fs https://api.github.com/repos/elixir-lang/elixir/releases \
|
|
||||||
| jq -r '.[].tag_name' \
|
|
||||||
| sed 's/^v//' \
|
|
||||||
| grep -v '-' \
|
|
||||||
> src/elixir-versions.txt
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
1.9.4
|
|
||||||
1.9.3
|
|
||||||
1.9.2
|
|
||||||
1.9.1
|
|
||||||
1.9.0
|
|
||||||
1.8.2
|
|
||||||
1.8.1
|
|
||||||
1.8.0
|
|
||||||
1.7.4
|
|
||||||
1.7.3
|
|
||||||
1.7.2
|
|
||||||
1.7.1
|
|
||||||
1.7.0
|
|
||||||
1.6.6
|
|
||||||
1.6.5
|
|
||||||
1.6.4
|
|
||||||
1.6.3
|
|
||||||
1.6.2
|
|
||||||
1.6.1
|
|
||||||
1.6.0
|
|
||||||
1.5.3
|
|
||||||
1.5.2
|
|
||||||
1.5.1
|
|
||||||
1.5.0
|
|
||||||
@@ -1,143 +0,0 @@
|
|||||||
22.1.5
|
|
||||||
22.1.4
|
|
||||||
22.1.3
|
|
||||||
22.1.2
|
|
||||||
22.1.1
|
|
||||||
22.1
|
|
||||||
22.0.7
|
|
||||||
22.0.6
|
|
||||||
22.0.5
|
|
||||||
22.0.4
|
|
||||||
22.0.3
|
|
||||||
22.0.2
|
|
||||||
22.0.1
|
|
||||||
22.0.0
|
|
||||||
21.3.8
|
|
||||||
21.3.7
|
|
||||||
21.3.6
|
|
||||||
21.3.5
|
|
||||||
21.3.4
|
|
||||||
21.3.3
|
|
||||||
21.3.2
|
|
||||||
21.3.1
|
|
||||||
21.3.0
|
|
||||||
21.2.7
|
|
||||||
21.2.6
|
|
||||||
21.2.5
|
|
||||||
21.2.4
|
|
||||||
21.2.3
|
|
||||||
21.2.2
|
|
||||||
21.2.1
|
|
||||||
21.2.0
|
|
||||||
21.1.4
|
|
||||||
21.1.3
|
|
||||||
21.1.2
|
|
||||||
21.1.1
|
|
||||||
21.1.0
|
|
||||||
21.0.9
|
|
||||||
21.0.8
|
|
||||||
21.0.7
|
|
||||||
21.0.6
|
|
||||||
21.0.5
|
|
||||||
21.0.4
|
|
||||||
21.0.3
|
|
||||||
21.0.2
|
|
||||||
21.0.1
|
|
||||||
21.0.0
|
|
||||||
20.3.8
|
|
||||||
20.3.7
|
|
||||||
20.3.6
|
|
||||||
20.3.5
|
|
||||||
20.3.4
|
|
||||||
20.3.3
|
|
||||||
20.3.2
|
|
||||||
20.3.1
|
|
||||||
20.3.0
|
|
||||||
20.2.4
|
|
||||||
20.2.3
|
|
||||||
20.2.2
|
|
||||||
20.2.1
|
|
||||||
20.2.0
|
|
||||||
20.1.7
|
|
||||||
20.1.6
|
|
||||||
20.1.5
|
|
||||||
20.1.4
|
|
||||||
20.1.3
|
|
||||||
20.1.2
|
|
||||||
20.1.1
|
|
||||||
20.1.0
|
|
||||||
20.0.5
|
|
||||||
20.0.4
|
|
||||||
20.0.3
|
|
||||||
20.0.2
|
|
||||||
20.0.1
|
|
||||||
20.0.0
|
|
||||||
19.3.6
|
|
||||||
19.3.5
|
|
||||||
19.3.4
|
|
||||||
19.3.3
|
|
||||||
19.3.2
|
|
||||||
19.3.1
|
|
||||||
19.3.0
|
|
||||||
19.2.3
|
|
||||||
19.2.2
|
|
||||||
19.2.1
|
|
||||||
19.2.0
|
|
||||||
19.1.6
|
|
||||||
19.1.5
|
|
||||||
19.1.4
|
|
||||||
19.1.3
|
|
||||||
19.1.2
|
|
||||||
19.1.1
|
|
||||||
19.1.0
|
|
||||||
19.0.7
|
|
||||||
19.0.6
|
|
||||||
19.0.5
|
|
||||||
19.0.4
|
|
||||||
19.0.3
|
|
||||||
19.0.2
|
|
||||||
19.0.1
|
|
||||||
19.0.0
|
|
||||||
18.3.4
|
|
||||||
18.3.3
|
|
||||||
18.3.2
|
|
||||||
18.3.1
|
|
||||||
18.3.0
|
|
||||||
18.2.4
|
|
||||||
18.2.3
|
|
||||||
18.2.2
|
|
||||||
18.2.1
|
|
||||||
18.2.0
|
|
||||||
18.1.5
|
|
||||||
18.1.4
|
|
||||||
18.1.3
|
|
||||||
18.1.2
|
|
||||||
18.1.1
|
|
||||||
18.1.0
|
|
||||||
18.0.3
|
|
||||||
18.0.2
|
|
||||||
18.0.1
|
|
||||||
18.0.0
|
|
||||||
17.5.6
|
|
||||||
17.5.5
|
|
||||||
17.5.4
|
|
||||||
17.5.3
|
|
||||||
17.5.2
|
|
||||||
17.5.1
|
|
||||||
17.5.0
|
|
||||||
17.4.1
|
|
||||||
17.4.0
|
|
||||||
17.3.4
|
|
||||||
17.3.3
|
|
||||||
17.3.2
|
|
||||||
17.3.1
|
|
||||||
17.3.0
|
|
||||||
17.2.2
|
|
||||||
17.2.1
|
|
||||||
17.2.0
|
|
||||||
17.1.2
|
|
||||||
17.1.1
|
|
||||||
17.1.0
|
|
||||||
17.0.2
|
|
||||||
17.0.1
|
|
||||||
17.0.0
|
|
||||||
10
src/install-elixir
Executable file
10
src/install-elixir
Executable file
@@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -eo pipefail
|
||||||
|
|
||||||
|
cd /tmp
|
||||||
|
|
||||||
|
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"
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -eo pipefail
|
|
||||||
|
|
||||||
release=$(cat /etc/os-release | grep UBUNTU_CODENAME | cut -d= -f2)
|
|
||||||
version=$1
|
|
||||||
arch=$2
|
|
||||||
file=elixir_$version-1~ubuntu~$release\_$arch.deb
|
|
||||||
|
|
||||||
cd /tmp
|
|
||||||
|
|
||||||
wget https://packages.erlang-solutions.com/erlang/debian/pool/$file
|
|
||||||
sudo dpkg -i $file
|
|
||||||
12
src/install-otp
Executable file
12
src/install-otp
Executable file
@@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -eo pipefail
|
||||||
|
|
||||||
|
cd /tmp
|
||||||
|
|
||||||
|
wget -q -O otp.tar.gz https://repo.hex.pm/builds/otp/ubuntu-14.04/OTP-${1}.tar.gz
|
||||||
|
mkdir -p .setup-elixir/otp
|
||||||
|
tar zxf otp.tar.gz -C .setup-elixir/otp --strip-components=1
|
||||||
|
rm otp.tar.gz
|
||||||
|
.setup-elixir/otp/Install -minimal $(pwd)/.setup-elixir/otp
|
||||||
|
echo "::add-path::$(pwd)/.setup-elixir/otp/bin"
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -eo pipefail
|
|
||||||
|
|
||||||
release=$(lsb_release -cs)
|
|
||||||
version=$1
|
|
||||||
file=esl-erlang_$version-1~ubuntu~$release\_amd64.deb
|
|
||||||
|
|
||||||
sudo apt-get install -y libwxbase3.0-0v5
|
|
||||||
sudo apt-get install -y libwxgtk3.0-0v5
|
|
||||||
sudo apt-get install -y libsctp1
|
|
||||||
|
|
||||||
cd /tmp
|
|
||||||
|
|
||||||
wget https://packages.erlang-solutions.com/erlang/debian/pool/$file
|
|
||||||
sudo dpkg -i $file
|
|
||||||
@@ -8,14 +8,12 @@ module.exports = {installElixir, installOTP}
|
|||||||
* Install Elixir.
|
* Install Elixir.
|
||||||
*
|
*
|
||||||
* @param {string} version
|
* @param {string} version
|
||||||
* @param {string} arch
|
* @param {string} otpMajor
|
||||||
*/
|
*/
|
||||||
async function installElixir(version) {
|
async function installElixir(version, otpMajor) {
|
||||||
let arch = 'all'
|
|
||||||
if (semver.gt('1.9.0', version)) arch = 'amd64'
|
|
||||||
|
|
||||||
if (process.platform === 'linux') {
|
if (process.platform === 'linux') {
|
||||||
await exec(path.join(__dirname, 'install-elixir-ubuntu'), [version, arch])
|
const otpString = otpMajor ? `-otp-${otpMajor}` : ''
|
||||||
|
await exec(path.join(__dirname, 'install-elixir'), [version, otpString])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,7 +24,7 @@ async function installElixir(version) {
|
|||||||
*/
|
*/
|
||||||
async function installOTP(version) {
|
async function installOTP(version) {
|
||||||
if (process.platform === 'linux') {
|
if (process.platform === 'linux') {
|
||||||
await exec(path.join(__dirname, 'install-otp-ubuntu'), [version])
|
await exec(path.join(__dirname, 'install-otp'), [version])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
const core = require('@actions/core')
|
const core = require('@actions/core')
|
||||||
const {exec} = require('@actions/exec')
|
const {exec} = require('@actions/exec')
|
||||||
const {installElixir, installOTP} = require('./installer')
|
const {installElixir, installOTP} = require('./installer')
|
||||||
const {readFile} = require('fs').promises
|
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const semver = require('semver')
|
const semver = require('semver')
|
||||||
|
const https = require('https')
|
||||||
|
|
||||||
main().catch(err => {
|
main().catch(err => {
|
||||||
core.setFailed(err.message)
|
core.setFailed(err.message)
|
||||||
@@ -14,33 +14,32 @@ async function main() {
|
|||||||
|
|
||||||
const otpSpec = core.getInput('otp-version', {required: true})
|
const otpSpec = core.getInput('otp-version', {required: true})
|
||||||
const elixirSpec = core.getInput('elixir-version', {required: true})
|
const elixirSpec = core.getInput('elixir-version', {required: true})
|
||||||
const otpVersion = await getVersion(
|
const otpVersion = await getOtpVersion(otpSpec)
|
||||||
otpSpec,
|
const [elixirVersion, otpMajor] = await getElixirVersion(
|
||||||
path.join(__dirname, 'erlang-versions.txt')
|
|
||||||
)
|
|
||||||
const elixirVersion = await getVersion(
|
|
||||||
elixirSpec,
|
elixirSpec,
|
||||||
path.join(__dirname, 'elixir-versions.txt')
|
otpVersion
|
||||||
)
|
)
|
||||||
|
|
||||||
let installHex = core.getInput('install-hex')
|
let installHex = core.getInput('install-hex')
|
||||||
installHex = installHex == null ? true : installHex
|
installHex = installHex == null ? 'true' : installHex
|
||||||
let installRebar = core.getInput('install-rebar')
|
let installRebar = core.getInput('install-rebar')
|
||||||
installRebar = installRebar == null ? true : installRebar
|
installRebar = installRebar == null ? 'true' : installRebar
|
||||||
|
|
||||||
console.log(`##[group]Installing OTP ${otpVersion}`)
|
console.log(`##[group]Installing OTP ${otpVersion}`)
|
||||||
await installOTP(otpVersion)
|
await installOTP(otpVersion)
|
||||||
console.log(`##[endgroup]`)
|
console.log(`##[endgroup]`)
|
||||||
|
|
||||||
console.log(`##[group]Installing Elixir ${elixirVersion}`)
|
console.log(`##[group]Installing Elixir ${elixirVersion}`)
|
||||||
await installElixir(elixirVersion)
|
await installElixir(elixirVersion, otpMajor)
|
||||||
console.log(`##[endgroup]`)
|
console.log(`##[endgroup]`)
|
||||||
|
|
||||||
if (installRebar) await exec('mix local.rebar --force')
|
process.env.PATH = `/tmp/.setup-elixir/elixir/bin:/tmp/.setup-elixir/otp/bin:${process.env.PATH}`
|
||||||
if (installHex) await exec('mix local.hex --force')
|
|
||||||
|
|
||||||
const matchersPath = path.join(__dirname, '..', '.github');
|
if (installRebar === 'true') await exec('mix local.rebar --force')
|
||||||
console.log(`##[add-matcher]${path.join(matchersPath, 'elixir.json')}`);
|
if (installHex === 'true') await exec('mix local.hex --force')
|
||||||
|
|
||||||
|
const matchersPath = path.join(__dirname, '..', '.github')
|
||||||
|
console.log(`##[add-matcher]${path.join(matchersPath, 'elixir.json')}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkPlatform() {
|
function checkPlatform() {
|
||||||
@@ -50,9 +49,91 @@ function checkPlatform() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getVersion(spec, versionFile) {
|
async function getOtpVersion(spec) {
|
||||||
const range = semver.validRange(spec)
|
return getVersionFromSpec(spec, await getOtpVersions()) || spec
|
||||||
const versions = (await readFile(versionFile)).toString().split('\n')
|
}
|
||||||
const version = semver.maxSatisfying(versions, range)
|
|
||||||
return version || 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(gitRef).includes(otpMajor)) {
|
||||||
|
return [gitRef, otpMajor]
|
||||||
|
} else {
|
||||||
|
return [gitRef, null]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getVersionFromSpec(spec, versions) {
|
||||||
|
if (versions.includes(spec)) {
|
||||||
|
return spec
|
||||||
|
} else {
|
||||||
|
const range = semver.validRange(spec)
|
||||||
|
return semver.maxSatisfying(versions, range)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getOtpVersions() {
|
||||||
|
const result = await get(
|
||||||
|
'https://raw.githubusercontent.com/erlang/otp/master/otp_versions.table'
|
||||||
|
)
|
||||||
|
|
||||||
|
return result
|
||||||
|
.trim()
|
||||||
|
.split('\n')
|
||||||
|
.map(line => {
|
||||||
|
const [_, version] = line.match(/^OTP-([\.\d]+)/)
|
||||||
|
return version
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getElixirVersions() {
|
||||||
|
const result = await get('https://repo.hex.pm/builds/elixir/builds.txt')
|
||||||
|
const map = new Map()
|
||||||
|
|
||||||
|
result
|
||||||
|
.trim()
|
||||||
|
.split('\n')
|
||||||
|
.forEach(line => {
|
||||||
|
const match =
|
||||||
|
line.match(/^(v\d+\.\d+\.\d+)-otp-(\d+)/) ||
|
||||||
|
line.match(/^([^-]+)-otp-(\d+)/)
|
||||||
|
|
||||||
|
if (match) {
|
||||||
|
const [_, version, otp] = match
|
||||||
|
const array = map.get(version) || []
|
||||||
|
array.push(otp)
|
||||||
|
map.set(version, array)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return map
|
||||||
|
}
|
||||||
|
|
||||||
|
function get(url) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const req = https.get(url)
|
||||||
|
|
||||||
|
req.on('response', res => {
|
||||||
|
let data = ''
|
||||||
|
res.on('data', chunk => {
|
||||||
|
data += chunk
|
||||||
|
})
|
||||||
|
res.on('end', () => {
|
||||||
|
resolve(data)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
req.on('error', err => {
|
||||||
|
reject(err)
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user