8000 Include Python version in pip cache key · actions/setup-python@95b9974 · GitHub
[go: up one dir, main page]

Skip to content

Commit 95b9974

Browse files
committed
Include Python version in pip cache key
1 parent 6277dd1 commit 95b9974

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

__tests__/cache-restore.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,9 @@ describe('restore-cache', () => {
9292
dependencyFile
9393
);
9494
await cacheDistributor.restoreCache();
95-
let pythonKey = '';
96-
if (packageManager === 'pipenv') {
97-
pythonKey = `python-${pythonVersion}-`;
98-
}
9995

10096
expect(infoSpy).toHaveBeenCalledWith(
101-
`Cache restored from key: setup-python-${process.env['RUNNER_OS']}-${pythonKey}${packageManager}-${fileHash}`
97+
`Cache restored from key: setup-python-${process.env['RUNNER_OS']}-python-${pythonVersion}-${packageManager}-${fileHash}`
10298
);
10399
}
104100
);

src/cache-distributions/cache-factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function getCacheDistributor(
1313
) {
1414
switch (packageManager) {
1515
case PackageManagers.Pip:
16-
return new PipCache(cacheDependencyPath);
16+
return new PipCache(pythonVersion, cacheDependencyPath);
1717
case PackageManagers.Pipenv:
1818
return new PipenvCache(pythonVersion, cacheDependencyPath);
1919
default:

src/cache-distributions/pip-cache.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import os from 'os';
88
import CacheDistributor from './cache-distributor';
99

1010
class PipCache extends CacheDistributor {
11-
constructor(cacheDependencyPath: string = '**/requirements.txt') {
11+
constructor(
12+
private pythonVersion: string,
13+
cacheDependencyPath: string = '**/requirements.txt'
14+
) {
1215
super('pip', cacheDependencyPath);
1316
}
1417

@@ -36,8 +39,8 @@ class PipCache extends CacheDistributor {
3639

3740
protected async computeKeys() {
3841
const hash = await glob.hashFiles(this.cacheDependencyPath);
39-
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${this.packageManager}-${hash}`;
40-
const restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${this.packageManager}`;
42+
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
43+
const restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}`;
4144

4245
return {
4346
primaryKey,

0 commit comments

Comments
 (0)
0