Add GOCACHE AND GOMODCACHE symlink on Windows

Use D drive for faster cache restore

Signed-off-by: Anton Troshin <anton@diagrid.io>
This commit is contained in:
Anton Troshin 2024-11-18 18:53:10 -06:00
parent 41dfa10bad
commit 28b19b8019
No known key found for this signature in database
GPG key ID: 9F8A96ACA9EB6363
2 changed files with 50 additions and 0 deletions

View file

@ -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;