mirror of
https://github.com/ruby/setup-ruby.git
synced 2026-09-13 14:34:21 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
31a7f6d628 | ||
|
|
59b5745c73 | ||
|
|
d03a71de6e | ||
|
|
ddde3938f5 | ||
|
|
5a73aa9f67 | ||
|
|
d01c52ad8b | ||
|
|
377a94bc68 |
@@ -30,6 +30,11 @@ inputs:
|
||||
description: |
|
||||
Arbitrary string that will be added to the cache key of the bundler cache. Set or change it if you need
|
||||
to invalidate the cache.
|
||||
self-hosted:
|
||||
description: |
|
||||
Consider the runner as a self-hosted runner, which means not using prebuilt Ruby binaries which only work
|
||||
on GitHub-hosted runners or self-hosted runners with a very similar image to the ones used by GitHub runners.
|
||||
The default is to detect this automatically based on the OS, OS version and $RUNNER_TOOL_CACHE.
|
||||
outputs:
|
||||
ruby-prefix:
|
||||
description: 'The prefix of the installed ruby'
|
||||
|
||||
@@ -5,6 +5,7 @@ const util = require('util')
|
||||
const stream = require('stream')
|
||||
const crypto = require('crypto')
|
||||
const core = require('@actions/core')
|
||||
const tc = require('@actions/tool-cache')
|
||||
const { performance } = require('perf_hooks')
|
||||
const linuxOSInfo = require('linux-os-info')
|
||||
import macosRelease from 'macos-release'
|
||||
@@ -13,6 +14,10 @@ export const windows = (os.platform() === 'win32')
|
||||
// Extract to SSD on Windows, see https://github.com/ruby/setup-ruby/pull/14
|
||||
export const drive = (windows ? (process.env['GITHUB_WORKSPACE'] || 'C')[0] : undefined)
|
||||
|
||||
export const inputs = {
|
||||
selfHosted: undefined
|
||||
}
|
||||
|
||||
export function partition(string, separator) {
|
||||
const i = string.indexOf(separator)
|
||||
if (i === -1) {
|
||||
@@ -162,9 +167,24 @@ const GitHubHostedPlatforms = [
|
||||
'windows-2022-x64',
|
||||
]
|
||||
|
||||
// Actually a self-hosted runner which does not correspond to a GitHub-hosted runner image
|
||||
// Actually a self-hosted runner for which the OS and OS version does not correspond to a GitHub-hosted runner image,
|
||||
export function isSelfHostedRunner() {
|
||||
return !GitHubHostedPlatforms.includes(getOSNameVersionArch())
|
||||
if (inputs.selfHosted === undefined) {
|
||||
throw new Error('inputs.selfHosted should have been already set')
|
||||
}
|
||||
|
||||
return inputs.selfHosted === 'true' ||
|
||||
!GitHubHostedPlatforms.includes(getOSNameVersionArch())
|
||||
}
|
||||
|
||||
export function selfHostedRunnerReason() {
|
||||
if (inputs.selfHosted === 'true') {
|
||||
return 'the self-hosted input was set'
|
||||
} else if (!GitHubHostedPlatforms.includes(getOSNameVersionArch())) {
|
||||
return 'the platform does not match a GitHub-hosted runner image (or that image is deprecated and no longer supported)'
|
||||
} else {
|
||||
return 'unknown reason'
|
||||
}
|
||||
}
|
||||
|
||||
let virtualEnvironmentName = undefined
|
||||
@@ -213,35 +233,61 @@ export function shouldUseToolCache(engine, version) {
|
||||
return (engine === 'ruby' && !isHeadVersion(version)) || isSelfHostedRunner()
|
||||
}
|
||||
|
||||
function getPlatformToolCache(platform) {
|
||||
export function getToolCachePath() {
|
||||
if (isSelfHostedRunner()) {
|
||||
const runnerToolCache = process.env['RUNNER_TOOL_CACHE']
|
||||
if (!runnerToolCache) {
|
||||
throw new Error('$RUNNER_TOOL_CACHE must be set on self-hosted runners')
|
||||
}
|
||||
return runnerToolCache
|
||||
return getRunnerToolCache()
|
||||
} else {
|
||||
// Rubies prebuilt by this action embed this path rather than using $RUNNER_TOOL_CACHE
|
||||
// so use that path is not isSelfHostedRunner()
|
||||
return getDefaultToolCachePath()
|
||||
}
|
||||
// Hardcode paths rather than using $RUNNER_TOOL_CACHE because the prebuilt Rubies cannot be moved anyway
|
||||
}
|
||||
|
||||
export function getRunnerToolCache() {
|
||||
const runnerToolCache = process.env['RUNNER_TOOL_CACHE']
|
||||
if (!runnerToolCache) {
|
||||
throw new Error('$RUNNER_TOOL_CACHE must be set')
|
||||
}
|
||||
return runnerToolCache
|
||||
}
|
||||
|
||||
// Rubies prebuilt by this action embed this path rather than using $RUNNER_TOOL_CACHE
|
||||
function getDefaultToolCachePath() {
|
||||
const platform = getVirtualEnvironmentName()
|
||||
if (platform.startsWith('ubuntu-')) {
|
||||
return '/opt/hostedtoolcache'
|
||||
} else if (platform.startsWith('macos-')) {
|
||||
return '/Users/runner/hostedtoolcache'
|
||||
} else if (platform.startsWith('windows-')) {
|
||||
return 'C:/hostedtoolcache/windows'
|
||||
return 'C:\\hostedtoolcache\\windows'
|
||||
} else {
|
||||
throw new Error('Unknown platform')
|
||||
}
|
||||
}
|
||||
|
||||
export function getToolCacheRubyPrefix(platform, engine, version) {
|
||||
const toolCache = getPlatformToolCache(platform)
|
||||
const name = {
|
||||
// tc.find() but using RUNNER_TOOL_CACHE=getToolCachePath()
|
||||
export function toolCacheFind(engine, version) {
|
||||
const originalToolCache = getToolCachePath()
|
||||
process.env['RUNNER_TOOL_CACHE'] = getToolCachePath()
|
||||
try {
|
||||
return tc.find(engineToToolCacheName(engine), version)
|
||||
} finally {
|
||||
process.env['RUNNER_TOOL_CACHE'] = originalToolCache
|
||||
}
|
||||
}
|
||||
|
||||
function engineToToolCacheName(engine) {
|
||||
return {
|
||||
ruby: 'Ruby',
|
||||
jruby: 'JRuby',
|
||||
truffleruby: 'TruffleRuby',
|
||||
"truffleruby+graalvm": 'TruffleRubyGraalVM'
|
||||
}[engine]
|
||||
return path.join(toolCache, name, version, os.arch())
|
||||
}
|
||||
|
||||
export function getToolCacheRubyPrefix(platform, engine, version) {
|
||||
const toolCache = getToolCachePath()
|
||||
return path.join(toolCache, engineToToolCacheName(engine), version, os.arch())
|
||||
}
|
||||
|
||||
export function toolCacheCompleteFile(toolCacheRubyPrefix) {
|
||||
|
||||
+72
-28
@@ -291,10 +291,13 @@ __nccwpck_require__.d(__webpack_exports__, {
|
||||
"drive": () => (/* binding */ drive),
|
||||
"floatVersion": () => (/* binding */ floatVersion),
|
||||
"getOSNameVersionArch": () => (/* binding */ getOSNameVersionArch),
|
||||
"getRunnerToolCache": () => (/* binding */ getRunnerToolCache),
|
||||
"getToolCachePath": () => (/* binding */ getToolCachePath),
|
||||
"getToolCacheRubyPrefix": () => (/* binding */ getToolCacheRubyPrefix),
|
||||
"getVirtualEnvironmentName": () => (/* binding */ getVirtualEnvironmentName),
|
||||
"hasBundlerDefaultGem": () => (/* binding */ hasBundlerDefaultGem),
|
||||
"hashFile": () => (/* binding */ hashFile),
|
||||
"inputs": () => (/* binding */ inputs),
|
||||
"isBundler1Default": () => (/* binding */ isBundler1Default),
|
||||
"isBundler2Default": () => (/* binding */ isBundler2Default),
|
||||
"isBundler2dot2Default": () => (/* binding */ isBundler2dot2Default),
|
||||
@@ -303,11 +306,13 @@ __nccwpck_require__.d(__webpack_exports__, {
|
||||
"isStableVersion": () => (/* binding */ isStableVersion),
|
||||
"measure": () => (/* binding */ measure),
|
||||
"partition": () => (/* binding */ partition),
|
||||
"selfHostedRunnerReason": () => (/* binding */ selfHostedRunnerReason),
|
||||
"setupPath": () => (/* binding */ setupPath),
|
||||
"shouldUseToolCache": () => (/* binding */ shouldUseToolCache),
|
||||
"targetRubyVersion": () => (/* binding */ targetRubyVersion),
|
||||
"time": () => (/* binding */ time),
|
||||
"toolCacheCompleteFile": () => (/* binding */ toolCacheCompleteFile),
|
||||
"toolCacheFind": () => (/* binding */ toolCacheFind),
|
||||
"win2nix": () => (/* binding */ win2nix),
|
||||
"windows": () => (/* binding */ windows)
|
||||
});
|
||||
@@ -357,6 +362,7 @@ const util = __nccwpck_require__(3837)
|
||||
const stream = __nccwpck_require__(2781)
|
||||
const common_crypto = __nccwpck_require__(6113)
|
||||
const core = __nccwpck_require__(2186)
|
||||
const tc = __nccwpck_require__(7784)
|
||||
const { performance } = __nccwpck_require__(4074)
|
||||
const linuxOSInfo = __nccwpck_require__(8487)
|
||||
;
|
||||
@@ -365,6 +371,10 @@ const windows = (os.platform() === 'win32')
|
||||
// Extract to SSD on Windows, see https://github.com/ruby/setup-ruby/pull/14
|
||||
const drive = (windows ? (process.env['GITHUB_WORKSPACE'] || 'C')[0] : undefined)
|
||||
|
||||
const inputs = {
|
||||
selfHosted: undefined
|
||||
}
|
||||
|
||||
function partition(string, separator) {
|
||||
const i = string.indexOf(separator)
|
||||
if (i === -1) {
|
||||
@@ -514,9 +524,24 @@ const GitHubHostedPlatforms = [
|
||||
'windows-2022-x64',
|
||||
]
|
||||
|
||||
// Actually a self-hosted runner which does not correspond to a GitHub-hosted runner image
|
||||
// Actually a self-hosted runner for which the OS and OS version does not correspond to a GitHub-hosted runner image,
|
||||
function isSelfHostedRunner() {
|
||||
return !GitHubHostedPlatforms.includes(getOSNameVersionArch())
|
||||
if (inputs.selfHosted === undefined) {
|
||||
throw new Error('inputs.selfHosted should have been already set')
|
||||
}
|
||||
|
||||
return inputs.selfHosted === 'true' ||
|
||||
!GitHubHostedPlatforms.includes(getOSNameVersionArch())
|
||||
}
|
||||
|
||||
function selfHostedRunnerReason() {
|
||||
if (inputs.selfHosted === 'true') {
|
||||
return 'the self-hosted input was set'
|
||||
} else if (!GitHubHostedPlatforms.includes(getOSNameVersionArch())) {
|
||||
return 'the platform does not match a GitHub-hosted runner image (or that image is deprecated and no longer supported)'
|
||||
} else {
|
||||
return 'unknown reason'
|
||||
}
|
||||
}
|
||||
|
||||
let virtualEnvironmentName = undefined
|
||||
@@ -565,35 +590,61 @@ function shouldUseToolCache(engine, version) {
|
||||
return (engine === 'ruby' && !isHeadVersion(version)) || isSelfHostedRunner()
|
||||
}
|
||||
|
||||
function getPlatformToolCache(platform) {
|
||||
function getToolCachePath() {
|
||||
if (isSelfHostedRunner()) {
|
||||
const runnerToolCache = process.env['RUNNER_TOOL_CACHE']
|
||||
if (!runnerToolCache) {
|
||||
throw new Error('$RUNNER_TOOL_CACHE must be set on self-hosted runners')
|
||||
}
|
||||
return runnerToolCache
|
||||
return getRunnerToolCache()
|
||||
} else {
|
||||
// Rubies prebuilt by this action embed this path rather than using $RUNNER_TOOL_CACHE
|
||||
// so use that path is not isSelfHostedRunner()
|
||||
return getDefaultToolCachePath()
|
||||
}
|
||||
// Hardcode paths rather than using $RUNNER_TOOL_CACHE because the prebuilt Rubies cannot be moved anyway
|
||||
}
|
||||
|
||||
function getRunnerToolCache() {
|
||||
const runnerToolCache = process.env['RUNNER_TOOL_CACHE']
|
||||
if (!runnerToolCache) {
|
||||
throw new Error('$RUNNER_TOOL_CACHE must be set')
|
||||
}
|
||||
return runnerToolCache
|
||||
}
|
||||
|
||||
// Rubies prebuilt by this action embed this path rather than using $RUNNER_TOOL_CACHE
|
||||
function getDefaultToolCachePath() {
|
||||
const platform = getVirtualEnvironmentName()
|
||||
if (platform.startsWith('ubuntu-')) {
|
||||
return '/opt/hostedtoolcache'
|
||||
} else if (platform.startsWith('macos-')) {
|
||||
return '/Users/runner/hostedtoolcache'
|
||||
} else if (platform.startsWith('windows-')) {
|
||||
return 'C:/hostedtoolcache/windows'
|
||||
return 'C:\\hostedtoolcache\\windows'
|
||||
} else {
|
||||
throw new Error('Unknown platform')
|
||||
}
|
||||
}
|
||||
|
||||
function getToolCacheRubyPrefix(platform, engine, version) {
|
||||
const toolCache = getPlatformToolCache(platform)
|
||||
const name = {
|
||||
// tc.find() but using RUNNER_TOOL_CACHE=getToolCachePath()
|
||||
function toolCacheFind(engine, version) {
|
||||
const originalToolCache = getToolCachePath()
|
||||
process.env['RUNNER_TOOL_CACHE'] = getToolCachePath()
|
||||
try {
|
||||
return tc.find(engineToToolCacheName(engine), version)
|
||||
} finally {
|
||||
process.env['RUNNER_TOOL_CACHE'] = originalToolCache
|
||||
}
|
||||
}
|
||||
|
||||
function engineToToolCacheName(engine) {
|
||||
return {
|
||||
ruby: 'Ruby',
|
||||
jruby: 'JRuby',
|
||||
truffleruby: 'TruffleRuby',
|
||||
"truffleruby+graalvm": 'TruffleRubyGraalVM'
|
||||
}[engine]
|
||||
return path.join(toolCache, name, version, os.arch())
|
||||
}
|
||||
|
||||
function getToolCacheRubyPrefix(platform, engine, version) {
|
||||
const toolCache = getToolCachePath()
|
||||
return path.join(toolCache, engineToToolCacheName(engine), version, os.arch())
|
||||
}
|
||||
|
||||
function toolCacheCompleteFile(toolCacheRubyPrefix) {
|
||||
@@ -68245,7 +68296,7 @@ function getAvailableVersions(platform, engine) {
|
||||
async function install(platform, engine, version) {
|
||||
let rubyPrefix, inToolCache
|
||||
if (common.shouldUseToolCache(engine, version)) {
|
||||
inToolCache = tc.find('Ruby', version)
|
||||
inToolCache = common.toolCacheFind(engine, version)
|
||||
if (inToolCache) {
|
||||
rubyPrefix = inToolCache
|
||||
} else {
|
||||
@@ -68253,8 +68304,8 @@ async function install(platform, engine, version) {
|
||||
if (common.isSelfHostedRunner()) {
|
||||
const rubyBuildDefinition = engine === 'ruby' ? version : `${engine}-${version}`
|
||||
core.error(
|
||||
`The current runner (${common.getOSNameVersionArch()}) was detected as self-hosted and not matching a GitHub-hosted runner image.\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` +
|
||||
`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` +
|
||||
@@ -68275,7 +68326,7 @@ async function install(platform, engine, version) {
|
||||
common.setupPath([path.join(rubyPrefix, 'bin')])
|
||||
|
||||
if (!inToolCache) {
|
||||
await preparePrefix(rubyPrefix)
|
||||
await io.mkdirP(rubyPrefix)
|
||||
if (engine === 'truffleruby+graalvm') {
|
||||
await installWithRubyBuild(engine, version, rubyPrefix)
|
||||
} else {
|
||||
@@ -68286,15 +68337,6 @@ async function install(platform, engine, version) {
|
||||
return rubyPrefix
|
||||
}
|
||||
|
||||
async function preparePrefix(rubyPrefix) {
|
||||
const parentDir = path.dirname(rubyPrefix)
|
||||
|
||||
await io.rmRF(rubyPrefix)
|
||||
if (!(fs.existsSync(parentDir) && fs.statSync(parentDir).isDirectory())) {
|
||||
await io.mkdirP(parentDir)
|
||||
}
|
||||
}
|
||||
|
||||
async function installWithRubyBuild(engine, version, rubyPrefix) {
|
||||
const tmp = process.env['RUNNER_TEMP'] || os.tmpdir()
|
||||
const rubyBuildDir = path.join(tmp, 'ruby-build-for-setup-ruby')
|
||||
@@ -68459,7 +68501,7 @@ async function install(platform, engine, version) {
|
||||
|
||||
let rubyPrefix, inToolCache
|
||||
if (common.shouldUseToolCache(engine, version)) {
|
||||
inToolCache = tc.find('Ruby', version)
|
||||
inToolCache = common.toolCacheFind(engine, version)
|
||||
if (inToolCache) {
|
||||
rubyPrefix = inToolCache
|
||||
} else {
|
||||
@@ -69015,6 +69057,7 @@ const inputDefaults = {
|
||||
'bundler-cache': 'false',
|
||||
'working-directory': '.',
|
||||
'cache-version': bundler.DEFAULT_CACHE_VERSION,
|
||||
'self-hosted': 'false',
|
||||
}
|
||||
|
||||
// entry point when this action is run on its own
|
||||
@@ -69038,6 +69081,7 @@ async function setupRuby(options = {}) {
|
||||
inputs[key] = core.getInput(key) || inputDefaults[key]
|
||||
}
|
||||
}
|
||||
common.inputs.selfHosted = inputs['self-hosted']
|
||||
|
||||
process.chdir(inputs['working-directory'])
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ const inputDefaults = {
|
||||
'bundler-cache': 'false',
|
||||
'working-directory': '.',
|
||||
'cache-version': bundler.DEFAULT_CACHE_VERSION,
|
||||
'self-hosted': 'false',
|
||||
}
|
||||
|
||||
// entry point when this action is run on its own
|
||||
@@ -39,6 +40,7 @@ export async function setupRuby(options = {}) {
|
||||
inputs[key] = core.getInput(key) || inputDefaults[key]
|
||||
}
|
||||
}
|
||||
common.inputs.selfHosted = inputs['self-hosted']
|
||||
|
||||
process.chdir(inputs['working-directory'])
|
||||
|
||||
|
||||
+4
-13
@@ -20,7 +20,7 @@ export function getAvailableVersions(platform, engine) {
|
||||
export async function install(platform, engine, version) {
|
||||
let rubyPrefix, inToolCache
|
||||
if (common.shouldUseToolCache(engine, version)) {
|
||||
inToolCache = tc.find('Ruby', version)
|
||||
inToolCache = common.toolCacheFind(engine, version)
|
||||
if (inToolCache) {
|
||||
rubyPrefix = inToolCache
|
||||
} else {
|
||||
@@ -28,8 +28,8 @@ export async function install(platform, engine, version) {
|
||||
if (common.isSelfHostedRunner()) {
|
||||
const rubyBuildDefinition = engine === 'ruby' ? version : `${engine}-${version}`
|
||||
core.error(
|
||||
`The current runner (${common.getOSNameVersionArch()}) was detected as self-hosted and not matching a GitHub-hosted runner image.\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` +
|
||||
`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` +
|
||||
@@ -50,7 +50,7 @@ export async function install(platform, engine, version) {
|
||||
common.setupPath([path.join(rubyPrefix, 'bin')])
|
||||
|
||||
if (!inToolCache) {
|
||||
await preparePrefix(rubyPrefix)
|
||||
await io.mkdirP(rubyPrefix)
|
||||
if (engine === 'truffleruby+graalvm') {
|
||||
await installWithRubyBuild(engine, version, rubyPrefix)
|
||||
} else {
|
||||
@@ -61,15 +61,6 @@ export async function install(platform, engine, version) {
|
||||
return rubyPrefix
|
||||
}
|
||||
|
||||
async function preparePrefix(rubyPrefix) {
|
||||
const parentDir = path.dirname(rubyPrefix)
|
||||
|
||||
await io.rmRF(rubyPrefix)
|
||||
if (!(fs.existsSync(parentDir) && fs.statSync(parentDir).isDirectory())) {
|
||||
await io.mkdirP(parentDir)
|
||||
}
|
||||
}
|
||||
|
||||
async function installWithRubyBuild(engine, version, rubyPrefix) {
|
||||
const tmp = process.env['RUNNER_TEMP'] || os.tmpdir()
|
||||
const rubyBuildDir = path.join(tmp, 'ruby-build-for-setup-ruby')
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ export async function install(platform, engine, version) {
|
||||
|
||||
let rubyPrefix, inToolCache
|
||||
if (common.shouldUseToolCache(engine, version)) {
|
||||
inToolCache = tc.find('Ruby', version)
|
||||
inToolCache = common.toolCacheFind(engine, version)
|
||||
if (inToolCache) {
|
||||
rubyPrefix = inToolCache
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user