Skip to content

Commit

Permalink
Use tc.find() with the effective tool cache path
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
eregon committed Mar 5, 2023
1 parent d03a71d commit 59b5745
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
14 changes: 13 additions & 1 deletion common.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const util = require('util')
const stream = require('stream')
const crypto = require('crypto')
const core = require('@actions/core')
const tc = require('@actions/tool-cache')
const { performance } = require('perf_hooks')
const linuxOSInfo = require('linux-os-info')
import macosRelease from 'macos-release'
Expand Down Expand Up @@ -264,7 +265,18 @@ function getDefaultToolCachePath() {
}
}

export function engineToToolCacheName(engine) {
// tc.find() but using RUNNER_TOOL_CACHE=getToolCachePath()
export function toolCacheFind(engine, version) {
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',
jruby: 'JRuby',
Expand Down
18 changes: 15 additions & 3 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 @@ -20,7 +20,7 @@ export function getAvailableVersions(platform, engine) {
export async function install(platform, engine, version) {
let rubyPrefix, inToolCache
if (common.shouldUseToolCache(engine, version)) {
inToolCache = tc.find(common.engineToToolCacheName(engine), version)
inToolCache = common.toolCacheFind(engine, version)
if (inToolCache) {
rubyPrefix = inToolCache
} else {
Expand Down
2 changes: 1 addition & 1 deletion windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export async function install(platform, engine, version) {

let rubyPrefix, inToolCache
if (common.shouldUseToolCache(engine, version)) {
inToolCache = tc.find(common.engineToToolCacheName(engine), version)
inToolCache = common.toolCacheFind(engine, version)
if (inToolCache) {
rubyPrefix = inToolCache
} else {
Expand Down

0 comments on commit 59b5745

Please sign in to comment.