mirror of
https://github.com/actions/setup-go.git
synced 2026-04-14 16:16:51 +00:00
handle distinct cache
This commit is contained in:
parent
3efc8fd0e3
commit
fa4cd7679b
3 changed files with 23 additions and 5 deletions
|
|
@ -1421,7 +1421,8 @@ use .
|
||||||
// Mock the installed Go binary reporting a different patch version
|
// Mock the installed Go binary reporting a different patch version
|
||||||
execFileSpy.mockImplementation(() => 'go version go1.20.14 linux/amd64');
|
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);
|
cacheSpy.mockImplementation(async () => toolPath);
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
@ -1432,7 +1433,7 @@ use .
|
||||||
// Cache key should use actual version, not the input spec
|
// Cache key should use actual version, not the input spec
|
||||||
expect(cacheSpy).toHaveBeenCalledWith(
|
expect(cacheSpy).toHaveBeenCalledWith(
|
||||||
expect.any(String),
|
expect.any(String),
|
||||||
'go-custom',
|
expectedToolName,
|
||||||
'1.20.14',
|
'1.20.14',
|
||||||
'x64'
|
'x64'
|
||||||
);
|
);
|
||||||
|
|
@ -1558,7 +1559,8 @@ use .
|
||||||
findSpy.mockImplementation(() => '');
|
findSpy.mockImplementation(() => '');
|
||||||
dlSpy.mockImplementation(async () => '/some/temp/path');
|
dlSpy.mockImplementation(async () => '/some/temp/path');
|
||||||
extractTarSpy.mockImplementation(async () => '/some/other/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);
|
cacheSpy.mockImplementation(async () => toolPath);
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
|
||||||
10
dist/setup/index.js
vendored
10
dist/setup/index.js
vendored
|
|
@ -77034,6 +77034,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.GOTOOLCHAIN_LOCAL_VAL = exports.GOTOOLCHAIN_ENV_VAR = void 0;
|
exports.GOTOOLCHAIN_LOCAL_VAL = exports.GOTOOLCHAIN_ENV_VAR = void 0;
|
||||||
exports.getGo = getGo;
|
exports.getGo = getGo;
|
||||||
|
exports.customToolCacheName = customToolCacheName;
|
||||||
exports.extractGoArchive = extractGoArchive;
|
exports.extractGoArchive = extractGoArchive;
|
||||||
exports.getManifest = getManifest;
|
exports.getManifest = getManifest;
|
||||||
exports.getInfoFromManifest = getInfoFromManifest;
|
exports.getInfoFromManifest = getInfoFromManifest;
|
||||||
|
|
@ -77049,6 +77050,7 @@ const path = __importStar(__nccwpck_require__(16928));
|
||||||
const semver = __importStar(__nccwpck_require__(62088));
|
const semver = __importStar(__nccwpck_require__(62088));
|
||||||
const httpm = __importStar(__nccwpck_require__(54844));
|
const httpm = __importStar(__nccwpck_require__(54844));
|
||||||
const sys = __importStar(__nccwpck_require__(57666));
|
const sys = __importStar(__nccwpck_require__(57666));
|
||||||
|
const crypto_1 = __importDefault(__nccwpck_require__(76982));
|
||||||
const child_process_1 = __importDefault(__nccwpck_require__(35317));
|
const child_process_1 = __importDefault(__nccwpck_require__(35317));
|
||||||
const fs_1 = __importDefault(__nccwpck_require__(79896));
|
const fs_1 = __importDefault(__nccwpck_require__(79896));
|
||||||
const os_1 = __importDefault(__nccwpck_require__(70857));
|
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
|
// Use a distinct tool cache name for custom downloads to avoid
|
||||||
// colliding with the runner's pre-installed Go
|
// colliding with the runner's pre-installed Go
|
||||||
const toolCacheName = customBaseUrl ? 'go-custom' : 'go';
|
const toolCacheName = customBaseUrl
|
||||||
|
? customToolCacheName(customBaseUrl)
|
||||||
|
: 'go';
|
||||||
// check cache
|
// check cache
|
||||||
const toolPath = tc.find(toolCacheName, versionSpec, arch);
|
const toolPath = tc.find(toolCacheName, versionSpec, arch);
|
||||||
// If not found in cache, download
|
// 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)));
|
(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) {
|
function installGoVersion(info_1, auth_1, arch_1) {
|
||||||
return __awaiter(this, arguments, void 0, function* (info, auth, arch, toolName = 'go') {
|
return __awaiter(this, arguments, void 0, function* (info, auth, arch, toolName = 'go') {
|
||||||
core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
|
core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import * as path from 'path';
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
import * as httpm from '@actions/http-client';
|
import * as httpm from '@actions/http-client';
|
||||||
import * as sys from './system';
|
import * as sys from './system';
|
||||||
|
import crypto from 'crypto';
|
||||||
import cp from 'child_process';
|
import cp from 'child_process';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
|
|
@ -112,7 +113,9 @@ export async function getGo(
|
||||||
|
|
||||||
// Use a distinct tool cache name for custom downloads to avoid
|
// Use a distinct tool cache name for custom downloads to avoid
|
||||||
// colliding with the runner's pre-installed Go
|
// colliding with the runner's pre-installed Go
|
||||||
const toolCacheName = customBaseUrl ? 'go-custom' : 'go';
|
const toolCacheName = customBaseUrl
|
||||||
|
? customToolCacheName(customBaseUrl)
|
||||||
|
: 'go';
|
||||||
|
|
||||||
// check cache
|
// check cache
|
||||||
const toolPath = tc.find(toolCacheName, versionSpec, arch);
|
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(
|
async function installGoVersion(
|
||||||
info: IGoVersionInfo,
|
info: IGoVersionInfo,
|
||||||
auth: string | undefined,
|
auth: string | undefined,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue