mirror of
https://github.com/ruby/setup-ruby.git
synced 2026-09-13 14:34:21 +02:00
Get started
This commit is contained in:
@@ -1,21 +1,56 @@
|
||||
const core = require('@actions/core');
|
||||
const wait = require('./wait');
|
||||
const core = require('@actions/core')
|
||||
const io = require('@actions/io')
|
||||
const tc = require('@actions/tool-cache')
|
||||
const os = require('os')
|
||||
const fs = require('fs')
|
||||
|
||||
|
||||
// most @actions toolkit packages have async methods
|
||||
async function run() {
|
||||
try {
|
||||
const ms = core.getInput('milliseconds');
|
||||
console.log(`Waiting ${ms} milliseconds ...`)
|
||||
try {
|
||||
const rubyVersion = core.getInput('ruby-version')
|
||||
|
||||
core.debug((new Date()).toTimeString())
|
||||
wait(parseInt(ms));
|
||||
core.debug((new Date()).toTimeString())
|
||||
let ruby = rubyVersion
|
||||
if (!ruby.includes('-')) {
|
||||
ruby = 'ruby-' + ruby;
|
||||
}
|
||||
|
||||
core.setOutput('time', new Date().toTimeString());
|
||||
}
|
||||
catch (error) {
|
||||
core.setFailed(error.message);
|
||||
const rubiesDir = `${process.env.HOME}/.rubies`
|
||||
await io.mkdirP(rubiesDir)
|
||||
|
||||
const platform = getVirtualEnvironmentName()
|
||||
const url = `https://github.com/eregon/ruby-install-builder/releases/download/builds/${ruby}-${platform}.tar.gz`
|
||||
console.log(url)
|
||||
|
||||
const downloadPath = await tc.downloadTool(url)
|
||||
await tc.extractTar(downloadPath, rubiesDir)
|
||||
|
||||
const rubyPrefix = `${rubiesDir}/${ruby}`
|
||||
core.addPath(`${rubyPrefix}/bin`)
|
||||
core.setOutput('ruby-prefix', rubyPrefix)
|
||||
} catch (error) {
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
function getVirtualEnvironmentName() {
|
||||
const platform = os.platform()
|
||||
if (platform == 'linux') {
|
||||
return `ubuntu-${findUbuntuVersion()}`
|
||||
} else if (platform == 'darwin') {
|
||||
return 'macos-latest'
|
||||
} else if (platform == 'win32') {
|
||||
return 'windows-latest'
|
||||
} else {
|
||||
throw new Error(`Unknown platform ${platform}`)
|
||||
}
|
||||
}
|
||||
|
||||
function findUbuntuVersion() {
|
||||
const lsb_release = fs.readFileSync('/etc/lsb-release', 'utf8')
|
||||
const match = lsb_release.match(/^DISTRIB_RELEASE=(\d+\.\d+)$/m)
|
||||
if (match) {
|
||||
return match[1]
|
||||
} else {
|
||||
throw new Error('Could not find Ubuntu version')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user