From 59b5745c73c7ec1d7efad4926cb9ff20dcf8eff9 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Sun, 5 Mar 2023 14:42:52 +0100 Subject: [PATCH] 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 --- common.js | 14 +++++++++++++- dist/index.js | 18 +++++++++++++++--- ruby-builder.js | 2 +- windows.js | 2 +- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/common.js b/common.js index dc71bc0..a28f839 100644 --- a/common.js +++ b/common.js @@ -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' @@ -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', diff --git a/dist/index.js b/dist/index.js index c2a54b5..48ccb66 100644 --- a/dist/index.js +++ b/dist/index.js @@ -289,7 +289,6 @@ __nccwpck_require__.r(__webpack_exports__); __nccwpck_require__.d(__webpack_exports__, { "createToolCacheCompleteFile": () => (/* binding */ createToolCacheCompleteFile), "drive": () => (/* binding */ drive), - "engineToToolCacheName": () => (/* binding */ engineToToolCacheName), "floatVersion": () => (/* binding */ floatVersion), "getOSNameVersionArch": () => (/* binding */ getOSNameVersionArch), "getRunnerToolCache": () => (/* binding */ getRunnerToolCache), @@ -313,6 +312,7 @@ __nccwpck_require__.d(__webpack_exports__, { "targetRubyVersion": () => (/* binding */ targetRubyVersion), "time": () => (/* binding */ time), "toolCacheCompleteFile": () => (/* binding */ toolCacheCompleteFile), + "toolCacheFind": () => (/* binding */ toolCacheFind), "win2nix": () => (/* binding */ win2nix), "windows": () => (/* binding */ windows) }); @@ -362,6 +362,7 @@ const util = __nccwpck_require__(3837) const stream = __nccwpck_require__(2781) const common_crypto = __nccwpck_require__(6113) const core = __nccwpck_require__(2186) +const tc = __nccwpck_require__(7784) const { performance } = __nccwpck_require__(4074) const linuxOSInfo = __nccwpck_require__(8487) ; @@ -621,6 +622,17 @@ function getDefaultToolCachePath() { } } +// tc.find() but using RUNNER_TOOL_CACHE=getToolCachePath() +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', @@ -68284,7 +68296,7 @@ function getAvailableVersions(platform, engine) { 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 { @@ -68498,7 +68510,7 @@ 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 { diff --git a/ruby-builder.js b/ruby-builder.js index 8dd71c5..9f5b143 100644 --- a/ruby-builder.js +++ b/ruby-builder.js @@ -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 { diff --git a/windows.js b/windows.js index d827071..e831cb4 100644 --- a/windows.js +++ b/windows.js @@ -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 {