handle distinct cache

This commit is contained in:
George Adams 2026-03-09 14:54:34 +00:00
commit fa4cd7679b
3 changed files with 23 additions and 5 deletions

View file

@ -1421,7 +1421,8 @@ use .
// Mock the installed Go binary reporting a different patch version
execFileSpy.mockImplementation(() => 'go version go1.20.14 linux/amd64');
const toolPath = path.normalize('/cache/go-custom/1.20.14/x64');
const expectedToolName = im.customToolCacheName(customBaseUrl);
const toolPath = path.normalize(`/cache/${expectedToolName}/1.20.14/x64`);
cacheSpy.mockImplementation(async () => toolPath);
await main.run();
@ -1432,7 +1433,7 @@ use .
// Cache key should use actual version, not the input spec
expect(cacheSpy).toHaveBeenCalledWith(
expect.any(String),
'go-custom',
expectedToolName,
'1.20.14',
'x64'
);
@ -1558,7 +1559,8 @@ use .
findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(async () => '/some/temp/path');
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
const toolPath = path.normalize('/cache/go-custom/1.25.0/x64');
const expectedToolName = im.customToolCacheName(customBaseUrl);
const toolPath = path.normalize(`/cache/${expectedToolName}/1.25.0/x64`);
cacheSpy.mockImplementation(async () => toolPath);
await main.run();

10
dist/setup/index.js vendored
View file

@ -77034,6 +77034,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.GOTOOLCHAIN_LOCAL_VAL = exports.GOTOOLCHAIN_ENV_VAR = void 0;
exports.getGo = getGo;
exports.customToolCacheName = customToolCacheName;
exports.extractGoArchive = extractGoArchive;
exports.getManifest = getManifest;
exports.getInfoFromManifest = getInfoFromManifest;
@ -77049,6 +77050,7 @@ const path = __importStar(__nccwpck_require__(16928));
const semver = __importStar(__nccwpck_require__(62088));
const httpm = __importStar(__nccwpck_require__(54844));
const sys = __importStar(__nccwpck_require__(57666));
const crypto_1 = __importDefault(__nccwpck_require__(76982));
const child_process_1 = __importDefault(__nccwpck_require__(35317));
const fs_1 = __importDefault(__nccwpck_require__(79896));
const os_1 = __importDefault(__nccwpck_require__(70857));
@ -77101,7 +77103,9 @@ function getGo(versionSpec_1, checkLatest_1, auth_1) {
}
// Use a distinct tool cache name for custom downloads to avoid
// colliding with the runner's pre-installed Go
const toolCacheName = customBaseUrl ? 'go-custom' : 'go';
const toolCacheName = customBaseUrl
? customToolCacheName(customBaseUrl)
: 'go';
// check cache
const toolPath = tc.find(toolCacheName, versionSpec, arch);
// If not found in cache, download
@ -77237,6 +77241,10 @@ function addExecutablesToToolCache(extPath_1, info_1, arch_1) {
(yield tc.cacheDir(extPath, toolName, version, arch)));
});
}
function customToolCacheName(baseUrl) {
const hash = crypto_1.default.createHash('sha256').update(baseUrl).digest('hex');
return `go-${hash.substring(0, 8)}`;
}
function installGoVersion(info_1, auth_1, arch_1) {
return __awaiter(this, arguments, void 0, function* (info, auth, arch, toolName = 'go') {
core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);

View file

@ -4,6 +4,7 @@ import * as path from 'path';
import * as semver from 'semver';
import * as httpm from '@actions/http-client';
import * as sys from './system';
import crypto from 'crypto';
import cp from 'child_process';
import fs from 'fs';
import os from 'os';
@ -112,7 +113,9 @@ export async function getGo(
// Use a distinct tool cache name for custom downloads to avoid
// colliding with the runner's pre-installed Go
const toolCacheName = customBaseUrl ? 'go-custom' : 'go';
const toolCacheName = customBaseUrl
? customToolCacheName(customBaseUrl)
: 'go';
// check cache
const toolPath = tc.find(toolCacheName, versionSpec, arch);
@ -294,6 +297,11 @@ async function addExecutablesToToolCache(
);
}
export function customToolCacheName(baseUrl: string): string {
const hash = crypto.createHash('sha256').update(baseUrl).digest('hex');
return `go-${hash.substring(0, 8)}`;
}
async function installGoVersion(
info: IGoVersionInfo,
auth: string | undefined,