Skip to content

Commit 930ff22

Browse files
committed
Fix Install on Windows is very slow
1 parent 08b314a commit 930ff22

File tree

2 files changed

+57
-13
lines changed

2 files changed

+57
-13
lines changed

dist/setup/index.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61441,6 +61441,14 @@ function resolveVersionFromManifest(versionSpec, stable, auth, arch, manifest) {
6144161441
}
6144261442
});
6144361443
}
61444+
function addExecutablesToCache(extPath, info, arch) {
61445+
return __awaiter(this, void 0, void 0, function* () {
61446+
core.info('Adding to the cache ...');
61447+
const cachedDir = yield tc.cacheDir(extPath, 'go', makeSemver(info.resolvedVersion), arch);
61448+
core.info(`Successfully cached go to ${cachedDir}`);
61449+
return cachedDir;
61450+
});
61451+
}
6144461452
function installGoVersion(info, auth, arch) {
6144561453
return __awaiter(this, void 0, void 0, function* () {
6144661454
core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
@@ -61455,10 +61463,21 @@ function installGoVersion(info, auth, arch) {
6145561463
if (info.type === 'dist') {
6145661464
extPath = path.join(extPath, 'go');
6145761465
}
61458-
core.info('Adding to the cache ...');
61459-
const cachedDir = yield tc.cacheDir(extPath, 'go', makeSemver(info.resolvedVersion), arch);
61460-
core.info(`Successfully cached go to ${cachedDir}`);
61461-
return cachedDir;
61466+
if (isWindows) {
61467+
const oldCacheDir = process.env['RUNNER_TOOL_CACHE'] || '';
61468+
const tempCacheDir = oldCacheDir.replace('C:', 'D:').replace('c:', 'd:');
61469+
process.env['RUNNER_TOOL_CACHE'] = tempCacheDir;
61470+
const cachedDir = yield addExecutablesToCache(extPath, info, arch);
61471+
const lnkDest = cachedDir;
61472+
const lnkSrc = lnkDest.replace(tempCacheDir, oldCacheDir);
61473+
const lnkSrcDir = path.dirname(lnkSrc);
61474+
fs_1.default.mkdirSync(lnkSrcDir, { recursive: true });
61475+
fs_1.default.symlinkSync(lnkDest, lnkSrc, 'junction');
61476+
core.info(`Created link ${lnkSrc} => ${lnkDest}`);
61477+
process.env['RUNNER_TOOL_CACHE'] = oldCacheDir;
61478+
return cachedDir.replace(tempCacheDir, oldCacheDir);
61479+
}
61480+
return yield addExecutablesToCache(extPath, info, arch);
6146261481
});
6146361482
}
6146461483
function extractGoArchive(archivePath) {

src/installer.ts

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,22 @@ async function resolveVersionFromManifest(
164164
}
165165
}
166166

167+
async function addExecutablesToCache(
168+
extPath: string,
169+
info: IGoVersionInfo,
170+
arch: string
171+
): Promise<string> {
172+
core.info('Adding to the cache ...');
173+
const cachedDir = await tc.cacheDir(
174+
extPath,
175+
'go',
176+
makeSemver(info.resolvedVersion),
177+
arch
178+
);
179+
core.info(`Successfully cached go to ${cachedDir}`);
180+
return cachedDir;
181+
}
182+
167183
async function installGoVersion(
168184
info: IGoVersionInfo,
169185
auth: string | undefined,
@@ -185,15 +201,24 @@ async function installGoVersion(
185201
extPath = path.join(extPath, 'go');
186202
}
187203

188-
core.info('Adding to the cache ...');
189-
const cachedDir = await tc.cacheDir(
190-
extPath,
191-
'go',
192-
makeSemver(info.resolvedVersion),
193-
arch
194-
);
195-
core.info(`Successfully cached go to ${cachedDir}`);
196-
return cachedDir;
204+
if (isWindows) {
205+
const oldCacheDir = process.env['RUNNER_TOOL_CACHE'] || '';
206+
const tempCacheDir = oldCacheDir.replace('C:', 'D:').replace('c:', 'd:');
207+
process.env['RUNNER_TOOL_CACHE'] = tempCacheDir;
208+
209+
const cachedDir = await addExecutablesToCache(extPath, info, arch);
210+
211+
const lnkDest = cachedDir;
212+
const lnkSrc = lnkDest.replace(tempCacheDir, oldCacheDir);
213+
const lnkSrcDir = path.dirname(lnkSrc);
214+
fs.mkdirSync(lnkSrcDir, {recursive: true});
215+
fs.symlinkSync(lnkDest, lnkSrc, 'junction');
216+
core.info(`Created link ${lnkSrc} => ${lnkDest}`);
217+
process.env['RUNNER_TOOL_CACHE'] = oldCacheDir;
218+
return cachedDir.replace(tempCacheDir, oldCacheDir);
219+
}
220+
221+
return await addExecutablesToCache(extPath, info, arch);
197222
}
198223

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

0 commit comments

Comments
 (0)