mirror of
https://github.com/actions/setup-python.git
synced 2026-06-23 08:12:48 +00:00
make cache keys distro-aware and key RHEL by major version
This commit is contained in:
parent
332cb90ccc
commit
9c2781a11e
5334
dist/cache-save/index.js
vendored
5334
dist/cache-save/index.js
vendored
File diff suppressed because it is too large
Load Diff
35
dist/setup/index.js
vendored
35
dist/setup/index.js
vendored
@ -53813,6 +53813,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|||||||
exports.State = void 0;
|
exports.State = void 0;
|
||||||
const cache = __importStar(__nccwpck_require__(5116));
|
const cache = __importStar(__nccwpck_require__(5116));
|
||||||
const core = __importStar(__nccwpck_require__(37484));
|
const core = __importStar(__nccwpck_require__(37484));
|
||||||
|
const utils_1 = __nccwpck_require__(71798);
|
||||||
const constants_1 = __nccwpck_require__(10565);
|
const constants_1 = __nccwpck_require__(10565);
|
||||||
var State;
|
var State;
|
||||||
(function (State) {
|
(function (State) {
|
||||||
@ -53829,6 +53830,20 @@ class CacheDistributor {
|
|||||||
this.cacheDependencyPath = cacheDependencyPath;
|
this.cacheDependencyPath = cacheDependencyPath;
|
||||||
}
|
}
|
||||||
async handleLoadedCache() { }
|
async handleLoadedCache() { }
|
||||||
|
/**
|
||||||
|
* Builds the Linux distro portion of a cache key (e.g. `-26.04-Ubuntu`, `-9-rhel`).
|
||||||
|
* RHEL is keyed by major version since it ships one ABI-stable artifact per major.
|
||||||
|
*/
|
||||||
|
async getLinuxInfoKeySegment() {
|
||||||
|
if (!utils_1.IS_LINUX) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
const osInfo = await (0, utils_1.getLinuxInfo)();
|
||||||
|
const osVersion = osInfo.osName === 'rhel'
|
||||||
|
? osInfo.osVersion.split('.')[0]
|
||||||
|
: osInfo.osVersion;
|
||||||
|
return `-${osVersion}-${osInfo.osName}`;
|
||||||
|
}
|
||||||
async restoreCache() {
|
async restoreCache() {
|
||||||
const { primaryKey, restoreKey } = await this.computeKeys();
|
const { primaryKey, restoreKey } = await this.computeKeys();
|
||||||
if (primaryKey.endsWith('-')) {
|
if (primaryKey.endsWith('-')) {
|
||||||
@ -54011,17 +54026,9 @@ class PipCache extends cache_distributor_1.default {
|
|||||||
async computeKeys() {
|
async computeKeys() {
|
||||||
const hash = (await glob.hashFiles(this.cacheDependencyPath)) ||
|
const hash = (await glob.hashFiles(this.cacheDependencyPath)) ||
|
||||||
(await glob.hashFiles(this.cacheDependencyBackupPath));
|
(await glob.hashFiles(this.cacheDependencyBackupPath));
|
||||||
let primaryKey = '';
|
const osSegment = await this.getLinuxInfoKeySegment();
|
||||||
let restoreKey = '';
|
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}${osSegment}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
|
||||||
if (utils_1.IS_LINUX) {
|
const restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}${osSegment}-python-${this.pythonVersion}-${this.packageManager}`;
|
||||||
const osInfo = await (0, utils_1.getLinuxInfo)();
|
|
||||||
primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-${osInfo.osVersion}-${osInfo.osName}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
|
|
||||||
restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-${osInfo.osVersion}-${osInfo.osName}-python-${this.pythonVersion}-${this.packageManager}`;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
|
|
||||||
restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-python-${this.pythonVersion}-${this.packageManager}`;
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
primaryKey,
|
primaryKey,
|
||||||
restoreKey: [restoreKey]
|
restoreKey: [restoreKey]
|
||||||
@ -54105,7 +54112,8 @@ class PipenvCache extends cache_distributor_1.default {
|
|||||||
}
|
}
|
||||||
async computeKeys() {
|
async computeKeys() {
|
||||||
const hash = await glob.hashFiles(this.patterns);
|
const hash = await glob.hashFiles(this.patterns);
|
||||||
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
|
const osSegment = await this.getLinuxInfoKeySegment();
|
||||||
|
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}${osSegment}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
|
||||||
const restoreKey = undefined;
|
const restoreKey = undefined;
|
||||||
return {
|
return {
|
||||||
primaryKey,
|
primaryKey,
|
||||||
@ -54197,8 +54205,9 @@ class PoetryCache extends cache_distributor_1.default {
|
|||||||
}
|
}
|
||||||
async computeKeys() {
|
async computeKeys() {
|
||||||
const hash = await glob.hashFiles(this.patterns);
|
const hash = await glob.hashFiles(this.patterns);
|
||||||
|
const osSegment = await this.getLinuxInfoKeySegment();
|
||||||
// "v2" is here to invalidate old caches of this cache distributor, which were created broken:
|
// "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 primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}${osSegment}-python-${this.pythonVersion}-${this.packageManager}-v2-${hash}`;
|
||||||
const restoreKey = undefined;
|
const restoreKey = undefined;
|
||||||
return {
|
return {
|
||||||
primaryKey,
|
primaryKey,
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import * as cache from '@actions/cache';
|
import * as cache from '@actions/cache';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
|
import {getLinuxInfo, IS_LINUX} from '../utils';
|
||||||
import {CACHE_DEPENDENCY_BACKUP_PATH} from './constants';
|
import {CACHE_DEPENDENCY_BACKUP_PATH} from './constants';
|
||||||
|
|
||||||
export enum State {
|
export enum State {
|
||||||
@ -22,6 +23,24 @@ abstract class CacheDistributor {
|
|||||||
}>;
|
}>;
|
||||||
protected async handleLoadedCache() {}
|
protected async handleLoadedCache() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the Linux distro portion of a cache key (e.g. `-26.04-Ubuntu`, `-9-rhel`).
|
||||||
|
* RHEL is keyed by major version since it ships one ABI-stable artifact per major.
|
||||||
|
*/
|
||||||
|
protected async getLinuxInfoKeySegment(): Promise<string> {
|
||||||
|
if (!IS_LINUX) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
const osInfo = await getLinuxInfo();
|
||||||
|
const osVersion =
|
||||||
|
osInfo.osName === 'rhel'
|
||||||
|
? osInfo.osVersion.split('.')[0]
|
||||||
|
: osInfo.osVersion;
|
||||||
|
|
||||||
|
return `-${osVersion}-${osInfo.osName}`;
|
||||||
|
}
|
||||||
|
|
||||||
public async restoreCache() {
|
public async restoreCache() {
|
||||||
const {primaryKey, restoreKey} = await this.computeKeys();
|
const {primaryKey, restoreKey} = await this.computeKeys();
|
||||||
if (primaryKey.endsWith('-')) {
|
if (primaryKey.endsWith('-')) {
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import * as path from 'path';
|
|||||||
import os from 'os';
|
import os from 'os';
|
||||||
|
|
||||||
import CacheDistributor from './cache-distributor';
|
import CacheDistributor from './cache-distributor';
|
||||||
import {getLinuxInfo, IS_LINUX, IS_WINDOWS} from '../utils';
|
import {IS_WINDOWS} from '../utils';
|
||||||
import {CACHE_DEPENDENCY_BACKUP_PATH} from './constants';
|
import {CACHE_DEPENDENCY_BACKUP_PATH} from './constants';
|
||||||
|
|
||||||
class PipCache extends CacheDistributor {
|
class PipCache extends CacheDistributor {
|
||||||
@ -62,17 +62,9 @@ class PipCache extends CacheDistributor {
|
|||||||
const hash =
|
const hash =
|
||||||
(await glob.hashFiles(this.cacheDependencyPath)) ||
|
(await glob.hashFiles(this.cacheDependencyPath)) ||
|
||||||
(await glob.hashFiles(this.cacheDependencyBackupPath));
|
(await glob.hashFiles(this.cacheDependencyBackupPath));
|
||||||
let primaryKey = '';
|
const osSegment = await this.getLinuxInfoKeySegment();
|
||||||
let restoreKey = '';
|
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}${osSegment}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
|
||||||
|
const restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}${osSegment}-python-${this.pythonVersion}-${this.packageManager}`;
|
||||||
if (IS_LINUX) {
|
|
||||||
const osInfo = await getLinuxInfo();
|
|
||||||
primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-${osInfo.osVersion}-${osInfo.osName}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
|
|
||||||
restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-${osInfo.osVersion}-${osInfo.osName}-python-${this.pythonVersion}-${this.packageManager}`;
|
|
||||||
} else {
|
|
||||||
primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
|
|
||||||
restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-python-${this.pythonVersion}-${this.packageManager}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
primaryKey,
|
primaryKey,
|
||||||
|
|||||||
@ -32,7 +32,8 @@ class PipenvCache extends CacheDistributor {
|
|||||||
|
|
||||||
protected async computeKeys() {
|
protected async computeKeys() {
|
||||||
const hash = await glob.hashFiles(this.patterns);
|
const hash = await glob.hashFiles(this.patterns);
|
||||||
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
|
const osSegment = await this.getLinuxInfoKeySegment();
|
||||||
|
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}${osSegment}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
|
||||||
const restoreKey = undefined;
|
const restoreKey = undefined;
|
||||||
return {
|
return {
|
||||||
primaryKey,
|
primaryKey,
|
||||||
|
|||||||
@ -46,8 +46,9 @@ class PoetryCache extends CacheDistributor {
|
|||||||
|
|
||||||
protected async computeKeys() {
|
protected async computeKeys() {
|
||||||
const hash = await glob.hashFiles(this.patterns);
|
const hash = await glob.hashFiles(this.patterns);
|
||||||
|
const osSegment = await this.getLinuxInfoKeySegment();
|
||||||
// "v2" is here to invalidate old caches of this cache distributor, which were created broken:
|
// "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 primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${process.arch}${osSegment}-python-${this.pythonVersion}-${this.packageManager}-v2-${hash}`;
|
||||||
const restoreKey = undefined;
|
const restoreKey = undefined;
|
||||||
return {
|
return {
|
||||||
primaryKey,
|
primaryKey,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user