Skip to content

Commit e5857db

Browse files
committed
Pass the validated engine and version to install()
1 parent 381e263 commit e5857db

File tree

5 files changed

+57
-58
lines changed

5 files changed

+57
-58
lines changed

common.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ export async function measure(name, block) {
1616
})
1717
}
1818

19+
export function isHeadVersion(rubyVersion) {
20+
return rubyVersion === 'head' || rubyVersion === 'mingw' || rubyVersion === 'mswin'
21+
}
22+
1923
export function getVirtualEnvironmentName() {
2024
const platform = os.platform()
2125
if (platform === 'linux') {

dist/index.js

Lines changed: 29 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async function main() {
1717
process.chdir(core.getInput('working-directory'))
1818

1919
const platform = common.getVirtualEnvironmentName()
20-
const [engine, version] = parseRubyEngineAndVersion(core.getInput('ruby-version'))
20+
const [engine, parsedVersion] = parseRubyEngineAndVersion(core.getInput('ruby-version'))
2121

2222
let installer
2323
if (platform === 'windows-latest' && engine !== 'jruby') {
@@ -27,13 +27,13 @@ async function main() {
2727
}
2828

2929
const engineVersions = installer.getAvailableVersions(platform, engine)
30-
const ruby = validateRubyEngineAndVersion(platform, engineVersions, engine, version)
30+
const version = validateRubyEngineAndVersion(platform, engineVersions, engine, parsedVersion)
3131

3232
createGemRC()
3333

34-
const [rubyPrefix, newPathEntries] = await installer.install(platform, ruby)
34+
const [rubyPrefix, newPathEntries] = await installer.install(platform, engine, version)
3535

36-
setupPath(ruby, newPathEntries)
36+
setupPath(newPathEntries)
3737

3838
if (core.getInput('bundler') !== 'none') {
3939
await common.measure('Installing Bundler', async () =>
@@ -78,24 +78,25 @@ function parseRubyEngineAndVersion(rubyVersion) {
7878
return [engine, version]
7979
}
8080

81-
function validateRubyEngineAndVersion(platform, engineVersions, engine, version) {
81+
function validateRubyEngineAndVersion(platform, engineVersions, engine, parsedVersion) {
8282
if (!engineVersions) {
8383
throw new Error(`Unknown engine ${engine} on ${platform}`)
8484
}
8585

86-
if (!engineVersions.includes(version)) {
86+
let version = parsedVersion
87+
if (!engineVersions.includes(parsedVersion)) {
8788
const latestToFirstVersion = engineVersions.slice().reverse()
88-
const found = latestToFirstVersion.find(v => v !== 'head' && v.startsWith(version))
89+
const found = latestToFirstVersion.find(v => v !== 'head' && v.startsWith(parsedVersion))
8990
if (found) {
9091
version = found
9192
} else {
92-
throw new Error(`Unknown version ${version} for ${engine} on ${platform}
93+
throw new Error(`Unknown version ${parsedVersion} for ${engine} on ${platform}
9394
available versions for ${engine} on ${platform}: ${engineVersions.join(', ')}
9495
File an issue at https://github.com/ruby/setup-ruby/issues if would like support for a new version`)
9596
}
9697
}
9798

98-
return engine + '-' + version
99+
return version
99100
}
100101

101102
function createGemRC() {
@@ -105,7 +106,7 @@ function createGemRC() {
105106
}
106107
}
107108

108-
function setupPath(ruby, newPathEntries) {
109+
function setupPath(newPathEntries) {
109110
const originalPath = process.env['PATH'].split(path.delimiter)
110111
let cleanPath = originalPath.filter(entry => !/\bruby\b/i.test(entry))
111112

@@ -164,7 +165,7 @@ async function installBundler(platform, rubyPrefix, engine, rubyVersion) {
164165
throw new Error(`Cannot parse bundler input: ${bundlerVersion}`)
165166
}
166167

167-
if (engine === 'ruby' && isHeadVersion(rubyVersion) && bundlerVersion === '2') {
168+
if (engine === 'ruby' && common.isHeadVersion(rubyVersion) && bundlerVersion === '2') {
168169
console.log(`Using Bundler 2 shipped with ${engine}-${rubyVersion}`)
169170
} else if (engine === 'truffleruby' && bundlerVersion === '1') {
170171
console.log(`Using Bundler 1 shipped with ${engine}`)
@@ -176,8 +177,4 @@ async function installBundler(platform, rubyPrefix, engine, rubyVersion) {
176177
}
177178
}
178179

179-
function isHeadVersion(rubyVersion) {
180-
return rubyVersion === 'head' || rubyVersion === 'mingw' || rubyVersion === 'mswin'
181-
}
182-
183180
if (__filename.endsWith('index.js')) { run() }

ruby-builder.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@ export function getAvailableVersions(platform, engine) {
1313
return rubyBuilderVersions.getVersions(platform)[engine]
1414
}
1515

16-
export async function install(platform, ruby) {
17-
const rubyPrefix = await downloadAndExtract(platform, ruby)
16+
export async function install(platform, engine, version) {
17+
const rubyPrefix = await downloadAndExtract(platform, engine, version)
1818
let newPathEntries
19-
if (ruby.startsWith('rubinius')) {
19+
if (engine === 'rubinius') {
2020
newPathEntries = [path.join(rubyPrefix, 'bin'), path.join(rubyPrefix, 'gems', 'bin')]
2121
} else {
2222
newPathEntries = [path.join(rubyPrefix, 'bin')]
2323
}
2424
return [rubyPrefix, newPathEntries]
2525
}
2626

27-
async function downloadAndExtract(platform, ruby) {
27+
async function downloadAndExtract(platform, engine, version) {
2828
const rubiesDir = path.join(os.homedir(), '.rubies')
2929
await io.mkdirP(rubiesDir)
3030

3131
const downloadPath = await common.measure('Downloading Ruby', async () => {
32-
const url = getDownloadURL(platform, ruby)
32+
const url = getDownloadURL(platform, engine, version)
3333
console.log(url)
3434
return await tc.downloadTool(url)
3535
})
@@ -38,18 +38,17 @@ async function downloadAndExtract(platform, ruby) {
3838
await common.measure('Extracting Ruby', async () =>
3939
exec.exec(tar, [ '-xz', '-C', rubiesDir, '-f', downloadPath ]))
4040

41-
return path.join(rubiesDir, ruby)
41+
return path.join(rubiesDir, `${engine}-${version}`)
4242
}
4343

44-
function getDownloadURL(platform, ruby) {
45-
if (ruby.endsWith('-head')) {
46-
return getLatestHeadBuildURL(platform, ruby)
44+
function getDownloadURL(platform, engine, version) {
45+
if (common.isHeadVersion(version)) {
46+
return getLatestHeadBuildURL(platform, engine, version)
4747
} else {
48-
return `${releasesURL}/download/${builderReleaseTag}/${ruby}-${platform}.tar.gz`
48+
return `${releasesURL}/download/${builderReleaseTag}/${engine}-${version}-${platform}.tar.gz`
4949
}
5050
}
5151

52-
function getLatestHeadBuildURL(platform, ruby) {
53-
const engine = ruby.split('-')[0]
52+
function getLatestHeadBuildURL(platform, engine, version) {
5453
return `https://github.com/ruby/${engine}-dev-builder/releases/latest/download/${engine}-head-${platform}.tar.gz`
5554
}

windows.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ export function getAvailableVersions(platform, engine) {
3333
}
3434
}
3535

36-
export async function install(platform, ruby) {
37-
const version = ruby.split('-', 2)[1]
36+
export async function install(platform, engine, version) {
3837
const url = rubyInstallerVersions[version]
3938

4039
if (!url.endsWith('.7z')) {

0 commit comments

Comments
 (0)