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
27 changes: 23 additions & 4 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61441,6 +61441,14 @@ function resolveVersionFromManifest(versionSpec, stable, auth, arch, manifest) {
}
});
}
function addExecutablesToCache(extPath, info, arch) {
return __awaiter(this, void 0, void 0, function* () {
core.info('Adding to the cache ...');
const cachedDir = yield tc.cacheDir(extPath, 'go', makeSemver(info.resolvedVersion), arch);
core.info(`Successfully cached go to ${cachedDir}`);
return cachedDir;
});
}
function installGoVersion(info, auth, arch) {
return __awaiter(this, void 0, void 0, function* () {
core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
Expand All @@ -61455,10 +61463,21 @@ function installGoVersion(info, auth, arch) {
if (info.type === 'dist') {
extPath = path.join(extPath, 'go');
}
core.info('Adding to the cache ...');
const cachedDir = yield tc.cacheDir(extPath, 'go', makeSemver(info.resolvedVersion), arch);
core.info(`Successfully cached go to ${cachedDir}`);
return cachedDir;
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 cachedDir = yield addExecutablesToCache(extPath, info, arch);
const lnkDest = cachedDir;
const lnkSrc = lnkDest.replace(tempCacheDir, oldCacheDir);
const lnkSrcDir = path.dirname(lnkSrc);
fs_1.default.mkdirSync(lnkSrcDir, { recursive: true });
fs_1.default.symlinkSync(lnkDest, lnkSrc, 'junction');
core.info(`Created link ${lnkSrc} => ${lnkDest}`);
process.env['RUNNER_TOOL_CACHE'] = oldCacheDir;
return cachedDir.replace(tempCacheDir, oldCacheDir);
}
return yield addExecutablesToCache(extPath, info, arch);
});
}
function extractGoArchive(archivePath) {
Expand Down
43 changes: 34 additions & 9 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,22 @@ async function resolveVersionFromManifest(
}
}

async function addExecutablesToCache(
extPath: string,
info: IGoVersionInfo,
arch: string
): Promise<string> {
core.info('Adding to the cache ...');
const cachedDir = await tc.cacheDir(
extPath,
'go',
makeSemver(info.resolvedVersion),
arch
);
core.info(`Successfully cached go to ${cachedDir}`);
return cachedDir;
}

async function installGoVersion(
info: IGoVersionInfo,
auth: string | undefined,
Expand All @@ -185,15 +201,24 @@ async function installGoVersion(
extPath = path.join(extPath, 'go');
}

core.info('Adding to the cache ...');
const cachedDir = await tc.cacheDir(
extPath,
'go',
makeSemver(info.resolvedVersion),
arch
);
core.info(`Successfully cached go to ${cachedDir}`);
return cachedDir;
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 cachedDir = 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);
}

return await addExecutablesToCache(extPath, info, arch);
}

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