Skip to content

Commit ddde393

Browse files
committed
Use the default tool cache path on self-hosted runners matching a GH-hosted runner image
* See #475 * Semantically reverts 377a94b
1 parent 5a73aa9 commit ddde393

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
lines changed

common.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -166,26 +166,21 @@ const GitHubHostedPlatforms = [
166166
'windows-2022-x64',
167167
]
168168

169-
// Actually a self-hosted runner for which either
170-
// * the OS and OS version does not correspond to a GitHub-hosted runner image,
171-
// * or the hosted tool cache is different from the default tool cache path
169+
// Actually a self-hosted runner for which the OS and OS version does not correspond to a GitHub-hosted runner image,
172170
export function isSelfHostedRunner() {
173171
if (inputs.selfHosted === undefined) {
174172
throw new Error('inputs.selfHosted should have been already set')
175173
}
176174

177175
return inputs.selfHosted === 'true' ||
178-
!GitHubHostedPlatforms.includes(getOSNameVersionArch()) ||
179-
getRunnerToolCache() !== getDefaultToolCachePath()
176+
!GitHubHostedPlatforms.includes(getOSNameVersionArch())
180177
}
181178

182179
export function selfHostedRunnerReason() {
183180
if (inputs.selfHosted === 'true') {
184181
return 'the self-hosted input was set'
185182
} else if (!GitHubHostedPlatforms.includes(getOSNameVersionArch())) {
186183
return 'the platform does not match a GitHub-hosted runner image (or that image is deprecated and no longer supported)'
187-
} else if (getRunnerToolCache() !== getDefaultToolCachePath()) {
188-
return 'the $RUNNER_TOOL_CACHE is different than the default tool cache path (they must be the same to reuse prebuilt Ruby binaries)'
189184
} else {
190185
return 'unknown reason'
191186
}
@@ -237,6 +232,16 @@ export function shouldUseToolCache(engine, version) {
237232
return (engine === 'ruby' && !isHeadVersion(version)) || isSelfHostedRunner()
238233
}
239234

235+
export function getToolCachePath() {
236+
if (isSelfHostedRunner()) {
237+
return getRunnerToolCache()
238+
} else {
239+
// Rubies prebuilt by this action embed this path rather than using $RUNNER_TOOL_CACHE
240+
// so use that path is not isSelfHostedRunner()
241+
return getDefaultToolCachePath()
242+
}
243+
}
244+
240245
export function getRunnerToolCache() {
241246
const runnerToolCache = process.env['RUNNER_TOOL_CACHE']
242247
if (!runnerToolCache) {
@@ -245,8 +250,7 @@ export function getRunnerToolCache() {
245250
return runnerToolCache
246251
}
247252

248-
// Rubies prebuilt by this action embed this path rather than using $RUNNER_TOOL_CACHE,
249-
// so they can only be used if the two paths are the same
253+
// Rubies prebuilt by this action embed this path rather than using $RUNNER_TOOL_CACHE
250254
function getDefaultToolCachePath() {
251255
const platform = getVirtualEnvironmentName()
252256
if (platform.startsWith('ubuntu-')) {
@@ -261,7 +265,7 @@ function getDefaultToolCachePath() {
261265
}
262266

263267
export function getToolCacheRubyPrefix(platform, engine, version) {
264-
const toolCache = getRunnerToolCache()
268+
const toolCache = getToolCachePath()
265269
const name = {
266270
ruby: 'Ruby',
267271
jruby: 'JRuby',

dist/index.js

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

ruby-builder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export async function install(platform, engine, version) {
2828
if (common.isSelfHostedRunner()) {
2929
const rubyBuildDefinition = engine === 'ruby' ? version : `${engine}-${version}`
3030
core.error(
31-
`The current runner (${common.getOSNameVersionArch()}, RUNNER_TOOL_CACHE=${common.getRunnerToolCache()}) was detected as self-hosted because ${common.selfHostedRunnerReason()}.\n` +
31+
`The current runner (${common.getOSNameVersionArch()}) was detected as self-hosted because ${common.selfHostedRunnerReason()}.\n` +
3232
`In such a case, you should install Ruby in the $RUNNER_TOOL_CACHE yourself, for example using https://github.com/rbenv/ruby-build\n` +
3333
`You can take inspiration from this workflow for more details: https://github.com/ruby/ruby-builder/blob/master/.github/workflows/build.yml\n` +
3434
`$ ruby-build ${rubyBuildDefinition} ${toolCacheRubyPrefix}\n` +

0 commit comments

Comments
 (0)