forked from ruby/setup-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
windows.js
68 lines (52 loc) · 2.12 KB
/
windows.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
// Most of this logic is from
// https://github.com/MSP-Greg/actions-ruby/blob/master/lib/main.js
const fs = require('fs')
const core = require('@actions/core')
const exec = require('@actions/exec')
const tc = require('@actions/tool-cache')
const releasesURL = 'https://github.com/oneclick/rubyinstaller2/releases'
export async function downloadExtractAndSetPATH(ruby) {
const version = ruby.split('-', 2)[1]
if (!ruby.startsWith('ruby-') || version.startsWith('2.3')) {
throw new Error(`Only ruby >= 2.4 is supported on Windows currently (input: ${ruby})`)
}
const tag = `RubyInstaller-${version}-1`
const base = `${tag.toLowerCase()}-x64`
const url = `${releasesURL}/download/${tag}/${base}.7z`
console.log(url)
const downloadPath = await tc.downloadTool(url)
await exec.exec(`7z x ${downloadPath} -xr!${base}\\share\\doc -oC:\\`)
const rubyPrefix = `C:\\${base}`
const msys2 = await linkMSYS2()
const newPath = setupPath(msys2, rubyPrefix)
core.exportVariable('PATH', newPath)
if (!fs.existsSync(`${rubyPrefix}\\bin\\bundle.cmd`)) {
await exec.exec(`${rubyPrefix}\\bin\\gem install bundler -v "~> 1" --no-document`)
}
return rubyPrefix
}
async function linkMSYS2() {
const toolCacheVersions = tc.findAllVersions('Ruby')
toolCacheVersions.sort()
if (toolCacheVersions.length == 0) {
throw new Error('Could not find MSYS2 in the toolcache')
}
const latestVersion = toolCacheVersions.slice(-1)[0]
const latestHostedRuby = tc.find('Ruby', latestVersion)
const hostedMSYS2 = `${latestHostedRuby}\\msys64`
const msys2 = 'C:\\msys64'
await exec.exec(`cmd /c mklink /D ${msys2} ${hostedMSYS2}`)
return msys2
}
function setupPath(msys2, rubyPrefix) {
let path = process.env['PATH'].split(';')
// Remove conflicting dev tools from PATH
path = path.filter(e => !e.match(/\b(Chocolatey|CMake|mingw64|OpenSSL|Strawberry)\b/))
// Remove default Ruby in PATH
path = path.filter(e => !e.match(/\bRuby\b/))
// Add MSYS2 in PATH
path.unshift(`${msys2}\\mingw64\\bin`, `${msys2}\\usr\\bin`)
// Add the downloaded Ruby in PATH
path.unshift(`${rubyPrefix}\\bin`)
return path.join(';')
}