mirror of
https://github.com/ruby/setup-ruby.git
synced 2026-09-13 14:34:21 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59b5745c73 | ||
|
|
d03a71de6e | ||
|
|
ddde3938f5 |
@@ -5,6 +5,7 @@ const util = require('util')
|
|||||||
const stream = require('stream')
|
const stream = require('stream')
|
||||||
const crypto = require('crypto')
|
const crypto = require('crypto')
|
||||||
const core = require('@actions/core')
|
const core = require('@actions/core')
|
||||||
|
const tc = require('@actions/tool-cache')
|
||||||
const { performance } = require('perf_hooks')
|
const { performance } = require('perf_hooks')
|
||||||
const linuxOSInfo = require('linux-os-info')
|
const linuxOSInfo = require('linux-os-info')
|
||||||
import macosRelease from 'macos-release'
|
import macosRelease from 'macos-release'
|
||||||
@@ -166,17 +167,14 @@ const GitHubHostedPlatforms = [
|
|||||||
'windows-2022-x64',
|
'windows-2022-x64',
|
||||||
]
|
]
|
||||||
|
|
||||||
// Actually a self-hosted runner for which either
|
// Actually a self-hosted runner for which the OS and OS version does not correspond to a GitHub-hosted runner image,
|
||||||
// * the OS and OS version does not correspond to a GitHub-hosted runner image,
|
|
||||||
// * or the hosted tool cache is different from the default tool cache path
|
|
||||||
export function isSelfHostedRunner() {
|
export function isSelfHostedRunner() {
|
||||||
if (inputs.selfHosted === undefined) {
|
if (inputs.selfHosted === undefined) {
|
||||||
throw new Error('inputs.selfHosted should have been already set')
|
throw new Error('inputs.selfHosted should have been already set')
|
||||||
}
|
}
|
||||||
|
|
||||||
return inputs.selfHosted === 'true' ||
|
return inputs.selfHosted === 'true' ||
|
||||||
!GitHubHostedPlatforms.includes(getOSNameVersionArch()) ||
|
!GitHubHostedPlatforms.includes(getOSNameVersionArch())
|
||||||
getRunnerToolCache() !== getDefaultToolCachePath()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function selfHostedRunnerReason() {
|
export function selfHostedRunnerReason() {
|
||||||
@@ -184,8 +182,6 @@ export function selfHostedRunnerReason() {
|
|||||||
return 'the self-hosted input was set'
|
return 'the self-hosted input was set'
|
||||||
} else if (!GitHubHostedPlatforms.includes(getOSNameVersionArch())) {
|
} 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)'
|
return 'the platform does not match a GitHub-hosted runner image (or that image is deprecated and no longer supported)'
|
||||||
} else if (getRunnerToolCache() !== getDefaultToolCachePath()) {
|
|
||||||
return 'the $RUNNER_TOOL_CACHE is different than the default tool cache path (they must be the same to reuse prebuilt Ruby binaries)'
|
|
||||||
} else {
|
} else {
|
||||||
return 'unknown reason'
|
return 'unknown reason'
|
||||||
}
|
}
|
||||||
@@ -237,6 +233,16 @@ export function shouldUseToolCache(engine, version) {
|
|||||||
return (engine === 'ruby' && !isHeadVersion(version)) || isSelfHostedRunner()
|
return (engine === 'ruby' && !isHeadVersion(version)) || isSelfHostedRunner()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getToolCachePath() {
|
||||||
|
if (isSelfHostedRunner()) {
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function getRunnerToolCache() {
|
export function getRunnerToolCache() {
|
||||||
const runnerToolCache = process.env['RUNNER_TOOL_CACHE']
|
const runnerToolCache = process.env['RUNNER_TOOL_CACHE']
|
||||||
if (!runnerToolCache) {
|
if (!runnerToolCache) {
|
||||||
@@ -245,8 +251,7 @@ export function getRunnerToolCache() {
|
|||||||
return runnerToolCache
|
return runnerToolCache
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rubies prebuilt by this action embed this path rather than using $RUNNER_TOOL_CACHE,
|
// Rubies prebuilt by this action embed this path rather than using $RUNNER_TOOL_CACHE
|
||||||
// so they can only be used if the two paths are the same
|
|
||||||
function getDefaultToolCachePath() {
|
function getDefaultToolCachePath() {
|
||||||
const platform = getVirtualEnvironmentName()
|
const platform = getVirtualEnvironmentName()
|
||||||
if (platform.startsWith('ubuntu-')) {
|
if (platform.startsWith('ubuntu-')) {
|
||||||
@@ -260,15 +265,29 @@ function getDefaultToolCachePath() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getToolCacheRubyPrefix(platform, engine, version) {
|
// tc.find() but using RUNNER_TOOL_CACHE=getToolCachePath()
|
||||||
const toolCache = getRunnerToolCache()
|
export function toolCacheFind(engine, version) {
|
||||||
const name = {
|
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',
|
ruby: 'Ruby',
|
||||||
jruby: 'JRuby',
|
jruby: 'JRuby',
|
||||||
truffleruby: 'TruffleRuby',
|
truffleruby: 'TruffleRuby',
|
||||||
"truffleruby+graalvm": 'TruffleRubyGraalVM'
|
"truffleruby+graalvm": 'TruffleRubyGraalVM'
|
||||||
}[engine]
|
}[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) {
|
export function toolCacheCompleteFile(toolCacheRubyPrefix) {
|
||||||
|
|||||||
+37
-16
@@ -292,6 +292,7 @@ __nccwpck_require__.d(__webpack_exports__, {
|
|||||||
"floatVersion": () => (/* binding */ floatVersion),
|
"floatVersion": () => (/* binding */ floatVersion),
|
||||||
"getOSNameVersionArch": () => (/* binding */ getOSNameVersionArch),
|
"getOSNameVersionArch": () => (/* binding */ getOSNameVersionArch),
|
||||||
"getRunnerToolCache": () => (/* binding */ getRunnerToolCache),
|
"getRunnerToolCache": () => (/* binding */ getRunnerToolCache),
|
||||||
|
"getToolCachePath": () => (/* binding */ getToolCachePath),
|
||||||
"getToolCacheRubyPrefix": () => (/* binding */ getToolCacheRubyPrefix),
|
"getToolCacheRubyPrefix": () => (/* binding */ getToolCacheRubyPrefix),
|
||||||
"getVirtualEnvironmentName": () => (/* binding */ getVirtualEnvironmentName),
|
"getVirtualEnvironmentName": () => (/* binding */ getVirtualEnvironmentName),
|
||||||
"hasBundlerDefaultGem": () => (/* binding */ hasBundlerDefaultGem),
|
"hasBundlerDefaultGem": () => (/* binding */ hasBundlerDefaultGem),
|
||||||
@@ -311,6 +312,7 @@ __nccwpck_require__.d(__webpack_exports__, {
|
|||||||
"targetRubyVersion": () => (/* binding */ targetRubyVersion),
|
"targetRubyVersion": () => (/* binding */ targetRubyVersion),
|
||||||
"time": () => (/* binding */ time),
|
"time": () => (/* binding */ time),
|
||||||
"toolCacheCompleteFile": () => (/* binding */ toolCacheCompleteFile),
|
"toolCacheCompleteFile": () => (/* binding */ toolCacheCompleteFile),
|
||||||
|
"toolCacheFind": () => (/* binding */ toolCacheFind),
|
||||||
"win2nix": () => (/* binding */ win2nix),
|
"win2nix": () => (/* binding */ win2nix),
|
||||||
"windows": () => (/* binding */ windows)
|
"windows": () => (/* binding */ windows)
|
||||||
});
|
});
|
||||||
@@ -360,6 +362,7 @@ const util = __nccwpck_require__(3837)
|
|||||||
const stream = __nccwpck_require__(2781)
|
const stream = __nccwpck_require__(2781)
|
||||||
const common_crypto = __nccwpck_require__(6113)
|
const common_crypto = __nccwpck_require__(6113)
|
||||||
const core = __nccwpck_require__(2186)
|
const core = __nccwpck_require__(2186)
|
||||||
|
const tc = __nccwpck_require__(7784)
|
||||||
const { performance } = __nccwpck_require__(4074)
|
const { performance } = __nccwpck_require__(4074)
|
||||||
const linuxOSInfo = __nccwpck_require__(8487)
|
const linuxOSInfo = __nccwpck_require__(8487)
|
||||||
;
|
;
|
||||||
@@ -521,17 +524,14 @@ const GitHubHostedPlatforms = [
|
|||||||
'windows-2022-x64',
|
'windows-2022-x64',
|
||||||
]
|
]
|
||||||
|
|
||||||
// Actually a self-hosted runner for which either
|
// Actually a self-hosted runner for which the OS and OS version does not correspond to a GitHub-hosted runner image,
|
||||||
// * the OS and OS version does not correspond to a GitHub-hosted runner image,
|
|
||||||
// * or the hosted tool cache is different from the default tool cache path
|
|
||||||
function isSelfHostedRunner() {
|
function isSelfHostedRunner() {
|
||||||
if (inputs.selfHosted === undefined) {
|
if (inputs.selfHosted === undefined) {
|
||||||
throw new Error('inputs.selfHosted should have been already set')
|
throw new Error('inputs.selfHosted should have been already set')
|
||||||
}
|
}
|
||||||
|
|
||||||
return inputs.selfHosted === 'true' ||
|
return inputs.selfHosted === 'true' ||
|
||||||
!GitHubHostedPlatforms.includes(getOSNameVersionArch()) ||
|
!GitHubHostedPlatforms.includes(getOSNameVersionArch())
|
||||||
getRunnerToolCache() !== getDefaultToolCachePath()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function selfHostedRunnerReason() {
|
function selfHostedRunnerReason() {
|
||||||
@@ -539,8 +539,6 @@ function selfHostedRunnerReason() {
|
|||||||
return 'the self-hosted input was set'
|
return 'the self-hosted input was set'
|
||||||
} else if (!GitHubHostedPlatforms.includes(getOSNameVersionArch())) {
|
} 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)'
|
return 'the platform does not match a GitHub-hosted runner image (or that image is deprecated and no longer supported)'
|
||||||
} else if (getRunnerToolCache() !== getDefaultToolCachePath()) {
|
|
||||||
return 'the $RUNNER_TOOL_CACHE is different than the default tool cache path (they must be the same to reuse prebuilt Ruby binaries)'
|
|
||||||
} else {
|
} else {
|
||||||
return 'unknown reason'
|
return 'unknown reason'
|
||||||
}
|
}
|
||||||
@@ -592,6 +590,16 @@ function shouldUseToolCache(engine, version) {
|
|||||||
return (engine === 'ruby' && !isHeadVersion(version)) || isSelfHostedRunner()
|
return (engine === 'ruby' && !isHeadVersion(version)) || isSelfHostedRunner()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getToolCachePath() {
|
||||||
|
if (isSelfHostedRunner()) {
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getRunnerToolCache() {
|
function getRunnerToolCache() {
|
||||||
const runnerToolCache = process.env['RUNNER_TOOL_CACHE']
|
const runnerToolCache = process.env['RUNNER_TOOL_CACHE']
|
||||||
if (!runnerToolCache) {
|
if (!runnerToolCache) {
|
||||||
@@ -600,8 +608,7 @@ function getRunnerToolCache() {
|
|||||||
return runnerToolCache
|
return runnerToolCache
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rubies prebuilt by this action embed this path rather than using $RUNNER_TOOL_CACHE,
|
// Rubies prebuilt by this action embed this path rather than using $RUNNER_TOOL_CACHE
|
||||||
// so they can only be used if the two paths are the same
|
|
||||||
function getDefaultToolCachePath() {
|
function getDefaultToolCachePath() {
|
||||||
const platform = getVirtualEnvironmentName()
|
const platform = getVirtualEnvironmentName()
|
||||||
if (platform.startsWith('ubuntu-')) {
|
if (platform.startsWith('ubuntu-')) {
|
||||||
@@ -615,15 +622,29 @@ function getDefaultToolCachePath() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getToolCacheRubyPrefix(platform, engine, version) {
|
// tc.find() but using RUNNER_TOOL_CACHE=getToolCachePath()
|
||||||
const toolCache = getRunnerToolCache()
|
function toolCacheFind(engine, version) {
|
||||||
const name = {
|
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',
|
ruby: 'Ruby',
|
||||||
jruby: 'JRuby',
|
jruby: 'JRuby',
|
||||||
truffleruby: 'TruffleRuby',
|
truffleruby: 'TruffleRuby',
|
||||||
"truffleruby+graalvm": 'TruffleRubyGraalVM'
|
"truffleruby+graalvm": 'TruffleRubyGraalVM'
|
||||||
}[engine]
|
}[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) {
|
function toolCacheCompleteFile(toolCacheRubyPrefix) {
|
||||||
@@ -68275,7 +68296,7 @@ function getAvailableVersions(platform, engine) {
|
|||||||
async function install(platform, engine, version) {
|
async function install(platform, engine, version) {
|
||||||
let rubyPrefix, inToolCache
|
let rubyPrefix, inToolCache
|
||||||
if (common.shouldUseToolCache(engine, version)) {
|
if (common.shouldUseToolCache(engine, version)) {
|
||||||
inToolCache = tc.find('Ruby', version)
|
inToolCache = common.toolCacheFind(engine, version)
|
||||||
if (inToolCache) {
|
if (inToolCache) {
|
||||||
rubyPrefix = inToolCache
|
rubyPrefix = inToolCache
|
||||||
} else {
|
} else {
|
||||||
@@ -68283,7 +68304,7 @@ async function install(platform, engine, version) {
|
|||||||
if (common.isSelfHostedRunner()) {
|
if (common.isSelfHostedRunner()) {
|
||||||
const rubyBuildDefinition = engine === 'ruby' ? version : `${engine}-${version}`
|
const rubyBuildDefinition = engine === 'ruby' ? version : `${engine}-${version}`
|
||||||
core.error(
|
core.error(
|
||||||
`The current runner (${common.getOSNameVersionArch()}, RUNNER_TOOL_CACHE=${common.getRunnerToolCache()}) was detected as self-hosted because ${common.selfHostedRunnerReason()}.\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` +
|
`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` +
|
`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` +
|
`$ ruby-build ${rubyBuildDefinition} ${toolCacheRubyPrefix}\n` +
|
||||||
@@ -68489,7 +68510,7 @@ async function install(platform, engine, version) {
|
|||||||
|
|
||||||
let rubyPrefix, inToolCache
|
let rubyPrefix, inToolCache
|
||||||
if (common.shouldUseToolCache(engine, version)) {
|
if (common.shouldUseToolCache(engine, version)) {
|
||||||
inToolCache = tc.find('Ruby', version)
|
inToolCache = common.toolCacheFind(engine, version)
|
||||||
if (inToolCache) {
|
if (inToolCache) {
|
||||||
rubyPrefix = inToolCache
|
rubyPrefix = inToolCache
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+2
-2
@@ -20,7 +20,7 @@ export function getAvailableVersions(platform, engine) {
|
|||||||
export async function install(platform, engine, version) {
|
export async function install(platform, engine, version) {
|
||||||
let rubyPrefix, inToolCache
|
let rubyPrefix, inToolCache
|
||||||
if (common.shouldUseToolCache(engine, version)) {
|
if (common.shouldUseToolCache(engine, version)) {
|
||||||
inToolCache = tc.find('Ruby', version)
|
inToolCache = common.toolCacheFind(engine, version)
|
||||||
if (inToolCache) {
|
if (inToolCache) {
|
||||||
rubyPrefix = inToolCache
|
rubyPrefix = inToolCache
|
||||||
} else {
|
} else {
|
||||||
@@ -28,7 +28,7 @@ export async function install(platform, engine, version) {
|
|||||||
if (common.isSelfHostedRunner()) {
|
if (common.isSelfHostedRunner()) {
|
||||||
const rubyBuildDefinition = engine === 'ruby' ? version : `${engine}-${version}`
|
const rubyBuildDefinition = engine === 'ruby' ? version : `${engine}-${version}`
|
||||||
core.error(
|
core.error(
|
||||||
`The current runner (${common.getOSNameVersionArch()}, RUNNER_TOOL_CACHE=${common.getRunnerToolCache()}) was detected as self-hosted because ${common.selfHostedRunnerReason()}.\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` +
|
`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` +
|
`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` +
|
`$ ruby-build ${rubyBuildDefinition} ${toolCacheRubyPrefix}\n` +
|
||||||
|
|||||||
+1
-1
@@ -49,7 +49,7 @@ export async function install(platform, engine, version) {
|
|||||||
|
|
||||||
let rubyPrefix, inToolCache
|
let rubyPrefix, inToolCache
|
||||||
if (common.shouldUseToolCache(engine, version)) {
|
if (common.shouldUseToolCache(engine, version)) {
|
||||||
inToolCache = tc.find('Ruby', version)
|
inToolCache = common.toolCacheFind(engine, version)
|
||||||
if (inToolCache) {
|
if (inToolCache) {
|
||||||
rubyPrefix = inToolCache
|
rubyPrefix = inToolCache
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user