Add GOCACHE AND GOMODCACHE symlink on Windows

Use D drive for faster cache restore

Signed-off-by: Anton Troshin <anton@diagrid.io>
pull/515/head
Anton Troshin 2 months ago
parent 41dfa10bad
commit 28b19b8019
No known key found for this signature in database
GPG Key ID: 9F8A96ACA9EB6363

@ -88259,6 +88259,7 @@ const sys = __importStar(__nccwpck_require__(5632));
const fs_1 = __importDefault(__nccwpck_require__(7147));
const os_1 = __importDefault(__nccwpck_require__(2037));
const utils_1 = __nccwpck_require__(1314);
const cache_utils_1 = __nccwpck_require__(1678);
function getGo(versionSpec_1, checkLatest_1, auth_1) {
return __awaiter(this, arguments, void 0, function* (versionSpec, checkLatest, auth, arch = os_1.default.arch()) {
var _a;
@ -88383,6 +88384,27 @@ function cacheWindowsDir(extPath, tool, version, arch) {
const defaultToolCacheCompleteFile = `${defaultToolCacheDir}.complete`;
fs_1.default.symlinkSync(actualToolCacheCompleteFile, defaultToolCacheCompleteFile, 'file');
core.info(`Created link ${defaultToolCacheCompleteFile} => ${actualToolCacheCompleteFile}`);
const packageManager = 'default';
const packageManagerInfo = yield (0, cache_utils_1.getPackageManagerInfo)(packageManager);
const cacheDirectoryPaths = yield (0, cache_utils_1.getCacheDirectoryPath)(packageManagerInfo);
if (!cacheDirectoryPaths) {
throw new Error(`Could not get cache folder paths.`);
}
// replace cache directory path with actual cache directory path
const actualCacheDirectoryPaths = cacheDirectoryPaths.map(path => {
return {
defaultPath: path,
actualPath: path.replace('D:', 'C:').replace('d:', 'c:')
};
});
// iterate through actual cache directory paths and make links
for (const cachePath of actualCacheDirectoryPaths) {
if (!fs_1.default.existsSync(cachePath.actualPath)) {
fs_1.default.mkdirSync(path.dirname(cachePath.actualPath), { recursive: true });
}
fs_1.default.symlinkSync(cachePath.actualPath, cachePath.defaultPath, 'junction');
core.info(`Created link ${cachePath.defaultPath} => ${cachePath.actualPath}`);
}
// make outer code to continue using toolcache as if it were installed on c:
// restore toolcache root to default drive c:
process.env['RUNNER_TOOL_CACHE'] = defaultToolCacheRoot;

@ -7,6 +7,7 @@ import * as sys from './system';
import fs from 'fs';
import os from 'os';
import {StableReleaseAlias} from './utils';
import {getCacheDirectoryPath, getPackageManagerInfo} from './cache-utils';
type InstallationType = 'dist' | 'manifest';
@ -214,6 +215,33 @@ async function cacheWindowsDir(
`Created link ${defaultToolCacheCompleteFile} => ${actualToolCacheCompleteFile}`
);
const packageManager = 'default';
const packageManagerInfo = await getPackageManagerInfo(packageManager);
const cacheDirectoryPaths = await getCacheDirectoryPath(packageManagerInfo);
if (!cacheDirectoryPaths) {
throw new Error(`Could not get cache folder paths.`);
}
// replace cache directory path with actual cache directory path
const actualCacheDirectoryPaths = cacheDirectoryPaths.map(path => {
return {
defaultPath: path,
actualPath: path.replace('D:', 'C:').replace('d:', 'c:')
};
});
// iterate through actual cache directory paths and make links
for (const cachePath of actualCacheDirectoryPaths) {
if (!fs.existsSync(cachePath.actualPath)) {
fs.mkdirSync(path.dirname(cachePath.actualPath), {recursive: true});
}
fs.symlinkSync(cachePath.actualPath, cachePath.defaultPath, 'junction');
core.info(
`Created link ${cachePath.defaultPath} => ${cachePath.actualPath}`
);
}
// make outer code to continue using toolcache as if it were installed on c:
// restore toolcache root to default drive c:
process.env['RUNNER_TOOL_CACHE'] = defaultToolCacheRoot;

Loading…
Cancel
Save