Skip to content

Commit ba33a69

Browse files
authored
Include Python version in pip cache key (#303)
1 parent 156361d commit ba33a69

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

Diff for: __tests__/cache-restore.test.ts

+1-5
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
);

Diff for: dist/setup/index.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -34467,8 +34467,9 @@ const path = __importStar(__webpack_require__(622));
3446734467
const os_1 = __importDefault(__webpack_require__(87));
3446834468
const cache_distributor_1 = __importDefault(__webpack_require__(435));
3446934469
class PipCache extends cache_distributor_1.default {
34470-
constructor(cacheDependencyPath = '**/requirements.txt') {
34470+
constructor(pythonVersion, cacheDependencyPath = '**/requirements.txt') {
3447134471
super('pip', cacheDependencyPath);
34472+
this.pythonVersion = pythonVersion;
3447234473
}
3447334474
getCacheGlobalDirectories() {
3447434475
return __awaiter(this, void 0, void 0, function* () {
@@ -34487,8 +34488,8 @@ class PipCache extends cache_distributor_1.default {
3448734488
computeKeys() {
3448834489
return __awaiter(this, void 0, void 0, function* () {
3448934490
const hash = yield glob.hashFiles(this.cacheDependencyPath);
34490-
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${this.packageManager}-${hash}`;
34491-
const restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${this.packageManager}`;
34491+
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
34492+
const restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}`;
3449234493
return {
3449334494
primaryKey,
3449434495
restoreKey: [restoreKey]
@@ -43888,7 +43889,7 @@ var PackageManagers;
4388843889
function getCacheDistributor(packageManager, pythonVersion, cacheDependencyPath) {
4388943890
switch (packageManager) {
4389043891
case PackageManagers.Pip:
43891-
return new pip_cache_1.default(cacheDependencyPath);
43892+
return new pip_cache_1.default(pythonVersion, cacheDependencyPath);
4389243893
case PackageManagers.Pipenv:
4389343894
return new pipenv_cache_1.default(pythonVersion, cacheDependencyPath);
4389443895
default:

Diff for: src/cache-distributions/cache-factory.ts

+1-1
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:

Diff for: src/cache-distributions/pip-cache.ts

+6-3
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)