Skip to content

Commit 59b5745

Browse files
committed
Use tc.find() with the effective tool cache path
* So it finds already-download prebuilt Ruby in the GH-hosted tool cache path on self-hosted, where $RUNNER_TOOL_CACHE is often different than on GH-hosted. * See #475. * This relies on tc.find() looking up the env var every time: https://github.com/actions/toolkit/blob/1f4b3fac06/packages/tool-cache/src/tool-cache.ts#L522
1 parent d03a71d commit 59b5745

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

common.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const util = require('util')
55
const stream = require('stream')
66
const crypto = require('crypto')
77
const core = require('@actions/core')
8+
const tc = require('@actions/tool-cache')
89
const { performance } = require('perf_hooks')
910
const linuxOSInfo = require('linux-os-info')
1011
import macosRelease from 'macos-release'
@@ -264,7 +265,18 @@ function getDefaultToolCachePath() {
264265
}
265266
}
266267

267-
export function engineToToolCacheName(engine) {
268+
// tc.find() but using RUNNER_TOOL_CACHE=getToolCachePath()
269+
export function toolCacheFind(engine, version) {
270+
const originalToolCache = getToolCachePath()
271+
process.env['RUNNER_TOOL_CACHE'] = getToolCachePath()
272+
try {
273+
return tc.find(engineToToolCacheName(engine), version)
274+
} finally {
275+
process.env['RUNNER_TOOL_CACHE'] = originalToolCache
276+
}
277+
}
278+
279+
function engineToToolCacheName(engine) {
268280
return {
269281
ruby: 'Ruby',
270282
jruby: 'JRuby',

dist/index.js

Lines changed: 15 additions & 3 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
@@ -20,7 +20,7 @@ export function getAvailableVersions(platform, engine) {
2020
export async function install(platform, engine, version) {
2121
let rubyPrefix, inToolCache
2222
if (common.shouldUseToolCache(engine, version)) {
23-
inToolCache = tc.find(common.engineToToolCacheName(engine), version)
23+
inToolCache = common.toolCacheFind(engine, version)
2424
if (inToolCache) {
2525
rubyPrefix = inToolCache
2626
} else {

windows.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export async function install(platform, engine, version) {
4949

5050
let rubyPrefix, inToolCache
5151
if (common.shouldUseToolCache(engine, version)) {
52-
inToolCache = tc.find(common.engineToToolCacheName(engine), version)
52+
inToolCache = common.toolCacheFind(engine, version)
5353
if (inToolCache) {
5454
rubyPrefix = inToolCache
5555
} else {

0 commit comments

Comments
 (0)