Allow entries with same Job ID to match in different workflows

Previously, the workflow name was always included when matching a cache entry for the current job.
This can be overly restrictive when job definitions are shared between different workflows. 
The workflow name is still encoded in the cache entry key, but not in the restore key searching for entries with a matching job.

Fixes #1017
This commit is contained in:
Daz DeBoer 2024-01-04 02:38:36 +01:00 committed by GitHub
parent 270f30ba56
commit 32bab5b15a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 19 additions and 80 deletions

26
dist/main/index.js vendored
View file

@ -139505,7 +139505,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.tryDelete = exports.handleCacheFailure = exports.cacheDebug = exports.saveCache = exports.restoreCache = exports.hashStrings = exports.hashFileNames = exports.getUniqueLabelForJobInstanceValues = exports.getUniqueLabelForJobInstance = exports.getCacheKeyForJob = exports.getCacheKeyPrefix = exports.generateCacheKey = exports.CacheKey = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheOverwriteExisting = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
exports.tryDelete = exports.handleCacheFailure = exports.cacheDebug = exports.saveCache = exports.restoreCache = exports.hashStrings = exports.hashFileNames = exports.getCacheKeyPrefix = exports.generateCacheKey = exports.CacheKey = exports.isCacheCleanupEnabled = exports.isCacheDebuggingEnabled = exports.isCacheOverwriteExisting = exports.isCacheWriteOnly = exports.isCacheReadOnly = exports.isCacheDisabled = void 0;
const core = __importStar(__nccwpck_require__(42186));
const cache = __importStar(__nccwpck_require__(27799));
const github = __importStar(__nccwpck_require__(95438));
@ -139577,34 +139577,16 @@ function getCacheKeyEnvironment() {
return process.env[CACHE_KEY_OS_VAR] || runnerOs;
}
function getCacheKeyJob() {
return process.env[CACHE_KEY_JOB_VAR] || getCacheKeyForJob(github.context.workflow, github.context.job);
return process.env[CACHE_KEY_JOB_VAR] || github.context.job;
}
function getCacheKeyForJob(workflowName, jobId) {
const sanitizedWorkflow = workflowName.replace(/,/g, '').toLowerCase();
return `${sanitizedWorkflow}-${jobId}`;
}
exports.getCacheKeyForJob = getCacheKeyForJob;
function getCacheKeyJobInstance() {
const override = process.env[CACHE_KEY_JOB_INSTANCE_VAR];
if (override) {
return override;
}
const workflowName = github.context.workflow;
const workflowJobContext = params.getJobMatrix();
return hashStrings([workflowJobContext]);
}
function getUniqueLabelForJobInstance() {
return getUniqueLabelForJobInstanceValues(github.context.workflow, github.context.job, params.getJobMatrix());
}
exports.getUniqueLabelForJobInstance = getUniqueLabelForJobInstance;
function getUniqueLabelForJobInstanceValues(workflow, jobId, matrixJson) {
const matrix = JSON.parse(matrixJson);
const matrixString = Object.values(matrix).join('-');
const label = matrixString ? `${workflow}-${jobId}-${matrixString}` : `${workflow}-${jobId}`;
return sanitize(label);
}
exports.getUniqueLabelForJobInstanceValues = getUniqueLabelForJobInstanceValues;
function sanitize(value) {
return value.replace(/[^a-zA-Z0-9_-]/g, '').toLowerCase();
return hashStrings([workflowName, workflowJobContext]);
}
function getCacheKeyJobExecution() {
return process.env[CACHE_KEY_JOB_EXECUTION_VAR] || github.context.sha;