Skip to content

Commit

Permalink
Use the default tool cache path on self-hosted runners matching a GH-…
Browse files Browse the repository at this point in the history
…hosted runner image

* See #475
* Semantically reverts 377a94b
  • Loading branch information
eregon committed Mar 5, 2023
1 parent 5a73aa9 commit ddde393
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
24 changes: 14 additions & 10 deletions common.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,26 +166,21 @@ const GitHubHostedPlatforms = [
'windows-2022-x64',
]

// Actually a self-hosted runner for which either
// * 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
// Actually a self-hosted runner for which the OS and OS version does not correspond to a GitHub-hosted runner image,
export function isSelfHostedRunner() {
if (inputs.selfHosted === undefined) {
throw new Error('inputs.selfHosted should have been already set')
}

return inputs.selfHosted === 'true' ||
!GitHubHostedPlatforms.includes(getOSNameVersionArch()) ||
getRunnerToolCache() !== getDefaultToolCachePath()
!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 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 {
return 'unknown reason'
}
Expand Down Expand Up @@ -237,6 +232,16 @@ export function shouldUseToolCache(engine, version) {
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() {
const runnerToolCache = process.env['RUNNER_TOOL_CACHE']
if (!runnerToolCache) {
Expand All @@ -245,8 +250,7 @@ export function getRunnerToolCache() {
return runnerToolCache
}

// 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
// Rubies prebuilt by this action embed this path rather than using $RUNNER_TOOL_CACHE
function getDefaultToolCachePath() {
const platform = getVirtualEnvironmentName()
if (platform.startsWith('ubuntu-')) {
Expand All @@ -261,7 +265,7 @@ function getDefaultToolCachePath() {
}

export function getToolCacheRubyPrefix(platform, engine, version) {
const toolCache = getRunnerToolCache()
const toolCache = getToolCachePath()
const name = {
ruby: 'Ruby',
jruby: 'JRuby',
Expand Down
27 changes: 16 additions & 11 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ruby-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function install(platform, engine, version) {
if (common.isSelfHostedRunner()) {
const rubyBuildDefinition = engine === 'ruby' ? version : `${engine}-${version}`
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` +
`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` +
Expand Down

0 comments on commit ddde393

Please sign in to comment.