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
This commit is contained in:
Benoit Daloze
2023-03-05 14:56:02 +01:00
parent d03a71de6e
commit 59b5745c73
4 changed files with 30 additions and 6 deletions
+13 -1
View File
@@ -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',
Generated Vendored
+15 -3
View File
@@ -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 {
+1 -1
View File
@@ -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 {
+1 -1
View File
@@ -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 {