diff --git a/actions/get-package-manager/action.yml b/actions/get-package-manager/action.yml index 35d09e0..3165a01 100644 --- a/actions/get-package-manager/action.yml +++ b/actions/get-package-manager/action.yml @@ -91,23 +91,43 @@ runs: } let relativeWorkingDirectory = path.relative(process.env.GITHUB_WORKSPACE, workingDirectory) || '.'; + let cacheDependencyPathPrefix = relativeWorkingDirectory; + if (relativeWorkingDirectory.startsWith('../')) { - relativeWorkingDirectory = path.resolve(workingDirectory); + // Working directory is outside GITHUB_WORKSPACE + // Create a symlink inside GITHUB_WORKSPACE to enable caching + const symlinkName = '.github-actions-cache'; + const symlinkPath = path.join(process.env.GITHUB_WORKSPACE, symlinkName); + + try { + // Remove existing symlink if it exists + if (fs.existsSync(symlinkPath)) { + fs.unlinkSync(symlinkPath); + } + + // Create symlink pointing to the working directory + fs.symlinkSync(workingDirectory, symlinkPath, 'dir'); + core.info(`Created symlink at "${symlinkPath}" pointing to "${workingDirectory}" to enable caching.`); + cacheDependencyPathPrefix = symlinkName; + } catch (error) { + core.warning(`Failed to create symlink for caching: ${error.message}. Caching will be disabled.`); + cacheDependencyPathPrefix = ''; + } } const packageManagerConfig = { yarn: { - cacheDependencyPath: `${relativeWorkingDirectory}/**/yarn.lock`, + cacheDependencyPath: cacheDependencyPathPrefix ? `${cacheDependencyPathPrefix}/**/yarn.lock` : '', installCommand: 'yarn install --frozen-lockfile', runScriptCommand: 'yarn', }, pnpm: { - cacheDependencyPath: `${relativeWorkingDirectory}/**/pnpm-lock.yaml`, + cacheDependencyPath: cacheDependencyPathPrefix ? `${cacheDependencyPathPrefix}/**/pnpm-lock.yaml` : '', installCommand: 'pnpm install --frozen-lockfile', runScriptCommand: 'pnpm', }, npm: { - cacheDependencyPath: `${relativeWorkingDirectory}/**/package-lock.json`, + cacheDependencyPath: cacheDependencyPathPrefix ? `${cacheDependencyPathPrefix}/**/package-lock.json` : '', installCommand: 'npm ci', runScriptCommand: 'npm run', }, diff --git a/actions/setup-node/action.yml b/actions/setup-node/action.yml index 61caef8..8327671 100644 --- a/actions/setup-node/action.yml +++ b/actions/setup-node/action.yml @@ -138,7 +138,7 @@ runs: - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 with: node-version-file: ${{ steps.get-node-version-file.outputs.node-version-file }} - cache: ${{ steps.get-package-manager.outputs.package-manager }} + cache: ${{ steps.get-package-manager.outputs.cache-dependency-path != '' && steps.get-package-manager.outputs.package-manager || '' }} cache-dependency-path: ${{ steps.get-package-manager.outputs.cache-dependency-path }} - shell: bash