Compare commits

...

5 Commits

Author SHA1 Message Date
sgpinkus
5b92af7be6
Merge d99639b3c5 into e348410e00 2025-04-12 12:24:41 +02:00
aparnajyothi-y
e348410e00
Remove Ubuntu 20.04 from workflows due to deprecation from 2025-04-15 (#1065)
Some checks failed
Validate Python e2e / check-latest (macos-13, 3.10) (push) Has been cancelled
Validate Python e2e / check-latest (macos-13, 3.11) (push) Has been cancelled
Validate Python e2e / check-latest (macos-13, 3.12) (push) Has been cancelled
Validate Python e2e / check-latest (macos-13, 3.13) (push) Has been cancelled
Validate Python e2e / check-latest (macos-13, 3.9) (push) Has been cancelled
Validate Python e2e / check-latest (macos-latest, 3.10) (push) Has been cancelled
Validate Python e2e / check-latest (macos-latest, 3.11) (push) Has been cancelled
Validate Python e2e / check-latest (macos-latest, 3.12) (push) Has been cancelled
Validate Python e2e / check-latest (macos-latest, 3.13) (push) Has been cancelled
Validate Python e2e / check-latest (macos-latest, 3.9) (push) Has been cancelled
Validate Python e2e / check-latest (ubuntu-22.04-arm, 3.10) (push) Has been cancelled
Validate Python e2e / check-latest (ubuntu-22.04-arm, 3.11) (push) Has been cancelled
Validate Python e2e / check-latest (ubuntu-22.04-arm, 3.12) (push) Has been cancelled
Validate Python e2e / check-latest (ubuntu-22.04-arm, 3.13) (push) Has been cancelled
Validate Python e2e / check-latest (ubuntu-22.04-arm, 3.9) (push) Has been cancelled
Validate Python e2e / check-latest (ubuntu-24.04-arm, 3.10) (push) Has been cancelled
Validate Python e2e / check-latest (ubuntu-24.04-arm, 3.11) (push) Has been cancelled
Validate Python e2e / check-latest (ubuntu-24.04-arm, 3.12) (push) Has been cancelled
Validate Python e2e / check-latest (ubuntu-24.04-arm, 3.13) (push) Has been cancelled
Validate Python e2e / check-latest (ubuntu-24.04-arm, 3.9) (push) Has been cancelled
Validate Python e2e / check-latest (windows-latest, 3.10) (push) Has been cancelled
Validate Python e2e / check-latest (windows-latest, 3.11) (push) Has been cancelled
Validate Python e2e / check-latest (windows-latest, 3.12) (push) Has been cancelled
Validate Python e2e / check-latest (windows-latest, 3.13) (push) Has been cancelled
Validate Python e2e / check-latest (windows-latest, 3.9) (push) Has been cancelled
Validate Python e2e / setup-python-multiple-python-versions (macos-13) (push) Has been cancelled
Validate Python e2e / setup-python-multiple-python-versions (macos-latest) (push) Has been cancelled
Validate Python e2e / setup-python-multiple-python-versions (ubuntu-22.04-arm) (push) Has been cancelled
Validate Python e2e / setup-python-multiple-python-versions (ubuntu-24.04-arm) (push) Has been cancelled
Validate Python e2e / setup-python-multiple-python-versions (windows-latest) (push) Has been cancelled
* remove ubuntu-20.04

* check failure fix

* remove spaces

* npm run format-check
2025-04-11 13:36:23 -05:00
Sam Pinkus
d99639b3c5 Code improvemnt: Rm CacheDistributor.cacheDependencyPath field and pass back from computeKeys instead, simplifying CacheDistributor.restoreCache error check. Rm now uneeded constant.ts file. 2025-02-19 17:13:15 +10:00
Sam Pinkus
0024ce0d14 Readability improvement: Move CacheDistributor constructor params to readonly abstract fields of concrete cache implementations. Remove empty CacheDistributor constructor. 2025-02-19 17:13:15 +10:00
Sam Pinkus
1f3a570584 Readability improvement: rename PipenvCache,PoetryCache "patterns" field to "cacheDependencyPath" to be consistent with base class and cache-factory. 2025-02-19 17:13:15 +10:00
10 changed files with 34 additions and 45 deletions

View File

@ -78,6 +78,8 @@ jobs:
python-version: pypy-3.11-v7.x
- os: ubuntu-22.04
python-version: pypy-3.11-v7.x
- os: ubuntu-22.04-arm
python-version: pypy-3.10-v7.x
- os: ubuntu-22.04-arm
python-version: pypy-3.11-v7.x
steps:

View File

@ -19,7 +19,6 @@ jobs:
matrix:
operating-system:
[
ubuntu-20.04,
windows-latest,
ubuntu-22.04,
ubuntu-22.04-arm,

View File

@ -21,7 +21,6 @@ jobs:
os:
[
macos-latest,
ubuntu-20.04,
ubuntu-22.04,
ubuntu-22.04-arm,
ubuntu-24.04-arm,
@ -77,7 +76,6 @@ jobs:
os:
[
macos-latest,
ubuntu-20.04,
ubuntu-22.04,
ubuntu-22.04-arm,
ubuntu-24.04-arm,

View File

@ -24,7 +24,6 @@ jobs:
[
macos-latest,
windows-latest,
ubuntu-20.04,
ubuntu-22.04,
ubuntu-22.04-arm,
ubuntu-24.04-arm,
@ -142,7 +141,6 @@ jobs:
[
macos-latest,
windows-latest,
ubuntu-20.04,
ubuntu-22.04,
ubuntu-22.04-arm,
ubuntu-24.04-arm,
@ -177,7 +175,6 @@ jobs:
[
macos-latest,
windows-latest,
ubuntu-20.04,
ubuntu-22.04,
ubuntu-22.04-arm,
ubuntu-24.04-arm,
@ -220,7 +217,6 @@ jobs:
[
macos-latest,
windows-latest,
ubuntu-20.04,
ubuntu-22.04,
ubuntu-22.04-arm,
ubuntu-24.04-arm,

View File

@ -24,7 +24,6 @@ jobs:
[
macos-latest,
windows-latest,
ubuntu-20.04,
ubuntu-22.04,
ubuntu-22.04-arm,
macos-13,
@ -69,7 +68,6 @@ jobs:
[
macos-latest,
windows-latest,
ubuntu-20.04,
ubuntu-22.04,
ubuntu-22.04-arm,
macos-13,
@ -117,7 +115,6 @@ jobs:
[
macos-latest,
windows-latest,
ubuntu-20.04,
ubuntu-22.04,
ubuntu-22.04-arm,
macos-13,
@ -163,7 +160,6 @@ jobs:
[
macos-latest,
windows-latest,
ubuntu-20.04,
ubuntu-22.04,
ubuntu-22.04-arm,
macos-13,
@ -214,7 +210,6 @@ jobs:
[
macos-latest,
windows-latest,
ubuntu-20.04,
ubuntu-22.04,
ubuntu-22.04-arm,
macos-13,
@ -265,7 +260,6 @@ jobs:
[
macos-latest,
windows-latest,
ubuntu-20.04,
ubuntu-22.04,
ubuntu-22.04-arm,
macos-13,
@ -300,7 +294,6 @@ jobs:
[
macos-latest,
windows-latest,
ubuntu-20.04,
ubuntu-22.04,
ubuntu-22.04-arm,
macos-13,
@ -419,7 +412,6 @@ jobs:
[
macos-latest,
windows-latest,
ubuntu-20.04,
ubuntu-22.04,
ubuntu-22.04-arm,
macos-13,

View File

@ -1,6 +1,5 @@
import * as cache from '@actions/cache';
import * as core from '@actions/core';
import {CACHE_DEPENDENCY_BACKUP_PATH} from './constants';
export enum State {
STATE_CACHE_PRIMARY_KEY = 'cache-primary-key',
@ -10,27 +9,20 @@ export enum State {
abstract class CacheDistributor {
protected CACHE_KEY_PREFIX = 'setup-python';
constructor(
protected packageManager: string,
protected cacheDependencyPath: string
) {}
protected abstract readonly packageManager: string;
protected abstract getCacheGlobalDirectories(): Promise<string[]>;
protected abstract computeKeys(): Promise<{
primaryKey: string;
restoreKey: string[] | undefined;
cacheDependencyPath: string;
}>;
protected async handleLoadedCache() {}
public async restoreCache() {
const {primaryKey, restoreKey} = await this.computeKeys();
const {primaryKey, restoreKey, cacheDependencyPath} = await this.computeKeys();
if (primaryKey.endsWith('-')) {
const file =
this.packageManager === 'pip'
? `${this.cacheDependencyPath
.split('\n')
.join(',')} or ${CACHE_DEPENDENCY_BACKUP_PATH}`
: this.cacheDependencyPath.split('\n').join(',');
const file = cacheDependencyPath.split('\n').join(',');
throw new Error(
`No file in ${process.cwd()} matched to [${file}], make sure you have checked out the target repository`
);

View File

@ -1 +0,0 @@
export const CACHE_DEPENDENCY_BACKUP_PATH = '**/pyproject.toml';

View File

@ -8,16 +8,16 @@ import os from 'os';
import CacheDistributor from './cache-distributor';
import {getLinuxInfo, IS_LINUX, IS_WINDOWS} from '../utils';
import {CACHE_DEPENDENCY_BACKUP_PATH} from './constants';
class PipCache extends CacheDistributor {
private cacheDependencyBackupPath: string = CACHE_DEPENDENCY_BACKUP_PATH;
private cacheDependencyBackupPath = '**/pyproject.toml';
protected readonly packageManager = 'pip';
constructor(
private pythonVersion: string,
cacheDependencyPath = '**/requirements.txt'
protected readonly cacheDependencyPath = '**/requirements.txt'
) {
super('pip', cacheDependencyPath);
super();
}
protected async getCacheGlobalDirectories() {
@ -59,9 +59,12 @@ class PipCache extends CacheDistributor {
}
protected async computeKeys() {
const hash =
(await glob.hashFiles(this.cacheDependencyPath)) ||
(await glob.hashFiles(this.cacheDependencyBackupPath));
let cacheDependencyPath = this.cacheDependencyPath;
let hash = await glob.hashFiles(this.cacheDependencyPath);
if(!hash) {
hash = await glob.hashFiles(this.cacheDependencyBackupPath);
cacheDependencyPath = this.cacheDependencyBackupPath;
}
let primaryKey = '';
let restoreKey = '';
@ -76,7 +79,8 @@ class PipCache extends CacheDistributor {
return {
primaryKey,
restoreKey: [restoreKey]
restoreKey: [restoreKey],
cacheDependencyPath,
};
}
}

View File

@ -6,11 +6,13 @@ import * as core from '@actions/core';
import CacheDistributor from './cache-distributor';
class PipenvCache extends CacheDistributor {
protected readonly packageManager = 'pipenv';
constructor(
private pythonVersion: string,
protected patterns: string = '**/Pipfile.lock'
protected readonly cacheDependencyPath: string = '**/Pipfile.lock'
) {
super('pipenv', patterns);
super();
}
protected async getCacheGlobalDirectories() {
@ -31,12 +33,13 @@ class PipenvCache extends CacheDistributor {
}
protected async computeKeys() {
const hash = await glob.hashFiles(this.patterns);
const hash = await glob.hashFiles(this.cacheDependencyPath);
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
const restoreKey = undefined;
return {
primaryKey,
restoreKey
restoreKey,
cacheDependencyPath: this.cacheDependencyPath,
};
}
}

View File

@ -8,18 +8,21 @@ import CacheDistributor from './cache-distributor';
import {logWarning} from '../utils';
class PoetryCache extends CacheDistributor {
protected readonly packageManager = 'poetry';
constructor(
private pythonVersion: string,
protected patterns: string = '**/poetry.lock',
protected readonly cacheDependencyPath: string = '**/poetry.lock',
protected poetryProjects: Set<string> = new Set<string>()
) {
super('poetry', patterns);
super();
}
protected async getCacheGlobalDirectories() {
// Same virtualenvs path may appear for different projects, hence we use a Set
const paths = new Set<string>();
const globber = await glob.create(this.patterns);
const globber = await glob.create(this.cacheDependencyPath);
for await (const file of globber.globGenerator()) {
const basedir = path.dirname(file);
@ -45,13 +48,14 @@ class PoetryCache extends CacheDistributor {
}
protected async computeKeys() {
const hash = await glob.hashFiles(this.patterns);
const hash = await glob.hashFiles(this.cacheDependencyPath);
// "v2" is here to invalidate old caches of this cache distributor, which were created broken:
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-python-${this.pythonVersion}-${this.packageManager}-v2-${hash}`;
const restoreKey = undefined;
return {
primaryKey,
restoreKey
restoreKey,
cacheDependencyPath: this.cacheDependencyPath,
};
}