Skip to content

Commit 377a94b

Browse files
committed
Consider a different $RUNNER_TOOL_CACHE than the default as a self-hosted runner
* Fixes #242
1 parent 66dc012 commit 377a94b

File tree

3 files changed

+39
-26
lines changed

3 files changed

+39
-26
lines changed

common.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,12 @@ const GitHubHostedPlatforms = [
162162
'windows-2022-x64',
163163
]
164164

165-
// Actually a self-hosted runner which does not correspond to a GitHub-hosted runner image
165+
// Actually a self-hosted runner for which either
166+
// * the OS and OS version does not correspond to a GitHub-hosted runner image,
167+
// * or the hosted tool cache is different from the default tool cache path
166168
export function isSelfHostedRunner() {
167-
return !GitHubHostedPlatforms.includes(getOSNameVersionArch())
169+
return !GitHubHostedPlatforms.includes(getOSNameVersionArch()) ||
170+
getRunnerToolCache() !== getDefaultToolCachePath()
168171
}
169172

170173
let virtualEnvironmentName = undefined
@@ -213,28 +216,31 @@ export function shouldUseToolCache(engine, version) {
213216
return (engine === 'ruby' && !isHeadVersion(version)) || isSelfHostedRunner()
214217
}
215218

216-
function getPlatformToolCache(platform) {
217-
if (isSelfHostedRunner()) {
218-
const runnerToolCache = process.env['RUNNER_TOOL_CACHE']
219-
if (!runnerToolCache) {
220-
throw new Error('$RUNNER_TOOL_CACHE must be set on self-hosted runners')
221-
}
222-
return runnerToolCache
219+
export function getRunnerToolCache() {
220+
const runnerToolCache = process.env['RUNNER_TOOL_CACHE']
221+
if (!runnerToolCache) {
222+
throw new Error('$RUNNER_TOOL_CACHE must be set')
223223
}
224-
// Hardcode paths rather than using $RUNNER_TOOL_CACHE because the prebuilt Rubies cannot be moved anyway
224+
return runnerToolCache
225+
}
226+
227+
// Rubies prebuilt by this action embed this path rather than using $RUNNER_TOOL_CACHE,
228+
// so they can only be used if the two paths are the same
229+
function getDefaultToolCachePath() {
230+
const platform = getVirtualEnvironmentName()
225231
if (platform.startsWith('ubuntu-')) {
226232
return '/opt/hostedtoolcache'
227233
} else if (platform.startsWith('macos-')) {
228234
return '/Users/runner/hostedtoolcache'
229235
} else if (platform.startsWith('windows-')) {
230-
return 'C:/hostedtoolcache/windows'
236+
return 'C:\\hostedtoolcache\\windows'
231237
} else {
232238
throw new Error('Unknown platform')
233239
}
234240
}
235241

236242
export function getToolCacheRubyPrefix(platform, engine, version) {
237-
const toolCache = getPlatformToolCache(platform)
243+
const toolCache = getRunnerToolCache()
238244
const name = {
239245
ruby: 'Ruby',
240246
jruby: 'JRuby',

dist/index.js

Lines changed: 20 additions & 13 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()}) was detected as self-hosted and not matching a GitHub-hosted runner image.\n` +
31+
`The current runner (${common.getOSNameVersionArch()}, RUNNER_TOOL_CACHE=${common.getRunnerToolCache()}) was detected as self-hosted and not matching a GitHub-hosted runner image.\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)