mirror of
https://github.com/actions/setup-python.git
synced 2025-04-24 15:32:13 +00:00
Include Python version in pip cache key
This commit is contained in:
parent
156361d073
commit
4f512f8afc
3 changed files with 8 additions and 9 deletions
|
@ -92,13 +92,9 @@ describe('restore-cache', () => {
|
||||||
dependencyFile
|
dependencyFile
|
||||||
);
|
);
|
||||||
await cacheDistributor.restoreCache();
|
await cacheDistributor.restoreCache();
|
||||||
let pythonKey = '';
|
|
||||||
if (packageManager === 'pipenv') {
|
|
||||||
pythonKey = `python-${pythonVersion}-`;
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(infoSpy).toHaveBeenCalledWith(
|
expect(infoSpy).toHaveBeenCalledWith(
|
||||||
`Cache restored from key: setup-python-${process.env['RUNNER_OS']}-${pythonKey}${packageManager}-${fileHash}`
|
`Cache restored from key: setup-python-${process.env['RUNNER_OS']}-python-${pythonVersion}-${packageManager}-${fileHash}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -13,7 +13,7 @@ export function getCacheDistributor(
|
||||||
) {
|
) {
|
||||||
switch (packageManager) {
|
switch (packageManager) {
|
||||||
case PackageManagers.Pip:
|
case PackageManagers.Pip:
|
||||||
return new PipCache(cacheDependencyPath);
|
return new PipCache(pythonVersion, cacheDependencyPath);
|
||||||
case PackageManagers.Pipenv:
|
case PackageManagers.Pipenv:
|
||||||
return new PipenvCache(pythonVersion, cacheDependencyPath);
|
return new PipenvCache(pythonVersion, cacheDependencyPath);
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -8,7 +8,10 @@ import os from 'os';
|
||||||
import CacheDistributor from './cache-distributor';
|
import CacheDistributor from './cache-distributor';
|
||||||
|
|
||||||
class PipCache extends CacheDistributor {
|
class PipCache extends CacheDistributor {
|
||||||
constructor(cacheDependencyPath: string = '**/requirements.txt') {
|
constructor(
|
||||||
|
private pythonVersion: string,
|
||||||
|
cacheDependencyPath: string = '**/requirements.txt'
|
||||||
|
) {
|
||||||
super('pip', cacheDependencyPath);
|
super('pip', cacheDependencyPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,8 +39,8 @@ class PipCache extends CacheDistributor {
|
||||||
|
|
||||||
protected async computeKeys() {
|
protected async computeKeys() {
|
||||||
const hash = await glob.hashFiles(this.cacheDependencyPath);
|
const hash = await glob.hashFiles(this.cacheDependencyPath);
|
||||||
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${this.packageManager}-${hash}`;
|
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
|
||||||
const restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${this.packageManager}`;
|
const restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
primaryKey,
|
primaryKey,
|
||||||
|
|
Loading…
Add table
Reference in a new issue