1
0
Fork 0
mirror of https://code.forgejo.org/actions/setup-go synced 2025-06-19 00:20:25 +02:00

Improve readability

This commit is contained in:
Sergey Dolin 2023-07-12 00:28:42 +02:00
parent 93ae31f0a4
commit 1c500a4414
2 changed files with 39 additions and 25 deletions

View file

@ -202,20 +202,29 @@ async function installGoVersion(
}
if (isWindows) {
const oldCacheDir = process.env['RUNNER_TOOL_CACHE'] || '';
const tempCacheDir = oldCacheDir.replace('C:', 'D:').replace('c:', 'd:');
process.env['RUNNER_TOOL_CACHE'] = tempCacheDir;
const defaultToolCacheRoot = process.env['RUNNER_TOOL_CACHE'] || '';
const substitutedToolCacheRoot = defaultToolCacheRoot
.replace('C:', 'D:')
.replace('c:', 'd:');
// make toolcache root to be on drive d:
process.env['RUNNER_TOOL_CACHE'] = substitutedToolCacheRoot;
const cachedDir = await addExecutablesToCache(extPath, info, arch);
const actualToolCacheDir = await addExecutablesToCache(extPath, info, arch);
const lnkDest = cachedDir;
const lnkSrc = lnkDest.replace(tempCacheDir, oldCacheDir);
const lnkSrcDir = path.dirname(lnkSrc);
fs.mkdirSync(lnkSrcDir, {recursive: true});
fs.symlinkSync(lnkDest, lnkSrc, 'junction');
core.info(`Created link ${lnkSrc} => ${lnkDest}`);
process.env['RUNNER_TOOL_CACHE'] = oldCacheDir;
return cachedDir.replace(tempCacheDir, oldCacheDir);
// create a link from c: to d:
const lnkSrc = actualToolCacheDir.replace(
substitutedToolCacheRoot,
defaultToolCacheRoot
);
fs.mkdirSync(path.dirname(lnkSrc), {recursive: true});
fs.symlinkSync(actualToolCacheDir, lnkSrc, 'junction');
core.info(`Created link ${lnkSrc} => ${actualToolCacheDir}`);
// restore toolcache root to default drive c:
process.env['RUNNER_TOOL_CACHE'] = defaultToolCacheRoot;
// make outer code to continue using toolcache as if it were installed on c:
return lnkSrc;
}
return await addExecutablesToCache(extPath, info, arch);