From 28b19b80190a65f721f9cc30796abe6ccc09d942 Mon Sep 17 00:00:00 2001 From: Anton Troshin Date: Mon, 18 Nov 2024 18:53:10 -0600 Subject: [PATCH 01/15] Add GOCACHE AND GOMODCACHE symlink on Windows Use D drive for faster cache restore Signed-off-by: Anton Troshin --- dist/setup/index.js | 22 ++++++++++++++++++++++ src/installer.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/dist/setup/index.js b/dist/setup/index.js index f21396aa6..3266f9236 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -88259,6 +88259,7 @@ const sys = __importStar(__nccwpck_require__(5632)); const fs_1 = __importDefault(__nccwpck_require__(7147)); const os_1 = __importDefault(__nccwpck_require__(2037)); const utils_1 = __nccwpck_require__(1314); +const cache_utils_1 = __nccwpck_require__(1678); function getGo(versionSpec_1, checkLatest_1, auth_1) { return __awaiter(this, arguments, void 0, function* (versionSpec, checkLatest, auth, arch = os_1.default.arch()) { var _a; @@ -88383,6 +88384,27 @@ function cacheWindowsDir(extPath, tool, version, arch) { const defaultToolCacheCompleteFile = `${defaultToolCacheDir}.complete`; fs_1.default.symlinkSync(actualToolCacheCompleteFile, defaultToolCacheCompleteFile, 'file'); core.info(`Created link ${defaultToolCacheCompleteFile} => ${actualToolCacheCompleteFile}`); + const packageManager = 'default'; + const packageManagerInfo = yield (0, cache_utils_1.getPackageManagerInfo)(packageManager); + const cacheDirectoryPaths = yield (0, cache_utils_1.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_1.default.existsSync(cachePath.actualPath)) { + fs_1.default.mkdirSync(path.dirname(cachePath.actualPath), { recursive: true }); + } + fs_1.default.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; diff --git a/src/installer.ts b/src/installer.ts index 817c334f6..20014de21 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -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; From 0859a18f70b7ee0c0b7a1035437d23b2f95b110b Mon Sep 17 00:00:00 2001 From: Anton Troshin Date: Mon, 18 Nov 2024 19:24:46 -0600 Subject: [PATCH 02/15] add logs Signed-off-by: Anton Troshin --- src/installer.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/installer.ts b/src/installer.ts index 20014de21..2298a2490 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -222,6 +222,8 @@ async function cacheWindowsDir( throw new Error(`Could not get cache folder paths.`); } + core.info(`Found Cache Directory Paths: ${cacheDirectoryPaths}`); + // replace cache directory path with actual cache directory path const actualCacheDirectoryPaths = cacheDirectoryPaths.map(path => { return { @@ -233,6 +235,7 @@ async function cacheWindowsDir( // iterate through actual cache directory paths and make links for (const cachePath of actualCacheDirectoryPaths) { if (!fs.existsSync(cachePath.actualPath)) { + core.info(`Creating directory ${cachePath.actualPath}`); fs.mkdirSync(path.dirname(cachePath.actualPath), {recursive: true}); } From 97e00a50c1c1d2851e2977ce5d261be34a828816 Mon Sep 17 00:00:00 2001 From: Anton Troshin Date: Mon, 18 Nov 2024 19:26:53 -0600 Subject: [PATCH 03/15] build Signed-off-by: Anton Troshin --- dist/setup/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dist/setup/index.js b/dist/setup/index.js index 3266f9236..b9bd4edff 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -88390,6 +88390,7 @@ function cacheWindowsDir(extPath, tool, version, arch) { if (!cacheDirectoryPaths) { throw new Error(`Could not get cache folder paths.`); } + core.info(`Found Cache Directory Paths: ${cacheDirectoryPaths}`); // replace cache directory path with actual cache directory path const actualCacheDirectoryPaths = cacheDirectoryPaths.map(path => { return { @@ -88400,6 +88401,7 @@ function cacheWindowsDir(extPath, tool, version, arch) { // iterate through actual cache directory paths and make links for (const cachePath of actualCacheDirectoryPaths) { if (!fs_1.default.existsSync(cachePath.actualPath)) { + core.info(`Creating directory ${cachePath.actualPath}`); fs_1.default.mkdirSync(path.dirname(cachePath.actualPath), { recursive: true }); } fs_1.default.symlinkSync(cachePath.actualPath, cachePath.defaultPath, 'junction'); From 434fb1707877f3ce0bca58b1b10e2bb0f8d7c02a Mon Sep 17 00:00:00 2001 From: Anton Troshin Date: Tue, 19 Nov 2024 10:50:13 -0600 Subject: [PATCH 04/15] Fix path replace Signed-off-by: Anton Troshin --- src/installer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/installer.ts b/src/installer.ts index 2298a2490..66d4c9540 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -228,7 +228,7 @@ async function cacheWindowsDir( const actualCacheDirectoryPaths = cacheDirectoryPaths.map(path => { return { defaultPath: path, - actualPath: path.replace('D:', 'C:').replace('d:', 'c:') + actualPath: path.replace('C:', 'D:').replace('c:', 'd:') }; }); From 0dc6404f6a8765723e9068eab8d6b32ae25456ce Mon Sep 17 00:00:00 2001 From: Anton Troshin Date: Tue, 19 Nov 2024 11:50:35 -0600 Subject: [PATCH 05/15] add check for existing symlink Signed-off-by: Anton Troshin --- src/installer.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/installer.ts b/src/installer.ts index 66d4c9540..1fada71ce 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -223,7 +223,7 @@ async function cacheWindowsDir( } core.info(`Found Cache Directory Paths: ${cacheDirectoryPaths}`); - + // replace cache directory path with actual cache directory path const actualCacheDirectoryPaths = cacheDirectoryPaths.map(path => { return { @@ -232,17 +232,24 @@ async function cacheWindowsDir( }; }); - // iterate through actual cache directory paths and make links + // iterate through actual cache directory paths and make links if necessary for (const cachePath of actualCacheDirectoryPaths) { if (!fs.existsSync(cachePath.actualPath)) { core.info(`Creating directory ${cachePath.actualPath}`); fs.mkdirSync(path.dirname(cachePath.actualPath), {recursive: true}); + } else { + core.info(`Directory ${cachePath.actualPath} already exists`); + // make sure the link is pointing to the actual cache directory + let symlinkTarget = fs.readlinkSync(cachePath.defaultPath); + if (symlinkTarget !== "") { + core.info(`Found link ${cachePath.defaultPath} => ${symlinkTarget}`); + } else { + fs.symlinkSync(cachePath.actualPath, cachePath.defaultPath, 'junction'); + core.info( + `Created link ${cachePath.defaultPath} => ${cachePath.actualPath}` + ); + } } - - 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: From 6cd0eaadd68563a2f5aa1e6d82fe11ebc8ba0c6e Mon Sep 17 00:00:00 2001 From: Anton Troshin Date: Tue, 19 Nov 2024 12:09:58 -0600 Subject: [PATCH 06/15] lint and build Signed-off-by: Anton Troshin --- dist/setup/index.js | 18 ++++++++++++++---- src/installer.ts | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index b9bd4edff..a21c0799d 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -88395,17 +88395,27 @@ function cacheWindowsDir(extPath, tool, version, arch) { const actualCacheDirectoryPaths = cacheDirectoryPaths.map(path => { return { defaultPath: path, - actualPath: path.replace('D:', 'C:').replace('d:', 'c:') + actualPath: path.replace('C:', 'D:').replace('c:', 'd:') }; }); - // iterate through actual cache directory paths and make links + // iterate through actual cache directory paths and make links if necessary for (const cachePath of actualCacheDirectoryPaths) { if (!fs_1.default.existsSync(cachePath.actualPath)) { core.info(`Creating directory ${cachePath.actualPath}`); fs_1.default.mkdirSync(path.dirname(cachePath.actualPath), { recursive: true }); } - fs_1.default.symlinkSync(cachePath.actualPath, cachePath.defaultPath, 'junction'); - core.info(`Created link ${cachePath.defaultPath} => ${cachePath.actualPath}`); + else { + core.info(`Directory ${cachePath.actualPath} already exists`); + // make sure the link is pointing to the actual cache directory + const symlinkTarget = fs_1.default.readlinkSync(cachePath.defaultPath); + if (symlinkTarget !== "") { + core.info(`Found link ${cachePath.defaultPath} => ${symlinkTarget}`); + } + else { + fs_1.default.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: diff --git a/src/installer.ts b/src/installer.ts index 1fada71ce..dc66e01e9 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -240,7 +240,7 @@ async function cacheWindowsDir( } else { core.info(`Directory ${cachePath.actualPath} already exists`); // make sure the link is pointing to the actual cache directory - let symlinkTarget = fs.readlinkSync(cachePath.defaultPath); + const symlinkTarget = fs.readlinkSync(cachePath.defaultPath); if (symlinkTarget !== "") { core.info(`Found link ${cachePath.defaultPath} => ${symlinkTarget}`); } else { From fd3fcb34ee39ab9729bba70e064c6c55cca83950 Mon Sep 17 00:00:00 2001 From: Anton Troshin Date: Tue, 19 Nov 2024 12:28:31 -0600 Subject: [PATCH 07/15] move symlink check Signed-off-by: Anton Troshin --- src/installer.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/installer.ts b/src/installer.ts index dc66e01e9..ef7940ed9 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -239,16 +239,16 @@ async function cacheWindowsDir( fs.mkdirSync(path.dirname(cachePath.actualPath), {recursive: true}); } else { core.info(`Directory ${cachePath.actualPath} already exists`); - // make sure the link is pointing to the actual cache directory - const symlinkTarget = fs.readlinkSync(cachePath.defaultPath); - if (symlinkTarget !== "") { - core.info(`Found link ${cachePath.defaultPath} => ${symlinkTarget}`); - } else { - fs.symlinkSync(cachePath.actualPath, cachePath.defaultPath, 'junction'); - core.info( - `Created link ${cachePath.defaultPath} => ${cachePath.actualPath}` - ); - } + } + // make sure the link is pointing to the actual cache directory + const symlinkTarget = fs.readlinkSync(cachePath.defaultPath); + if (symlinkTarget !== "") { + core.info(`Found link ${cachePath.defaultPath} => ${symlinkTarget}`); + } else { + fs.symlinkSync(cachePath.actualPath, cachePath.defaultPath, 'junction'); + core.info( + `Created link ${cachePath.defaultPath} => ${cachePath.actualPath}` + ); } } From 896e2cbf0f3ef789193ebbb55ee66985369bac9f Mon Sep 17 00:00:00 2001 From: Anton Troshin Date: Tue, 19 Nov 2024 13:05:53 -0600 Subject: [PATCH 08/15] add logs Signed-off-by: Anton Troshin --- dist/setup/index.js | 20 +++++++++++--------- src/installer.ts | 2 ++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index a21c0799d..fff2f6cb9 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -88400,21 +88400,23 @@ function cacheWindowsDir(extPath, tool, version, arch) { }); // iterate through actual cache directory paths and make links if necessary for (const cachePath of actualCacheDirectoryPaths) { + core.info(`Trying to link ${cachePath.defaultPath} to ${cachePath.actualPath}`); if (!fs_1.default.existsSync(cachePath.actualPath)) { core.info(`Creating directory ${cachePath.actualPath}`); fs_1.default.mkdirSync(path.dirname(cachePath.actualPath), { recursive: true }); } else { core.info(`Directory ${cachePath.actualPath} already exists`); - // make sure the link is pointing to the actual cache directory - const symlinkTarget = fs_1.default.readlinkSync(cachePath.defaultPath); - if (symlinkTarget !== "") { - core.info(`Found link ${cachePath.defaultPath} => ${symlinkTarget}`); - } - else { - fs_1.default.symlinkSync(cachePath.actualPath, cachePath.defaultPath, 'junction'); - core.info(`Created link ${cachePath.defaultPath} => ${cachePath.actualPath}`); - } + } + // make sure the link is pointing to the actual cache directory + const symlinkTarget = fs_1.default.readlinkSync(cachePath.defaultPath); + core.info(`Symlink target: ${symlinkTarget}`); + if (symlinkTarget !== "") { + core.info(`Found link ${cachePath.defaultPath} => ${symlinkTarget}`); + } + else { + fs_1.default.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: diff --git a/src/installer.ts b/src/installer.ts index ef7940ed9..f617662a7 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -234,6 +234,7 @@ async function cacheWindowsDir( // iterate through actual cache directory paths and make links if necessary for (const cachePath of actualCacheDirectoryPaths) { + core.info(`Trying to link ${cachePath.defaultPath} to ${cachePath.actualPath}`); if (!fs.existsSync(cachePath.actualPath)) { core.info(`Creating directory ${cachePath.actualPath}`); fs.mkdirSync(path.dirname(cachePath.actualPath), {recursive: true}); @@ -242,6 +243,7 @@ async function cacheWindowsDir( } // make sure the link is pointing to the actual cache directory const symlinkTarget = fs.readlinkSync(cachePath.defaultPath); + core.info(`Symlink target: ${symlinkTarget}`); if (symlinkTarget !== "") { core.info(`Found link ${cachePath.defaultPath} => ${symlinkTarget}`); } else { From c8eefa5dde1822ec9819c2ffc4b7a539749ec980 Mon Sep 17 00:00:00 2001 From: Anton Troshin Date: Tue, 19 Nov 2024 16:20:55 -0600 Subject: [PATCH 09/15] wrap with try, debugging errors Signed-off-by: Anton Troshin --- src/installer.ts | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/installer.ts b/src/installer.ts index f617662a7..0554c174b 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -235,22 +235,28 @@ async function cacheWindowsDir( // iterate through actual cache directory paths and make links if necessary for (const cachePath of actualCacheDirectoryPaths) { core.info(`Trying to link ${cachePath.defaultPath} to ${cachePath.actualPath}`); - if (!fs.existsSync(cachePath.actualPath)) { - core.info(`Creating directory ${cachePath.actualPath}`); - fs.mkdirSync(path.dirname(cachePath.actualPath), {recursive: true}); - } else { - core.info(`Directory ${cachePath.actualPath} already exists`); - } - // make sure the link is pointing to the actual cache directory - const symlinkTarget = fs.readlinkSync(cachePath.defaultPath); - core.info(`Symlink target: ${symlinkTarget}`); - if (symlinkTarget !== "") { - core.info(`Found link ${cachePath.defaultPath} => ${symlinkTarget}`); - } else { - fs.symlinkSync(cachePath.actualPath, cachePath.defaultPath, 'junction'); - core.info( - `Created link ${cachePath.defaultPath} => ${cachePath.actualPath}` - ); + try { + if (!fs.existsSync(cachePath.actualPath)) { + core.info(`Creating directory ${cachePath.actualPath}`); + fs.mkdirSync(path.dirname(cachePath.actualPath), {recursive: true}); + } else { + core.info(`Directory ${cachePath.actualPath} already exists`); + } + + // check if the default path is a symlink + const isSymlink = fs.lstatSync(cachePath.defaultPath).isSymbolicLink(); + if (isSymlink) { + core.info(`Default path is symlink ${cachePath.defaultPath} => ${fs.readlinkSync(cachePath.defaultPath)}`); + } else { + core.info(`Default path is not a symlink ${cachePath.defaultPath}`); + fs.symlinkSync(cachePath.actualPath, cachePath.defaultPath, 'junction'); + core.info( + `Created link ${cachePath.defaultPath} => ${cachePath.actualPath}` + ); + } + } catch (err) { + core.info(`Failed to link ${cachePath.defaultPath} to ${cachePath.actualPath}`); + core.info('Error: ' + err); } } From f8cf508b5f3daba90b792418d1992464cd4d1e4a Mon Sep 17 00:00:00 2001 From: Anton Troshin Date: Tue, 19 Nov 2024 16:21:45 -0600 Subject: [PATCH 10/15] lint and build Signed-off-by: Anton Troshin --- dist/setup/index.js | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index fff2f6cb9..c8becb4a0 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -88401,22 +88401,28 @@ function cacheWindowsDir(extPath, tool, version, arch) { // iterate through actual cache directory paths and make links if necessary for (const cachePath of actualCacheDirectoryPaths) { core.info(`Trying to link ${cachePath.defaultPath} to ${cachePath.actualPath}`); - if (!fs_1.default.existsSync(cachePath.actualPath)) { - core.info(`Creating directory ${cachePath.actualPath}`); - fs_1.default.mkdirSync(path.dirname(cachePath.actualPath), { recursive: true }); - } - else { - core.info(`Directory ${cachePath.actualPath} already exists`); - } - // make sure the link is pointing to the actual cache directory - const symlinkTarget = fs_1.default.readlinkSync(cachePath.defaultPath); - core.info(`Symlink target: ${symlinkTarget}`); - if (symlinkTarget !== "") { - core.info(`Found link ${cachePath.defaultPath} => ${symlinkTarget}`); + try { + if (!fs_1.default.existsSync(cachePath.actualPath)) { + core.info(`Creating directory ${cachePath.actualPath}`); + fs_1.default.mkdirSync(path.dirname(cachePath.actualPath), { recursive: true }); + } + else { + core.info(`Directory ${cachePath.actualPath} already exists`); + } + // check if the default path is a symlink + const isSymlink = fs_1.default.lstatSync(cachePath.defaultPath).isSymbolicLink(); + if (isSymlink) { + core.info(`Default path is symlink ${cachePath.defaultPath} => ${fs_1.default.readlinkSync(cachePath.defaultPath)}`); + } + else { + core.info(`Default path is not a symlink ${cachePath.defaultPath}`); + fs_1.default.symlinkSync(cachePath.actualPath, cachePath.defaultPath, 'junction'); + core.info(`Created link ${cachePath.defaultPath} => ${cachePath.actualPath}`); + } } - else { - fs_1.default.symlinkSync(cachePath.actualPath, cachePath.defaultPath, 'junction'); - core.info(`Created link ${cachePath.defaultPath} => ${cachePath.actualPath}`); + catch (err) { + core.info(`Failed to link ${cachePath.defaultPath} to ${cachePath.actualPath}`); + core.info('Error: ' + err); } } // make outer code to continue using toolcache as if it were installed on c: From e3c077dd6d61ff27961ce60b46770be8bf66298f Mon Sep 17 00:00:00 2001 From: Anton Troshin Date: Tue, 19 Nov 2024 16:51:26 -0600 Subject: [PATCH 11/15] more logs and logic change Signed-off-by: Anton Troshin --- dist/setup/index.js | 11 ++++++++--- src/installer.ts | 11 ++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index c8becb4a0..af35fb67f 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -88402,12 +88402,17 @@ function cacheWindowsDir(extPath, tool, version, arch) { for (const cachePath of actualCacheDirectoryPaths) { core.info(`Trying to link ${cachePath.defaultPath} to ${cachePath.actualPath}`); try { + if (!fs_1.default.existsSync(cachePath.defaultPath)) { + core.info(`Default path ${cachePath.defaultPath} does not exist`); + core.info(`Creating directory ${cachePath.defaultPath}`); + fs_1.default.mkdirSync(cachePath.defaultPath, { recursive: true }); + } if (!fs_1.default.existsSync(cachePath.actualPath)) { - core.info(`Creating directory ${cachePath.actualPath}`); - fs_1.default.mkdirSync(path.dirname(cachePath.actualPath), { recursive: true }); + core.info(`Actual path ${cachePath.actualPath} does not exist. Safe to create symlink`); } else { - core.info(`Directory ${cachePath.actualPath} already exists`); + core.info(`Actual path ${cachePath.actualPath} already exists. Skipping symlink creation`); + continue; } // check if the default path is a symlink const isSymlink = fs_1.default.lstatSync(cachePath.defaultPath).isSymbolicLink(); diff --git a/src/installer.ts b/src/installer.ts index 0554c174b..235a64043 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -236,11 +236,16 @@ async function cacheWindowsDir( for (const cachePath of actualCacheDirectoryPaths) { core.info(`Trying to link ${cachePath.defaultPath} to ${cachePath.actualPath}`); try { + if (!fs.existsSync(cachePath.defaultPath)) { + core.info(`Default path ${cachePath.defaultPath} does not exist`); + core.info(`Creating directory ${cachePath.defaultPath}`); + fs.mkdirSync(cachePath.defaultPath, {recursive: true}); + } if (!fs.existsSync(cachePath.actualPath)) { - core.info(`Creating directory ${cachePath.actualPath}`); - fs.mkdirSync(path.dirname(cachePath.actualPath), {recursive: true}); + core.info(`Actual path ${cachePath.actualPath} does not exist. Safe to create symlink`); } else { - core.info(`Directory ${cachePath.actualPath} already exists`); + core.info(`Actual path ${cachePath.actualPath} already exists. Skipping symlink creation`); + continue; } // check if the default path is a symlink From e91efc513ba578e447b6a5f6909f789836a5e190 Mon Sep 17 00:00:00 2001 From: Anton Troshin Date: Tue, 19 Nov 2024 19:27:12 -0600 Subject: [PATCH 12/15] fix Signed-off-by: Anton Troshin --- src/installer.ts | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/src/installer.ts b/src/installer.ts index 235a64043..1935d0c75 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -236,29 +236,20 @@ async function cacheWindowsDir( for (const cachePath of actualCacheDirectoryPaths) { core.info(`Trying to link ${cachePath.defaultPath} to ${cachePath.actualPath}`); try { - if (!fs.existsSync(cachePath.defaultPath)) { - core.info(`Default path ${cachePath.defaultPath} does not exist`); - core.info(`Creating directory ${cachePath.defaultPath}`); - fs.mkdirSync(cachePath.defaultPath, {recursive: true}); - } - if (!fs.existsSync(cachePath.actualPath)) { - core.info(`Actual path ${cachePath.actualPath} does not exist. Safe to create symlink`); - } else { - core.info(`Actual path ${cachePath.actualPath} already exists. Skipping symlink creation`); - continue; + // the symlink already exists, skip + if (fs.existsSync(cachePath.defaultPath) && fs.lstatSync(cachePath.defaultPath).isSymbolicLink()) { + continue } + // create a parent directory where the link will be created + fs.mkdirSync(path.dirname(cachePath.defaultPath), {recursive: true}); - // check if the default path is a symlink - const isSymlink = fs.lstatSync(cachePath.defaultPath).isSymbolicLink(); - if (isSymlink) { - core.info(`Default path is symlink ${cachePath.defaultPath} => ${fs.readlinkSync(cachePath.defaultPath)}`); - } else { - core.info(`Default path is not a symlink ${cachePath.defaultPath}`); - fs.symlinkSync(cachePath.actualPath, cachePath.defaultPath, 'junction'); - core.info( - `Created link ${cachePath.defaultPath} => ${cachePath.actualPath}` - ); + // create the target directory if it doesn't exist yet + if (!fs.existsSync(cachePath.actualPath)) { + core.info(`Actual path ${cachePath.actualPath} does not exist. Creating`); + fs.mkdirSync(cachePath.actualPath, {recursive: true}); } + fs.symlinkSync(cachePath.actualPath, cachePath.defaultPath, 'junction'); + core.info(`Created link ${cachePath.defaultPath} => ${cachePath.actualPath}`); } catch (err) { core.info(`Failed to link ${cachePath.defaultPath} to ${cachePath.actualPath}`); core.info('Error: ' + err); From 5b1dffca1bbe160a20cb9cb84b59215de4153933 Mon Sep 17 00:00:00 2001 From: Anton Troshin Date: Tue, 19 Nov 2024 20:15:14 -0600 Subject: [PATCH 13/15] remove empty cache folders to be able to create symlinks Signed-off-by: Anton Troshin --- dist/setup/index.js | 33 +++++++++++++++++---------------- src/installer.ts | 11 ++++++++++- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index af35fb67f..eea6899cb 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -88402,28 +88402,29 @@ function cacheWindowsDir(extPath, tool, version, arch) { for (const cachePath of actualCacheDirectoryPaths) { core.info(`Trying to link ${cachePath.defaultPath} to ${cachePath.actualPath}`); try { - if (!fs_1.default.existsSync(cachePath.defaultPath)) { - core.info(`Default path ${cachePath.defaultPath} does not exist`); - core.info(`Creating directory ${cachePath.defaultPath}`); - fs_1.default.mkdirSync(cachePath.defaultPath, { recursive: true }); + // the symlink already exists, skip + const stats = fs_1.default.lstatSync(cachePath.defaultPath); + if (fs_1.default.existsSync(cachePath.defaultPath) && stats.isSymbolicLink()) { + core.info(`Directory ${cachePath.defaultPath} already linked. Skipping`); + continue; } - if (!fs_1.default.existsSync(cachePath.actualPath)) { - core.info(`Actual path ${cachePath.actualPath} does not exist. Safe to create symlink`); + // the directory is empty, delete it to be able to create a symlink + if (stats.size == 0) { + fs_1.default.rmSync(cachePath.defaultPath, { recursive: true, force: true }); } else { - core.info(`Actual path ${cachePath.actualPath} already exists. Skipping symlink creation`); + core.info(`Directory ${cachePath.defaultPath} is not empty. Skipping`); continue; } - // check if the default path is a symlink - const isSymlink = fs_1.default.lstatSync(cachePath.defaultPath).isSymbolicLink(); - if (isSymlink) { - core.info(`Default path is symlink ${cachePath.defaultPath} => ${fs_1.default.readlinkSync(cachePath.defaultPath)}`); - } - else { - core.info(`Default path is not a symlink ${cachePath.defaultPath}`); - fs_1.default.symlinkSync(cachePath.actualPath, cachePath.defaultPath, 'junction'); - core.info(`Created link ${cachePath.defaultPath} => ${cachePath.actualPath}`); + // create a parent directory where the link will be created + fs_1.default.mkdirSync(path.dirname(cachePath.defaultPath), { recursive: true }); + // create the target directory if it doesn't exist yet + if (!fs_1.default.existsSync(cachePath.actualPath)) { + core.info(`Actual path ${cachePath.actualPath} does not exist. Creating`); + fs_1.default.mkdirSync(cachePath.actualPath, { recursive: true }); } + fs_1.default.symlinkSync(cachePath.actualPath, cachePath.defaultPath, 'junction'); + core.info(`Created link ${cachePath.defaultPath} => ${cachePath.actualPath}`); } catch (err) { core.info(`Failed to link ${cachePath.defaultPath} to ${cachePath.actualPath}`); diff --git a/src/installer.ts b/src/installer.ts index 1935d0c75..6157b4235 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -237,9 +237,18 @@ async function cacheWindowsDir( core.info(`Trying to link ${cachePath.defaultPath} to ${cachePath.actualPath}`); try { // the symlink already exists, skip - if (fs.existsSync(cachePath.defaultPath) && fs.lstatSync(cachePath.defaultPath).isSymbolicLink()) { + const stats = fs.lstatSync(cachePath.defaultPath); + if (fs.existsSync(cachePath.defaultPath) && stats.isSymbolicLink()) { + core.info(`Directory ${cachePath.defaultPath} already linked. Skipping`); continue } + // the directory is empty, delete it to be able to create a symlink + if (stats.size == 0) { + fs.rmSync(cachePath.defaultPath, {recursive: true, force: true}); + } else { + core.info(`Directory ${cachePath.defaultPath} is not empty. Skipping`); + continue; + } // create a parent directory where the link will be created fs.mkdirSync(path.dirname(cachePath.defaultPath), {recursive: true}); From be775566d415d0c8252ad1602eb01ab091ce3fee Mon Sep 17 00:00:00 2001 From: Anton Troshin Date: Tue, 19 Nov 2024 21:15:12 -0600 Subject: [PATCH 14/15] try different approach by overriding go ENV GOCACHE and GOMODCACHE vars for Windows Signed-off-by: Anton Troshin --- dist/setup/index.js | 27 ++++++++++++++++++++++++++- src/cache-restore.ts | 33 +++++++++++++++++++++++++++++++-- src/main.ts | 3 ++- 3 files changed, 59 insertions(+), 4 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index eea6899cb..1c59f6918 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -88034,7 +88034,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.restoreCache = void 0; +exports.setWindowsCacheDirectories = exports.restoreCache = void 0; const cache = __importStar(__nccwpck_require__(7799)); const core = __importStar(__nccwpck_require__(2186)); const glob = __importStar(__nccwpck_require__(8090)); @@ -88042,6 +88042,7 @@ const path_1 = __importDefault(__nccwpck_require__(1017)); const fs_1 = __importDefault(__nccwpck_require__(7147)); const constants_1 = __nccwpck_require__(9042); const cache_utils_1 = __nccwpck_require__(1678); +const os_1 = __importDefault(__nccwpck_require__(2037)); const restoreCache = (versionSpec, packageManager, cacheDependencyPath) => __awaiter(void 0, void 0, void 0, function* () { const packageManagerInfo = yield (0, cache_utils_1.getPackageManagerInfo)(packageManager); const platform = process.env.RUNNER_OS; @@ -88069,6 +88070,29 @@ const restoreCache = (versionSpec, packageManager, cacheDependencyPath) => __awa core.info(`Cache restored from key: ${cacheKey}`); }); exports.restoreCache = restoreCache; +const setWindowsCacheDirectories = () => __awaiter(void 0, void 0, void 0, function* () { + if (os_1.default.platform() !== 'win32') + return; + let goCache = yield (0, cache_utils_1.getCommandOutput)(`go env GOCACHE`); + core.info(`GOCACHE: ${goCache}`); + goCache = goCache.replace('C:', 'D:').replace('c:', 'd:'); + if (!fs_1.default.existsSync(goCache)) { + core.info(`${goCache} does not exist. Creating`); + fs_1.default.mkdirSync(goCache, { recursive: true }); + } + const setOutput = yield (0, cache_utils_1.getCommandOutput)(`go env -w GOCACHE=${goCache}`); + core.info(`go env -w GOCACHE output: ${setOutput}`); + let goModCache = yield (0, cache_utils_1.getCommandOutput)(`go env GOMODCACHE`); + core.info(`GOMODCACHE: ${goModCache}`); + goModCache = goModCache.replace('C:', 'D:').replace('c:', 'd:'); + if (!fs_1.default.existsSync(goModCache)) { + core.info(`${goModCache} does not exist. Creating`); + fs_1.default.mkdirSync(goModCache, { recursive: true }); + } + const setModOutput = yield (0, cache_utils_1.getCommandOutput)(`go env -w GOMODCACHE=${goModCache}`); + core.info(`go env -w GOMODCACHE output: ${setModOutput}`); +}); +exports.setWindowsCacheDirectories = setWindowsCacheDirectories; const findDependencyFile = (packageManager) => { const dependencyFile = packageManager.dependencyFilePattern; const workspace = process.env.GITHUB_WORKSPACE; @@ -88701,6 +88725,7 @@ const os_1 = __importDefault(__nccwpck_require__(2037)); function run() { return __awaiter(this, void 0, void 0, function* () { try { + yield (0, cache_restore_1.setWindowsCacheDirectories)(); // // versionSpec is optional. If supplied, install / use from the tool cache // If not supplied then problem matchers will still be setup. Useful for self-hosted. diff --git a/src/cache-restore.ts b/src/cache-restore.ts index 18d930bdf..47898ad46 100644 --- a/src/cache-restore.ts +++ b/src/cache-restore.ts @@ -4,9 +4,10 @@ import * as glob from '@actions/glob'; import path from 'path'; import fs from 'fs'; -import {State, Outputs} from './constants'; +import {Outputs, State} from './constants'; import {PackageManagerInfo} from './package-managers'; -import {getCacheDirectoryPath, getPackageManagerInfo} from './cache-utils'; +import {getCacheDirectoryPath, getCommandOutput, getPackageManagerInfo} from './cache-utils'; +import os from "os"; export const restoreCache = async ( versionSpec: string, @@ -50,6 +51,34 @@ export const restoreCache = async ( core.info(`Cache restored from key: ${cacheKey}`); }; +export const setWindowsCacheDirectories = async () => { + if (os.platform() !== 'win32') return; + + let goCache = await getCommandOutput(`go env GOCACHE`); + core.info(`GOCACHE: ${goCache}`); + goCache = goCache.replace('C:', 'D:').replace('c:', 'd:'); + + if (!fs.existsSync(goCache)) { + core.info(`${goCache} does not exist. Creating`); + fs.mkdirSync(goCache, {recursive: true}); + } + + const setOutput = await getCommandOutput(`go env -w GOCACHE=${goCache}`); + core.info(`go env -w GOCACHE output: ${setOutput}`); + + let goModCache = await getCommandOutput(`go env GOMODCACHE`); + core.info(`GOMODCACHE: ${goModCache}`); + goModCache = goModCache.replace('C:', 'D:').replace('c:', 'd:'); + + if (!fs.existsSync(goModCache)) { + core.info(`${goModCache} does not exist. Creating`); + fs.mkdirSync(goModCache, {recursive: true}); + } + + const setModOutput = await getCommandOutput(`go env -w GOMODCACHE=${goModCache}`); + core.info(`go env -w GOMODCACHE output: ${setModOutput}`); +}; + const findDependencyFile = (packageManager: PackageManagerInfo) => { const dependencyFile = packageManager.dependencyFilePattern; const workspace = process.env.GITHUB_WORKSPACE!; diff --git a/src/main.ts b/src/main.ts index 690d277f9..f4de9ae67 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,7 +3,7 @@ import * as io from '@actions/io'; import * as installer from './installer'; import * as semver from 'semver'; import path from 'path'; -import {restoreCache} from './cache-restore'; +import {restoreCache, setWindowsCacheDirectories} from './cache-restore'; import {isCacheFeatureAvailable} from './cache-utils'; import cp from 'child_process'; import fs from 'fs'; @@ -11,6 +11,7 @@ import os from 'os'; export async function run() { try { + await setWindowsCacheDirectories(); // // versionSpec is optional. If supplied, install / use from the tool cache // If not supplied then problem matchers will still be setup. Useful for self-hosted. From bda02de8887c9946189f81e7e59512914aeb9ea4 Mon Sep 17 00:00:00 2001 From: Anton Troshin Date: Tue, 19 Nov 2024 21:28:54 -0600 Subject: [PATCH 15/15] remove previous attempt logic Signed-off-by: Anton Troshin --- dist/setup/index.js | 48 ------------------------------------------ src/installer.ts | 51 --------------------------------------------- 2 files changed, 99 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 1c59f6918..490c489ec 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -88283,7 +88283,6 @@ const sys = __importStar(__nccwpck_require__(5632)); const fs_1 = __importDefault(__nccwpck_require__(7147)); const os_1 = __importDefault(__nccwpck_require__(2037)); const utils_1 = __nccwpck_require__(1314); -const cache_utils_1 = __nccwpck_require__(1678); function getGo(versionSpec_1, checkLatest_1, auth_1) { return __awaiter(this, arguments, void 0, function* (versionSpec, checkLatest, auth, arch = os_1.default.arch()) { var _a; @@ -88408,53 +88407,6 @@ function cacheWindowsDir(extPath, tool, version, arch) { const defaultToolCacheCompleteFile = `${defaultToolCacheDir}.complete`; fs_1.default.symlinkSync(actualToolCacheCompleteFile, defaultToolCacheCompleteFile, 'file'); core.info(`Created link ${defaultToolCacheCompleteFile} => ${actualToolCacheCompleteFile}`); - const packageManager = 'default'; - const packageManagerInfo = yield (0, cache_utils_1.getPackageManagerInfo)(packageManager); - const cacheDirectoryPaths = yield (0, cache_utils_1.getCacheDirectoryPath)(packageManagerInfo); - if (!cacheDirectoryPaths) { - throw new Error(`Could not get cache folder paths.`); - } - core.info(`Found Cache Directory Paths: ${cacheDirectoryPaths}`); - // replace cache directory path with actual cache directory path - const actualCacheDirectoryPaths = cacheDirectoryPaths.map(path => { - return { - defaultPath: path, - actualPath: path.replace('C:', 'D:').replace('c:', 'd:') - }; - }); - // iterate through actual cache directory paths and make links if necessary - for (const cachePath of actualCacheDirectoryPaths) { - core.info(`Trying to link ${cachePath.defaultPath} to ${cachePath.actualPath}`); - try { - // the symlink already exists, skip - const stats = fs_1.default.lstatSync(cachePath.defaultPath); - if (fs_1.default.existsSync(cachePath.defaultPath) && stats.isSymbolicLink()) { - core.info(`Directory ${cachePath.defaultPath} already linked. Skipping`); - continue; - } - // the directory is empty, delete it to be able to create a symlink - if (stats.size == 0) { - fs_1.default.rmSync(cachePath.defaultPath, { recursive: true, force: true }); - } - else { - core.info(`Directory ${cachePath.defaultPath} is not empty. Skipping`); - continue; - } - // create a parent directory where the link will be created - fs_1.default.mkdirSync(path.dirname(cachePath.defaultPath), { recursive: true }); - // create the target directory if it doesn't exist yet - if (!fs_1.default.existsSync(cachePath.actualPath)) { - core.info(`Actual path ${cachePath.actualPath} does not exist. Creating`); - fs_1.default.mkdirSync(cachePath.actualPath, { recursive: true }); - } - fs_1.default.symlinkSync(cachePath.actualPath, cachePath.defaultPath, 'junction'); - core.info(`Created link ${cachePath.defaultPath} => ${cachePath.actualPath}`); - } - catch (err) { - core.info(`Failed to link ${cachePath.defaultPath} to ${cachePath.actualPath}`); - core.info('Error: ' + err); - } - } // 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; diff --git a/src/installer.ts b/src/installer.ts index 6157b4235..817c334f6 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -7,7 +7,6 @@ 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'; @@ -215,56 +214,6 @@ 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.`); - } - - core.info(`Found Cache Directory Paths: ${cacheDirectoryPaths}`); - - // replace cache directory path with actual cache directory path - const actualCacheDirectoryPaths = cacheDirectoryPaths.map(path => { - return { - defaultPath: path, - actualPath: path.replace('C:', 'D:').replace('c:', 'd:') - }; - }); - - // iterate through actual cache directory paths and make links if necessary - for (const cachePath of actualCacheDirectoryPaths) { - core.info(`Trying to link ${cachePath.defaultPath} to ${cachePath.actualPath}`); - try { - // the symlink already exists, skip - const stats = fs.lstatSync(cachePath.defaultPath); - if (fs.existsSync(cachePath.defaultPath) && stats.isSymbolicLink()) { - core.info(`Directory ${cachePath.defaultPath} already linked. Skipping`); - continue - } - // the directory is empty, delete it to be able to create a symlink - if (stats.size == 0) { - fs.rmSync(cachePath.defaultPath, {recursive: true, force: true}); - } else { - core.info(`Directory ${cachePath.defaultPath} is not empty. Skipping`); - continue; - } - // create a parent directory where the link will be created - fs.mkdirSync(path.dirname(cachePath.defaultPath), {recursive: true}); - - // create the target directory if it doesn't exist yet - if (!fs.existsSync(cachePath.actualPath)) { - core.info(`Actual path ${cachePath.actualPath} does not exist. Creating`); - fs.mkdirSync(cachePath.actualPath, {recursive: true}); - } - fs.symlinkSync(cachePath.actualPath, cachePath.defaultPath, 'junction'); - core.info(`Created link ${cachePath.defaultPath} => ${cachePath.actualPath}`); - } catch (err) { - core.info(`Failed to link ${cachePath.defaultPath} to ${cachePath.actualPath}`); - core.info('Error: ' + err); - } - } - // 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;