Skip to content

Commit 5b62d9d

Browse files
Copilotneilime
andcommitted
fix: disable caching when working directory is outside GITHUB_WORKSPACE
Co-authored-by: neilime <[email protected]>
1 parent 55bc77c commit 5b62d9d

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

actions/get-package-manager/action.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,26 @@ runs:
9191
}
9292
9393
let relativeWorkingDirectory = path.relative(process.env.GITHUB_WORKSPACE, workingDirectory) || '.';
94+
let isOutsideWorkspace = false;
95+
9496
if (relativeWorkingDirectory.startsWith('../')) {
95-
relativeWorkingDirectory = path.resolve(workingDirectory);
97+
core.warning(`Working directory "${workingDirectory}" is outside GITHUB_WORKSPACE. Caching will be disabled for setup-node.`);
98+
isOutsideWorkspace = true;
9699
}
97100
98101
const packageManagerConfig = {
99102
yarn: {
100-
cacheDependencyPath: `${relativeWorkingDirectory}/**/yarn.lock`,
103+
cacheDependencyPath: isOutsideWorkspace ? '' : `${relativeWorkingDirectory}/**/yarn.lock`,
101104
installCommand: 'yarn install --frozen-lockfile',
102105
runScriptCommand: 'yarn',
103106
},
104107
pnpm: {
105-
cacheDependencyPath: `${relativeWorkingDirectory}/**/pnpm-lock.yaml`,
108+
cacheDependencyPath: isOutsideWorkspace ? '' : `${relativeWorkingDirectory}/**/pnpm-lock.yaml`,
106109
installCommand: 'pnpm install --frozen-lockfile',
107110
runScriptCommand: 'pnpm',
108111
},
109112
npm: {
110-
cacheDependencyPath: `${relativeWorkingDirectory}/**/package-lock.json`,
113+
cacheDependencyPath: isOutsideWorkspace ? '' : `${relativeWorkingDirectory}/**/package-lock.json`,
111114
installCommand: 'npm ci',
112115
runScriptCommand: 'npm run',
113116
},

actions/setup-node/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ runs:
138138
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
139139
with:
140140
node-version-file: ${{ steps.get-node-version-file.outputs.node-version-file }}
141-
cache: ${{ steps.get-package-manager.outputs.package-manager }}
141+
cache: ${{ steps.get-package-manager.outputs.cache-dependency-path != '' && steps.get-package-manager.outputs.package-manager || '' }}
142142
cache-dependency-path: ${{ steps.get-package-manager.outputs.cache-dependency-path }}
143143

144144
- shell: bash

0 commit comments

Comments
 (0)