diff --git a/common.js b/common.js index 6f1c227..ec294dd 100644 --- a/common.js +++ b/common.js @@ -59,6 +59,18 @@ function findUbuntuVersion() { } } +export function shouldExtractInToolCache(engine, version) { + return engine === 'ruby' && !isHeadVersion(version) +} + +export function getToolCacheRubyPrefix(version) { + const toolCache = process.env['RUNNER_TOOL_CACHE'] + if (!toolCache) { + throw new Error('$RUNNER_TOOL_CACHE must be set') + } + return path.join(toolCache, 'Ruby', version, 'x64') +} + // convert windows path like C:\Users\runneradmin to /c/Users/runneradmin export function win2nix(path) { if (/^[A-Z]:/i.test(path)) { diff --git a/dist/index.js b/dist/index.js index 8a1760c..15b7411 100644 --- a/dist/index.js +++ b/dist/index.js @@ -27682,6 +27682,7 @@ const path = __webpack_require__(622) const cp = __webpack_require__(129) const core = __webpack_require__(186) const exec = __webpack_require__(514) +const io = __webpack_require__(436) const tc = __webpack_require__(188) const common = __webpack_require__(390) const rubyInstallerVersions = __webpack_require__(223).versions @@ -27711,7 +27712,13 @@ async function install(platform, engine, version) { } const base = url.slice(url.lastIndexOf('/') + 1, url.length - '.7z'.length) - const rubyPrefix = `${drive}:\\${base}` + let rubyPrefix + if (common.shouldExtractInToolCache(engine, version)) { + rubyPrefix = common.getToolCacheRubyPrefix(version) + } else { + rubyPrefix = `${drive}:\\${base}` + } + const parentDir = path.dirname(rubyPrefix) let toolchainPaths = (version === 'mswin') ? await setupMSWin() : await setupMingw(version) @@ -27723,7 +27730,11 @@ async function install(platform, engine, version) { }) await common.measure('Extracting Ruby', async () => - exec.exec('7z', ['x', downloadPath, `-xr!${base}\\share\\doc`, `-o${drive}:\\`], { silent: true })) + exec.exec('7z', ['x', downloadPath, `-xr!${base}\\share\\doc`, `-o${parentDir}`], { silent: true })) + + if (base !== path.basename(rubyPrefix)) { + await io.mv(path.join(parentDir, base), rubyPrefix) + } return rubyPrefix } @@ -32087,6 +32098,8 @@ __webpack_require__.r(__webpack_exports__); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isHeadVersion", function() { return isHeadVersion; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "hashFile", function() { return hashFile; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getVirtualEnvironmentName", function() { return getVirtualEnvironmentName; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "shouldExtractInToolCache", function() { return shouldExtractInToolCache; }); +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "getToolCacheRubyPrefix", function() { return getToolCacheRubyPrefix; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "win2nix", function() { return win2nix; }); /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "setupPath", function() { return setupPath; }); const os = __webpack_require__(87) @@ -32150,6 +32163,18 @@ function findUbuntuVersion() { } } +function shouldExtractInToolCache(engine, version) { + return engine === 'ruby' && !isHeadVersion(version) +} + +function getToolCacheRubyPrefix(version) { + const toolCache = process.env['RUNNER_TOOL_CACHE'] + if (!toolCache) { + throw new Error('$RUNNER_TOOL_CACHE must be set') + } + return path.join(toolCache, 'Ruby', version, 'x64') +} + // convert windows path like C:\Users\runneradmin to /c/Users/runneradmin function win2nix(path) { if (/^[A-Z]:/i.test(path)) { @@ -51155,7 +51180,7 @@ async function setupRuby(options = {}) { const [engine, parsedVersion] = parseRubyEngineAndVersion(inputs['ruby-version']) let installer - if (platform === 'windows-latest' && engine !== 'jruby') { + if (platform === 'windows-latest' && engine === 'ruby') { installer = __webpack_require__(216) } else { installer = __webpack_require__(974) @@ -51242,7 +51267,7 @@ function parseRubyEngineAndVersion(rubyVersion) { version = rubyVersion } else if (!rubyVersion.includes('-')) { // myruby -> myruby-stableVersion engine = rubyVersion - version = '' // Let the logic below find the version + version = '' // Let the logic in validateRubyEngineAndVersion() find the version } else { // engine-X.Y.Z [engine, version] = rubyVersion.split('-', 2) } @@ -51311,7 +51336,7 @@ function readBundledWithFromGemfileLock(lockFile) { } async function installBundler(bundlerVersionInput, lockFile, platform, rubyPrefix, engine, rubyVersion) { - var bundlerVersion = bundlerVersionInput + let bundlerVersion = bundlerVersionInput if (bundlerVersion === 'default' || bundlerVersion === 'Gemfile.lock') { bundlerVersion = readBundledWithFromGemfileLock(lockFile) @@ -52859,7 +52884,7 @@ const tc = __webpack_require__(188) const common = __webpack_require__(390) const rubyBuilderVersions = __webpack_require__(694) -const builderReleaseTag = 'enable-shared' +const builderReleaseTag = 'toolcache' const releasesURL = 'https://github.com/ruby/ruby-builder/releases' const windows = common.windows @@ -52873,14 +52898,22 @@ async function install(platform, engine, version) { } async function downloadAndExtract(platform, engine, version) { - const rubiesDir = windows ? `${common.drive}:` : path.join(os.homedir(), '.rubies') + 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 rubyPrefix = path.join(rubiesDir, `${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.mkdirP(rubiesDir) + await io.rmRF(rubyPrefix) + await io.mkdirP(parentDir) const downloadPath = await common.measure('Downloading Ruby', async () => { const url = getDownloadURL(platform, engine, version) @@ -52891,9 +52924,9 @@ async function downloadAndExtract(platform, engine, version) { 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(rubiesDir), '-f', common.win2nix(downloadPath) ]) + await exec.exec('tar', [ '-xz', '-C', common.win2nix(parentDir), '-f', common.win2nix(downloadPath) ]) } else { - await exec.exec('tar', [ '-xz', '-C', rubiesDir, '-f', downloadPath ]) + await exec.exec('tar', [ '-xz', '-C', parentDir, '-f', downloadPath ]) } }) diff --git a/index.js b/index.js index eb14ffe..e8288ed 100644 --- a/index.js +++ b/index.js @@ -39,7 +39,7 @@ export async function setupRuby(options = {}) { const [engine, parsedVersion] = parseRubyEngineAndVersion(inputs['ruby-version']) let installer - if (platform === 'windows-latest' && engine !== 'jruby') { + if (platform === 'windows-latest' && engine === 'ruby') { installer = require('./windows') } else { installer = require('./ruby-builder') @@ -126,7 +126,7 @@ function parseRubyEngineAndVersion(rubyVersion) { version = rubyVersion } else if (!rubyVersion.includes('-')) { // myruby -> myruby-stableVersion engine = rubyVersion - version = '' // Let the logic below find the version + version = '' // Let the logic in validateRubyEngineAndVersion() find the version } else { // engine-X.Y.Z [engine, version] = rubyVersion.split('-', 2) } @@ -195,7 +195,7 @@ function readBundledWithFromGemfileLock(lockFile) { } async function installBundler(bundlerVersionInput, lockFile, platform, rubyPrefix, engine, rubyVersion) { - var bundlerVersion = bundlerVersionInput + let bundlerVersion = bundlerVersionInput if (bundlerVersion === 'default' || bundlerVersion === 'Gemfile.lock') { bundlerVersion = readBundledWithFromGemfileLock(lockFile) diff --git a/ruby-builder.js b/ruby-builder.js index 79ce27f..1bb116c 100644 --- a/ruby-builder.js +++ b/ruby-builder.js @@ -7,7 +7,7 @@ const tc = require('@actions/tool-cache') const common = require('./common') const rubyBuilderVersions = require('./ruby-builder-versions') -const builderReleaseTag = 'enable-shared' +const builderReleaseTag = 'toolcache' const releasesURL = 'https://github.com/ruby/ruby-builder/releases' const windows = common.windows @@ -21,14 +21,22 @@ export async function install(platform, engine, version) { } async function downloadAndExtract(platform, engine, version) { - const rubiesDir = windows ? `${common.drive}:` : path.join(os.homedir(), '.rubies') + 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 rubyPrefix = path.join(rubiesDir, `${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.mkdirP(rubiesDir) + await io.rmRF(rubyPrefix) + await io.mkdirP(parentDir) const downloadPath = await common.measure('Downloading Ruby', async () => { const url = getDownloadURL(platform, engine, version) @@ -39,9 +47,9 @@ async function downloadAndExtract(platform, engine, version) { 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(rubiesDir), '-f', common.win2nix(downloadPath) ]) + await exec.exec('tar', [ '-xz', '-C', common.win2nix(parentDir), '-f', common.win2nix(downloadPath) ]) } else { - await exec.exec('tar', [ '-xz', '-C', rubiesDir, '-f', downloadPath ]) + await exec.exec('tar', [ '-xz', '-C', parentDir, '-f', downloadPath ]) } }) diff --git a/windows.js b/windows.js index 84af7f6..c5e3c49 100644 --- a/windows.js +++ b/windows.js @@ -6,6 +6,7 @@ const path = require('path') const cp = require('child_process') 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 rubyInstallerVersions = require('./windows-versions').versions @@ -35,7 +36,13 @@ export async function install(platform, engine, version) { } const base = url.slice(url.lastIndexOf('/') + 1, url.length - '.7z'.length) - const rubyPrefix = `${drive}:\\${base}` + let rubyPrefix + if (common.shouldExtractInToolCache(engine, version)) { + rubyPrefix = common.getToolCacheRubyPrefix(version) + } else { + rubyPrefix = `${drive}:\\${base}` + } + const parentDir = path.dirname(rubyPrefix) let toolchainPaths = (version === 'mswin') ? await setupMSWin() : await setupMingw(version) @@ -47,7 +54,11 @@ export async function install(platform, engine, version) { }) await common.measure('Extracting Ruby', async () => - exec.exec('7z', ['x', downloadPath, `-xr!${base}\\share\\doc`, `-o${drive}:\\`], { silent: true })) + exec.exec('7z', ['x', downloadPath, `-xr!${base}\\share\\doc`, `-o${parentDir}`], { silent: true })) + + if (base !== path.basename(rubyPrefix)) { + await io.mv(path.join(parentDir, base), rubyPrefix) + } return rubyPrefix }