@@ -91,26 +91,43 @@ runs:
9191 }
9292
9393 let relativeWorkingDirectory = path.relative(process.env.GITHUB_WORKSPACE, workingDirectory) || '.';
94- let isOutsideWorkspace = false ;
94+ let cacheDependencyPathPrefix = relativeWorkingDirectory ;
9595
9696 if (relativeWorkingDirectory.startsWith('../')) {
97- core.warning(`Working directory "${workingDirectory}" is outside GITHUB_WORKSPACE. Caching will be disabled for setup-node.`);
98- isOutsideWorkspace = true;
97+ // Working directory is outside GITHUB_WORKSPACE
98+ // Create a symlink inside GITHUB_WORKSPACE to enable caching
99+ const symlinkName = '.github-actions-cache';
100+ const symlinkPath = path.join(process.env.GITHUB_WORKSPACE, symlinkName);
101+
102+ try {
103+ // Remove existing symlink if it exists
104+ if (fs.existsSync(symlinkPath)) {
105+ fs.unlinkSync(symlinkPath);
106+ }
107+
108+ // Create symlink pointing to the working directory
109+ fs.symlinkSync(workingDirectory, symlinkPath, 'dir');
110+ core.info(`Created symlink at "${symlinkPath}" pointing to "${workingDirectory}" to enable caching.`);
111+ cacheDependencyPathPrefix = symlinkName;
112+ } catch (error) {
113+ core.warning(`Failed to create symlink for caching: ${error.message}. Caching will be disabled.`);
114+ cacheDependencyPathPrefix = '';
115+ }
99116 }
100117
101118 const packageManagerConfig = {
102119 yarn: {
103- cacheDependencyPath: isOutsideWorkspace ? '' : `${relativeWorkingDirectory }/**/yarn.lock`,
120+ cacheDependencyPath: cacheDependencyPathPrefix ? `${cacheDependencyPathPrefix }/**/yarn.lock` : '' ,
104121 installCommand: 'yarn install --frozen-lockfile',
105122 runScriptCommand: 'yarn',
106123 },
107124 pnpm: {
108- cacheDependencyPath: isOutsideWorkspace ? '' : `${relativeWorkingDirectory }/**/pnpm-lock.yaml`,
125+ cacheDependencyPath: cacheDependencyPathPrefix ? `${cacheDependencyPathPrefix }/**/pnpm-lock.yaml` : '' ,
109126 installCommand: 'pnpm install --frozen-lockfile',
110127 runScriptCommand: 'pnpm',
111128 },
112129 npm: {
113- cacheDependencyPath: isOutsideWorkspace ? '' : `${relativeWorkingDirectory }/**/package-lock.json`,
130+ cacheDependencyPath: cacheDependencyPathPrefix ? `${cacheDependencyPathPrefix }/**/package-lock.json` : '' ,
114131 installCommand: 'npm ci',
115132 runScriptCommand: 'npm run',
116133 },
0 commit comments