forked from ruby/setup-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruby-builder.js
More file actions
51 lines (42 loc) · 1.68 KB
/
ruby-builder.js
File metadata and controls
51 lines (42 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const os = require('os')
const path = require('path')
const exec = require('@actions/exec')
const io = require('@actions/io')
const tc = require('@actions/tool-cache')
const rubyBuilderVersions = require('./ruby-builder-versions')
const builderReleaseTag = 'builds-no-warn'
const releasesURL = 'https://github.com/ruby/ruby-builder/releases'
export function getAvailableVersions(platform, engine) {
return rubyBuilderVersions.getVersions(platform)[engine]
}
export async function install(platform, ruby) {
const rubyPrefix = await downloadAndExtract(platform, ruby)
let newPathEntries;
if (ruby.startsWith('rubinius')) {
newPathEntries = [path.join(rubyPrefix, 'bin'), path.join(rubyPrefix, 'gems', 'bin')]
} else {
newPathEntries = [path.join(rubyPrefix, 'bin')]
}
return [rubyPrefix, newPathEntries]
}
async function downloadAndExtract(platform, ruby) {
const rubiesDir = path.join(os.homedir(), '.rubies')
await io.mkdirP(rubiesDir)
const url = await getDownloadURL(platform, ruby)
console.log(url)
const downloadPath = await tc.downloadTool(url)
const tar = platform.startsWith('windows') ? 'C:\\Windows\\system32\\tar.exe' : 'tar'
await exec.exec(tar, [ '-xz', '-C', rubiesDir, '-f', downloadPath ])
return path.join(rubiesDir, ruby)
}
function getDownloadURL(platform, ruby) {
if (ruby.endsWith('-head')) {
return getLatestHeadBuildURL(platform, ruby)
} else {
return `${releasesURL}/download/${builderReleaseTag}/${ruby}-${platform}.tar.gz`
}
}
function getLatestHeadBuildURL(platform, ruby) {
const engine = ruby.split('-')[0]
return `https://github.com/ruby/${engine}-dev-builder/releases/latest/download/${engine}-head-${platform}.tar.gz`
}