Uh oh!
There was an error while loading. Please reload this page.
forked from ruby/setup-ruby
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathruby-builder.js
More file actions
Latest commit
130 lines (112 loc) · 4.72 KB
/
Copy pathruby-builder.js
File metadata and controls
130 lines (112 loc) · 4.72 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
constos=require('os')
constfs=require('fs')
constpath=require('path')
constcore=require('@actions/core')
constexec=require('@actions/exec')
constio=require('@actions/io')
constcommon=require('./common')
construbyBuilderVersions=require('./ruby-builder-versions')
constreleasesURL='https://github.com/ruby/ruby-builder/releases'
constwindows=common.windows
exportfunctiongetAvailableVersions(platform,engine){
returnrubyBuilderVersions[engine]
}
exportasyncfunctioninstall(platform,engine,version){
letrubyPrefix,inToolCache
if(common.shouldUseToolCache(engine,version)){
inToolCache=common.toolCacheFind(engine,version)
if(inToolCache){
rubyPrefix=inToolCache
}else{
consttoolCacheRubyPrefix=common.getToolCacheRubyPrefix(platform,engine,version)
if(common.isSelfHostedRunner()){
construbyBuildDefinition=engine==='ruby' ? version : `${engine}-${version}`
core.error(
`The current runner (${common.getOSNameVersionArch()}) was detected as self-hosted because ${common.selfHostedRunnerReason()}.\n`+
`In such a case, you should install Ruby in the $RUNNER_TOOL_CACHE yourself, for example using https://github.com/rbenv/ruby-build\n`+
`You can take inspiration from this workflow for more details: https://github.com/ruby/ruby-builder/blob/master/.github/workflows/build.yml\n`+
`$ ruby-build ${rubyBuildDefinition}${toolCacheRubyPrefix}\n`+
`Once that completes successfully, mark it as complete with:\n`+
`$ touch ${common.toolCacheCompleteFile(toolCacheRubyPrefix)}\n`+
`It is your responsibility to ensure installing Ruby like that is not done in parallel.\n`)
process.exit(1)
}else{
rubyPrefix=toolCacheRubyPrefix
}
}
}elseif(windows){
rubyPrefix=path.join(`${common.drive}:`,`${engine}-${version}`)
}else{
rubyPrefix=path.join(os.homedir(),'.rubies',`${engine}-${version}`)
}
constpaths=[path.join(rubyPrefix,'bin')]
// JRuby can use compiled extension code via ffi, so make sure gcc exists.
if(platform.startsWith('windows')&&engine==='jruby'){
paths.push(...awaitrequire('./windows').installJRubyTools())
}
// Set the PATH now, so the MSYS2 'tar' is in Path on Windows
common.setupPath(paths)
if(!inToolCache){
awaitio.mkdirP(rubyPrefix)
awaitdownloadAndExtract(platform,engine,version,rubyPrefix)
}
// Ensure JRuby has minimum Java version to run
if(engine==="jruby"){
awaitcommon.setupJavaHome(rubyPrefix)
}
returnrubyPrefix
}
asyncfunctiondownloadAndExtract(platform,engine,version,rubyPrefix){
constparentDir=path.dirname(rubyPrefix)
constdownloadPath=awaitcommon.measure('Downloading Ruby',async()=>{
consturl=getDownloadURL(platform,engine,version)
console.log(url)
try{
returnawaitcommon.download(url)
}catch(error){
if(error.message.includes('404')){
thrownewError(`Unavailable version ${version} for ${engine} on ${platform}
You can request it at https://github.com/ruby/setup-ruby/issues
Cause: ${error.message}`)
}else{
throwerror
}
}
})
awaitcommon.measure('Extracting Ruby',async()=>{
if(windows){
// Windows 2016 doesn't have system tar, use MSYS2's, it needs unix style paths
awaitexec.exec('tar',['-xz','-C',common.win2nix(parentDir),'-f',common.win2nix(downloadPath)])
}else{
awaitexec.exec('tar',['-xz','-C',parentDir,'-f',downloadPath])
}
})
if(common.shouldUseToolCache(engine,version)){
common.createToolCacheCompleteFile(rubyPrefix)
}
}
functiongetDownloadURL(platform,engine,version){
letbuilderPlatform=null
if(platform.startsWith('windows-')){
builderPlatform=`windows-${os.arch()}`
}elseif(platform.startsWith('macos-')){
builderPlatform=`darwin-${os.arch()}`
}elseif(platform.startsWith('ubuntu-')){
builderPlatform=`${platform}-${os.arch()}`
}
if(builderPlatform===null||!['x64','arm64'].includes(os.arch())){
thrownewError(`Unknown download URL for platform ${platform}-${os.arch()}`)
}
if(common.isHeadVersion(version)){
returngetLatestHeadBuildURL(builderPlatform,engine,version)
}else{
return`${releasesURL}/download/${engine}-${version}/${engine}-${version}-${builderPlatform}.tar.gz`
}
}
functiongetLatestHeadBuildURL(platform,engine,version){
varrepo=`${engine}-dev-builder`
if(engine==='truffleruby+graalvm'){
repo='truffleruby-dev-builder'
}
return`https://github.com/ruby/${repo}/releases/latest/download/${engine}-${version}-${platform}.tar.gz`
}