generated from actions/javascript-action
-
-
Notifications
You must be signed in to change notification settings - Fork 312
/
Copy pathruby-builder.js
69 lines (56 loc) · 2.28 KB
/
ruby-builder.js
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const os = require('os')
const path = require('path')
const core = require('@actions/core')
const exec = require('@actions/exec')
const io = require('@actions/io')
const tc = require('@actions/tool-cache')
const common = require('./common')
const rubyBuilderVersions = require('./ruby-builder-versions')
const builderReleaseTag = 'toolcache'
const releasesURL = 'https://github.com/ruby/ruby-builder/releases'
const windows = common.windows
export function getAvailableVersions(platform, engine) {
return rubyBuilderVersions.getVersions(platform)[engine]
}
export async function install(platform, engine, version) {
return await downloadAndExtract(platform, engine, version)
}
async function downloadAndExtract(platform, engine, version) {
let rubyPrefix
if (common.shouldExtractInToolCache(engine, version)) {
rubyPrefix = common.getToolCacheRubyPrefix(version)
} else if (windows) {
rubyPrefix = path.join(`${common.drive}:`, `${engine}-${version}`)
} else {
rubyPrefix = path.join(os.homedir(), '.rubies', `${engine}-${version}`)
}
const parentDir = path.dirname(rubyPrefix)
// Set the PATH now, so the MSYS2 'tar' is in Path on Windows
common.setupPath([path.join(rubyPrefix, 'bin')])
await io.rmRF(rubyPrefix)
await io.mkdirP(parentDir)
const downloadPath = await common.measure('Downloading Ruby', async () => {
const url = getDownloadURL(platform, engine, version)
console.log(url)
return await tc.downloadTool(url)
})
await common.measure('Extracting Ruby', async () => {
if (windows) {
// Windows 2016 doesn't have system tar, use MSYS2's, it needs unix style paths
await exec.exec('tar', [ '-xz', '-C', common.win2nix(parentDir), '-f', common.win2nix(downloadPath) ])
} else {
await exec.exec('tar', [ '-xz', '-C', parentDir, '-f', downloadPath ])
}
})
return rubyPrefix
}
function getDownloadURL(platform, engine, version) {
if (common.isHeadVersion(version)) {
return getLatestHeadBuildURL(platform, engine, version)
} else {
return `${releasesURL}/download/${builderReleaseTag}/${engine}-${version}-${platform}.tar.gz`
}
}
function getLatestHeadBuildURL(platform, engine, version) {
return `https://github.com/ruby/${engine}-dev-builder/releases/latest/download/${engine}-${version}-${platform}.tar.gz`
}