mirror of
https://github.com/erlef/setup-beam.git
synced 2026-07-23 07:06:07 +00:00
Add Windows to the mix (#49)
This commit is contained in:
committed by
GitHub
parent
dd4eb24e91
commit
82b4475ba2
Vendored
+159
-58
@@ -4594,7 +4594,13 @@ const path = __nccwpck_require__(5622)
|
||||
* @param {string} otpVersion
|
||||
*/
|
||||
async function installOTP(osVersion, otpVersion) {
|
||||
await exec(__nccwpck_require__.ab + "install-otp", [osVersion, otpVersion])
|
||||
const OS = process.platform
|
||||
if (OS === 'linux') {
|
||||
await exec(__nccwpck_require__.ab + "install-otp.sh", [osVersion, otpVersion])
|
||||
} else if (OS === 'win32') {
|
||||
const script = __nccwpck_require__.ab + "install-otp.ps1"
|
||||
await exec(`powershell.exe ${script} -VSN:${otpVersion}`)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -4603,7 +4609,13 @@ async function installOTP(osVersion, otpVersion) {
|
||||
* @param {string} elixirVersion
|
||||
*/
|
||||
async function installElixir(elixirVersion) {
|
||||
await exec(__nccwpck_require__.ab + "install-elixir", [elixirVersion])
|
||||
const OS = process.platform
|
||||
if (OS === 'linux') {
|
||||
await exec(__nccwpck_require__.ab + "install-elixir.sh", [elixirVersion])
|
||||
} else if (OS === 'win32') {
|
||||
const script = __nccwpck_require__.ab + "install-elixir.ps1"
|
||||
await exec(`powershell.exe ${script} ${elixirVersion}`)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -4612,12 +4624,20 @@ async function installElixir(elixirVersion) {
|
||||
* @param {string} rebar3Version
|
||||
*/
|
||||
async function installRebar3(rebar3Version) {
|
||||
await exec(__nccwpck_require__.ab + "install-rebar3", [rebar3Version])
|
||||
const OS = process.platform
|
||||
if (OS === 'linux') {
|
||||
await exec(__nccwpck_require__.ab + "install-rebar3.sh", [rebar3Version])
|
||||
} else if (OS === 'win32') {
|
||||
const script = __nccwpck_require__.ab + "install-rebar3.ps1"
|
||||
await exec(`powershell.exe ${script} -VSN:${rebar3Version}`)
|
||||
}
|
||||
}
|
||||
|
||||
function checkPlatform() {
|
||||
if (process.platform !== 'linux') {
|
||||
throw new Error('@erlef/setup-beam only supports Ubuntu Linux at this time')
|
||||
if (process.platform !== 'linux' && process.platform !== 'win32') {
|
||||
throw new Error(
|
||||
'@erlef/setup-beam only supports Ubuntu and Windows at this time',
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4653,20 +4673,24 @@ async function main() {
|
||||
const otpVersion = await installOTP(otpSpec, osVersion)
|
||||
|
||||
const elixirSpec = core.getInput('elixir-version', { required: false })
|
||||
const elixirInstalled = await maybeInstallElixir(elixirSpec, otpVersion)
|
||||
const shouldMixHex = core.getInput('install-hex', {
|
||||
required: false,
|
||||
})
|
||||
const elixirInstalled = await maybeInstallElixir(
|
||||
elixirSpec,
|
||||
otpVersion,
|
||||
shouldMixHex,
|
||||
)
|
||||
if (elixirInstalled === true) {
|
||||
const shouldMixRebar = core.getInput('install-rebar', {
|
||||
required: false,
|
||||
})
|
||||
await mix(shouldMixRebar, 'rebar')
|
||||
const shouldMixHex = core.getInput('install-hex', {
|
||||
required: false,
|
||||
})
|
||||
await mix(shouldMixHex, 'hex')
|
||||
}
|
||||
|
||||
const rebar3Spec = core.getInput('rebar3-version', { required: false })
|
||||
maybeInstallRebar3(rebar3Spec)
|
||||
await maybeInstallRebar3(rebar3Spec)
|
||||
}
|
||||
|
||||
async function installOTP(otpSpec, osVersion) {
|
||||
@@ -4676,13 +4700,17 @@ async function installOTP(otpSpec, osVersion) {
|
||||
)
|
||||
await installer.installOTP(osVersion, otpVersion)
|
||||
core.setOutput('otp-version', otpVersion)
|
||||
prependToPath(`${process.env.RUNNER_TEMP}/.setup-beam/otp/bin`)
|
||||
if (process.platform === 'linux') {
|
||||
prependToPath(`${process.env.RUNNER_TEMP}/.setup-beam/otp/bin`)
|
||||
} else if (process.platform === 'win32') {
|
||||
prependToPath(`C:/Program Files/erl-${otpVersion}/bin`)
|
||||
}
|
||||
console.log('##[endgroup]')
|
||||
|
||||
return otpVersion
|
||||
}
|
||||
|
||||
async function maybeInstallElixir(elixirSpec, otpVersion) {
|
||||
async function maybeInstallElixir(elixirSpec, otpVersion, shouldMixHex) {
|
||||
if (elixirSpec) {
|
||||
const elixirVersion = await getElixirVersion(elixirSpec, otpVersion)
|
||||
console.log(`##[group]Installing Elixir ${elixirVersion}`)
|
||||
@@ -4698,6 +4726,12 @@ async function maybeInstallElixir(elixirSpec, otpVersion) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (shouldMixHex) {
|
||||
console.log(
|
||||
"hex will not be installed (overriding default) since Elixir wasn't either",
|
||||
)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -4784,7 +4818,7 @@ async function getElixirVersion(exSpec0, otpVersion) {
|
||||
`Using Elixir ${elixirVersion} (built for OTP ${otpVersionMajor})`,
|
||||
)
|
||||
} else {
|
||||
// ... and it's not available: fallback to the "generic" version (v1.4.5 only).
|
||||
// ... and it's not available: fallback to the 'generic' version (v1.4.5 only).
|
||||
elixirVersionWithOTP = elixirVersion
|
||||
core.info(`Using Elixir ${elixirVersion}`)
|
||||
}
|
||||
@@ -4811,34 +4845,61 @@ async function getRebar3Version(r3Spec) {
|
||||
}
|
||||
|
||||
async function getOTPVersions(osVersion) {
|
||||
const otpVersionsListing = await get(
|
||||
`https://repo.hex.pm/builds/otp/${osVersion}/builds.txt`,
|
||||
)
|
||||
let originListing
|
||||
let pageIdxs
|
||||
if (process.platform === 'linux') {
|
||||
originListing = `https://repo.hex.pm/builds/otp/${osVersion}/builds.txt`
|
||||
pageIdxs = [null]
|
||||
} else if (process.platform === 'win32') {
|
||||
originListing =
|
||||
'https://api.github.com/repos/erlang/otp/releases?per_page=100'
|
||||
pageIdxs = [1, 2, 3]
|
||||
}
|
||||
|
||||
const otpVersionsListings = await get(originListing, pageIdxs)
|
||||
const otpVersions = new Map()
|
||||
|
||||
otpVersionsListing
|
||||
.trim()
|
||||
.split('\n')
|
||||
.forEach((line) => {
|
||||
const otpMatch = line.match(/^(OTP-)?([^ ]+)/)
|
||||
if (process.platform === 'linux') {
|
||||
otpVersionsListings
|
||||
.trim()
|
||||
.split('\n')
|
||||
.forEach((line) => {
|
||||
const otpMatch = line.match(/^(OTP-)?([^ ]+)/)
|
||||
|
||||
let otpVersion = otpMatch[2]
|
||||
if (semver.validRange(otpVersion)) {
|
||||
otpVersion = semver.minVersion(otpVersion).version
|
||||
}
|
||||
otpVersions.set(otpVersion, otpMatch[0]) // we keep the original for later reference
|
||||
let otpVersion = otpMatch[2]
|
||||
if (semver.validRange(otpVersion) && hasPatch(otpVersion)) {
|
||||
otpVersion = semver.minVersion(otpVersion).version
|
||||
}
|
||||
otpVersions.set(otpVersion, otpMatch[0]) // we keep the original for later reference
|
||||
})
|
||||
} else if (process.platform === 'win32') {
|
||||
otpVersionsListings.forEach((otpVersionsListing) => {
|
||||
JSON.parse(otpVersionsListing)
|
||||
.map((x) => x.assets)
|
||||
.flat()
|
||||
.filter((x) => x.name.match(/^otp_win64_.*.exe$/))
|
||||
.forEach((x) => {
|
||||
const otpMatch = x.name.match(/^otp_win64_(.*).exe$/)
|
||||
let otpVersion = otpMatch[1]
|
||||
if (semver.validRange(otpVersion) && hasPatch(otpVersion)) {
|
||||
otpVersion = semver.minVersion(otpVersion).version
|
||||
}
|
||||
otpVersions.set(otpVersion, otpVersion)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
return otpVersions
|
||||
}
|
||||
|
||||
async function getElixirVersions() {
|
||||
const elixirVersionsListing = await get(
|
||||
const elixirVersionsListings = await get(
|
||||
'https://repo.hex.pm/builds/elixir/builds.txt',
|
||||
[null],
|
||||
)
|
||||
const otpVersionsForElixirMap = new Map()
|
||||
|
||||
elixirVersionsListing
|
||||
elixirVersionsListings
|
||||
.trim()
|
||||
.split('\n')
|
||||
.forEach((line) => {
|
||||
@@ -4858,13 +4919,17 @@ async function getElixirVersions() {
|
||||
}
|
||||
|
||||
async function getRebar3Versions() {
|
||||
const resultJSON = await get(
|
||||
const resultJSONs = await get(
|
||||
'https://api.github.com/repos/erlang/rebar3/releases?per_page=100',
|
||||
[1, 2, 3],
|
||||
)
|
||||
const rebar3VersionsListing = JSON.parse(resultJSON)
|
||||
.map((x) => x.tag_name)
|
||||
.sort()
|
||||
|
||||
const rebar3VersionsListing = []
|
||||
resultJSONs.forEach((resultJSON) => {
|
||||
JSON.parse(resultJSON)
|
||||
.map((x) => x.tag_name)
|
||||
.sort()
|
||||
.forEach((v) => rebar3VersionsListing.push(v))
|
||||
})
|
||||
return rebar3VersionsListing
|
||||
}
|
||||
|
||||
@@ -4877,43 +4942,79 @@ function getVersionFromSpec(spec, versions) {
|
||||
}
|
||||
|
||||
function getRunnerOSVersion() {
|
||||
const mapToUbuntuVersion = {
|
||||
const ImageOSToContainer = {
|
||||
ubuntu16: 'ubuntu-16.04',
|
||||
ubuntu18: 'ubuntu-18.04',
|
||||
ubuntu20: 'ubuntu-20.04',
|
||||
win16: 'windows-2016',
|
||||
win19: 'windows-2019',
|
||||
}
|
||||
|
||||
return mapToUbuntuVersion[process.env.ImageOS] || 'ubuntu-18.04'
|
||||
return ImageOSToContainer[process.env.ImageOS]
|
||||
}
|
||||
|
||||
function get(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
https
|
||||
.get(
|
||||
url,
|
||||
{
|
||||
headers: { 'user-agent': 'setup-beam' },
|
||||
},
|
||||
(res) => {
|
||||
let data = ''
|
||||
res.on('data', (chunk) => {
|
||||
data += chunk
|
||||
})
|
||||
res.on('end', () => {
|
||||
resolve(data)
|
||||
})
|
||||
},
|
||||
)
|
||||
.on('error', (err) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
async function get(url0, pageIdxs) {
|
||||
function getPage(pageIdx) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const url = new URL(url0)
|
||||
if (pageIdx !== null) {
|
||||
url.searchParams.append('page', pageIdx)
|
||||
}
|
||||
https
|
||||
.get(
|
||||
url,
|
||||
{
|
||||
headers: { 'user-agent': 'setup-beam' },
|
||||
},
|
||||
(res) => {
|
||||
let data = ''
|
||||
res.on('data', (chunk) => {
|
||||
data += chunk
|
||||
})
|
||||
res.on('end', () => {
|
||||
if (res.statusCode >= 400 && res.statusCode <= 599) {
|
||||
reject(
|
||||
new Error(
|
||||
`Got ${res.statusCode} from ${url}. Exiting with error`,
|
||||
),
|
||||
)
|
||||
} else {
|
||||
resolve(data)
|
||||
}
|
||||
})
|
||||
},
|
||||
)
|
||||
.on('error', (err) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
let ret
|
||||
if (pageIdxs[0] === null) {
|
||||
ret = getPage(null)
|
||||
} else {
|
||||
ret = Promise.all(pageIdxs.map((pageIdx) => getPage(pageIdx)))
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
function prependToPath(what) {
|
||||
process.env.PATH = `${what}:${process.env.PATH}`
|
||||
if (process.platform === 'linux') {
|
||||
process.env.PATH = `${what}:${process.env.PATH}`
|
||||
} else if (process.platform === 'win32') {
|
||||
process.env.PATH = `${what};${process.env.PATH}`
|
||||
}
|
||||
}
|
||||
|
||||
function hasPatch(v) {
|
||||
try {
|
||||
semver.patch(v)
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
module.exports = {
|
||||
getOTPVersion,
|
||||
getElixirVersion,
|
||||
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
Write-Output "Installer for Elixir for Windows not available"
|
||||
|
||||
$ErrorActionPreference="Stop"
|
||||
|
||||
Exit 1
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
param([Parameter(Mandatory=$true)][string]$VSN)
|
||||
|
||||
$ErrorActionPreference="Stop"
|
||||
|
||||
Set-Location $Env:RUNNER_TEMP
|
||||
|
||||
$FILE_OUTPUT="otp.exe"
|
||||
$DIR_FOR_BIN=".setup-beam/otp"
|
||||
|
||||
Remove-Item -Recurse -Force "$DIR_FOR_BIN" -ErrorAction SilentlyContinue
|
||||
$ProgressPreference="SilentlyContinue"
|
||||
Invoke-WebRequest "https://github.com/erlang/otp/releases/download/OTP-$VSN/otp_win64_$VSN.exe" -OutFile "$FILE_OUTPUT"
|
||||
$ProgressPreference="Continue"
|
||||
New-Item "$DIR_FOR_BIN" -ItemType Directory | Out-Null
|
||||
Move-Item "$FILE_OUTPUT" "$DIR_FOR_BIN"
|
||||
Start-Process "./$DIR_FOR_BIN/$FILE_OUTPUT" /S -Wait
|
||||
Write-Output "C:/Program Files/erl-$VSN/bin" | Out-File -FilePath $Env:GITHUB_PATH -Encoding utf8 -Append
|
||||
Write-Output "Installed Erlang/OTP version follows"
|
||||
& "C:/Program Files/erl-$VSN/bin/erl.exe" "+V" | Write-Output
|
||||
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
param([Parameter(Mandatory=$true)][string]$VSN)
|
||||
|
||||
$ErrorActionPreference="Stop"
|
||||
|
||||
Set-Location $Env:RUNNER_TEMP
|
||||
|
||||
$FILE_INPUT="rebar3"
|
||||
$FILE_OUTPUT="rebar3"
|
||||
$FILE_OUTPUT_PS1="rebar3.ps1"
|
||||
$DIR_FOR_BIN=".setup-beam/rebar3"
|
||||
|
||||
Remove-Item -Force "$FILE_OUTPUT" -ErrorAction SilentlyContinue
|
||||
Remove-Item -Recurse -Force "$DIR_FOR_BIN" -ErrorAction SilentlyContinue
|
||||
$ProgressPreference="SilentlyContinue"
|
||||
Invoke-WebRequest "https://github.com/erlang/rebar3/releases/download/${VSN}/${FILE_INPUT}" -OutFile "$FILE_OUTPUT"
|
||||
$ProgressPreference="Continue"
|
||||
New-Item "$DIR_FOR_BIN/bin" -ItemType Directory | Out-Null
|
||||
Move-Item "$FILE_OUTPUT" "$DIR_FOR_BIN/bin"
|
||||
Write-Output "& escript.exe $PWD/$DIR_FOR_BIN/bin/$FILE_OUTPUT `$args" | Out-File -FilePath "$FILE_OUTPUT_PS1" -Encoding utf8 -Append
|
||||
type $FILE_OUTPUT_PS1
|
||||
Move-Item "$FILE_OUTPUT_PS1" "$DIR_FOR_BIN/bin"
|
||||
Write-Output "$PWD/$DIR_FOR_BIN/bin" | Out-File -FilePath $Env:GITHUB_PATH -Encoding utf8 -Append
|
||||
Write-Output "Installed rebar3 version follows"
|
||||
& "$DIR_FOR_BIN/bin/rebar3" "version" | Write-Output
|
||||
Reference in New Issue
Block a user