Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Install on Windows is very slow #393

Merged
merged 16 commits into from
Aug 3, 2023
Prev Previous commit
Next Next commit
refactor conditions
  • Loading branch information
dsame committed Jul 17, 2023
commit 8998c6804e4448fb670c93965cdcdb77e3b0d3ae
45 changes: 23 additions & 22 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61466,31 +61466,32 @@ function installGoVersion(info, auth, arch) {
}
// for github hosted windows runner handle latency of OS drive
// by avoiding write operations to C:
if (!isWindows)
return addExecutablesToCache(extPath, info, arch);
const isHosted = process.env['RUNNER_ENVIRONMENT'] === 'github-hosted' ||
process.env['AGENT_ISSELFHOSTED'] === '0';
if (!isHosted)
return addExecutablesToCache(extPath, info, arch);
const defaultToolCacheRoot = process.env['RUNNER_TOOL_CACHE'];
if (isWindows &&
defaultToolCacheRoot &&
isHosted &&
fs_1.default.existsSync('d:\\') &&
fs_1.default.existsSync('c:\\')) {
const substitutedToolCacheRoot = defaultToolCacheRoot
.replace('C:', 'D:')
.replace('c:', 'd:');
// make toolcache root to be on drive d:
process.env['RUNNER_TOOL_CACHE'] = substitutedToolCacheRoot;
const actualToolCacheDir = yield addExecutablesToCache(extPath, info, arch);
// create a link from c: to d:
const defaultToolCacheDir = actualToolCacheDir.replace(substitutedToolCacheRoot, defaultToolCacheRoot);
fs_1.default.mkdirSync(path.dirname(defaultToolCacheDir), { recursive: true });
fs_1.default.symlinkSync(actualToolCacheDir, defaultToolCacheDir, 'junction');
core.info(`Created link ${defaultToolCacheDir} => ${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 defaultToolCacheDir;
}
return yield addExecutablesToCache(extPath, info, arch);
if (!defaultToolCacheRoot)
return addExecutablesToCache(extPath, info, arch);
if (!fs_1.default.existsSync('d:\\') || !fs_1.default.existsSync('c:\\'))
return addExecutablesToCache(extPath, info, arch);
const substitutedToolCacheRoot = defaultToolCacheRoot
.replace('C:', 'D:')
.replace('c:', 'd:');
// make toolcache root to be on drive d:
process.env['RUNNER_TOOL_CACHE'] = substitutedToolCacheRoot;
const actualToolCacheDir = yield addExecutablesToCache(extPath, info, arch);
// create a link from c: to d:
const defaultToolCacheDir = actualToolCacheDir.replace(substitutedToolCacheRoot, defaultToolCacheRoot);
fs_1.default.mkdirSync(path.dirname(defaultToolCacheDir), { recursive: true });
fs_1.default.symlinkSync(actualToolCacheDir, defaultToolCacheDir, 'junction');
core.info(`Created link ${defaultToolCacheDir} => ${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 defaultToolCacheDir;
});
}
function extractGoArchive(archivePath) {
Expand Down
58 changes: 29 additions & 29 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,42 +203,42 @@ async function installGoVersion(

// for github hosted windows runner handle latency of OS drive
// by avoiding write operations to C:

if (!isWindows) return addExecutablesToCache(extPath, info, arch);

const isHosted =
process.env['RUNNER_ENVIRONMENT'] === 'github-hosted' ||
process.env['AGENT_ISSELFHOSTED'] === '0';
if (!isHosted) return addExecutablesToCache(extPath, info, arch);

const defaultToolCacheRoot = process.env['RUNNER_TOOL_CACHE'];
if (
isWindows &&
defaultToolCacheRoot &&
isHosted &&
fs.existsSync('d:\\') &&
fs.existsSync('c:\\')
) {
const substitutedToolCacheRoot = defaultToolCacheRoot
.replace('C:', 'D:')
.replace('c:', 'd:');
// make toolcache root to be on drive d:
process.env['RUNNER_TOOL_CACHE'] = substitutedToolCacheRoot;

const actualToolCacheDir = await addExecutablesToCache(extPath, info, arch);

// create a link from c: to d:
const defaultToolCacheDir = actualToolCacheDir.replace(
substitutedToolCacheRoot,
defaultToolCacheRoot
);
fs.mkdirSync(path.dirname(defaultToolCacheDir), {recursive: true});
fs.symlinkSync(actualToolCacheDir, defaultToolCacheDir, 'junction');
core.info(`Created link ${defaultToolCacheDir} => ${actualToolCacheDir}`);
if (!defaultToolCacheRoot) return addExecutablesToCache(extPath, info, arch);

// restore toolcache root to default drive c:
process.env['RUNNER_TOOL_CACHE'] = defaultToolCacheRoot;
if (!fs.existsSync('d:\\') || !fs.existsSync('c:\\'))
return addExecutablesToCache(extPath, info, arch);

// make outer code to continue using toolcache as if it were installed on c:
return defaultToolCacheDir;
}
const substitutedToolCacheRoot = defaultToolCacheRoot
.replace('C:', 'D:')
.replace('c:', 'd:');
// make toolcache root to be on drive d:
process.env['RUNNER_TOOL_CACHE'] = substitutedToolCacheRoot;

const actualToolCacheDir = await addExecutablesToCache(extPath, info, arch);

// create a link from c: to d:
const defaultToolCacheDir = actualToolCacheDir.replace(
substitutedToolCacheRoot,
defaultToolCacheRoot
);
fs.mkdirSync(path.dirname(defaultToolCacheDir), {recursive: true});
fs.symlinkSync(actualToolCacheDir, defaultToolCacheDir, 'junction');
core.info(`Created link ${defaultToolCacheDir} => ${actualToolCacheDir}`);

// restore toolcache root to default drive c:
process.env['RUNNER_TOOL_CACHE'] = defaultToolCacheRoot;

return await addExecutablesToCache(extPath, info, arch);
// make outer code to continue using toolcache as if it were installed on c:
return defaultToolCacheDir;
}

export async function extractGoArchive(archivePath: string): Promise<string> {
Expand Down