feat: add ability to restore cache by exact match (#60)

Signed-off-by: szymonmaszke <github@maszke.co>
This commit is contained in:
Szymon Maszke 2024-08-09 09:07:36 +02:00 committed by GitHub
parent 176c044a20
commit 2f3a9be7ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 2381 additions and 1960 deletions

View File

@ -37,6 +37,12 @@ inputs:
description: The dependency file(s) to cache.
default: pdm.lock
required: false
cache-restore-exact-match:
description: >
Restore cache ONLY on exact match with the primary key.
Note: Post-installation cache will still be saved if cache is 'true'.
default: 'false'
required: false
update-python:
description: Whether to update the environment with the requested Python
default: 'true'

22
dist/setup-pdm.js vendored
View File

@ -2085,7 +2085,7 @@ var require_core = __commonJS({
return inputs.map((input) => input.trim());
}
exports2.getMultilineInput = getMultilineInput2;
function getBooleanInput3(name, options) {
function getBooleanInput4(name, options) {
const trueValue = ["true", "True", "TRUE"];
const falseValue = ["false", "False", "FALSE"];
const val = getInput5(name, options);
@ -2096,7 +2096,7 @@ var require_core = __commonJS({
throw new TypeError(`Input does not meet YAML 1.2 "Core Schema" specification: ${name}
Support boolean input list: \`true | True | TRUE | false | False | FALSE\``);
}
exports2.getBooleanInput = getBooleanInput3;
exports2.getBooleanInput = getBooleanInput4;
function setOutput5(name, value) {
const filePath = process.env["GITHUB_OUTPUT"] || "";
if (filePath) {
@ -84127,7 +84127,7 @@ var import_node_process4 = __toESM(require("node:process"));
var core8 = __toESM(require_core());
var import_exec2 = __toESM(require_exec());
// node_modules/.pnpm/github.com+actions+setup-python@2f078955e4d0f34cc7a8b0108b2eb7bbe154438e/node_modules/setup-python/src/utils.ts
// node_modules/.pnpm/setup-python@https+++codeload.github.com+actions+setup-python+tar.gz+2f078955e4d0f34cc7a8b0108b2eb7bbe154438e/node_modules/setup-python/src/utils.ts
var cache = __toESM(require_cache2());
var core = __toESM(require_core());
var import_fs = __toESM(require("fs"));
@ -90391,12 +90391,12 @@ var defaults = {
var got = create_default(defaults);
var source_default2 = got;
// node_modules/.pnpm/github.com+actions+setup-python@2f078955e4d0f34cc7a8b0108b2eb7bbe154438e/node_modules/setup-python/src/find-python.ts
// node_modules/.pnpm/setup-python@https+++codeload.github.com+actions+setup-python+tar.gz+2f078955e4d0f34cc7a8b0108b2eb7bbe154438e/node_modules/setup-python/src/find-python.ts
var os2 = __toESM(require("os"));
var path3 = __toESM(require("path"));
var semver2 = __toESM(require_semver4());
// node_modules/.pnpm/github.com+actions+setup-python@2f078955e4d0f34cc7a8b0108b2eb7bbe154438e/node_modules/setup-python/src/install-python.ts
// node_modules/.pnpm/setup-python@https+++codeload.github.com+actions+setup-python+tar.gz+2f078955e4d0f34cc7a8b0108b2eb7bbe154438e/node_modules/setup-python/src/install-python.ts
var path2 = __toESM(require("path"));
var core2 = __toESM(require_core());
var tc = __toESM(require_tool_cache());
@ -90485,7 +90485,7 @@ async function installCpythonFromRelease(release) {
}
}
// node_modules/.pnpm/github.com+actions+setup-python@2f078955e4d0f34cc7a8b0108b2eb7bbe154438e/node_modules/setup-python/src/find-python.ts
// node_modules/.pnpm/setup-python@https+++codeload.github.com+actions+setup-python+tar.gz+2f078955e4d0f34cc7a8b0108b2eb7bbe154438e/node_modules/setup-python/src/find-python.ts
var core3 = __toESM(require_core());
var tc2 = __toESM(require_tool_cache());
function binDir(installDir) {
@ -90608,10 +90608,10 @@ function pythonVersionToSemantic(versionSpec, allowPreReleases) {
return result;
}
// node_modules/.pnpm/github.com+actions+setup-python@2f078955e4d0f34cc7a8b0108b2eb7bbe154438e/node_modules/setup-python/src/find-pypy.ts
// node_modules/.pnpm/setup-python@https+++codeload.github.com+actions+setup-python+tar.gz+2f078955e4d0f34cc7a8b0108b2eb7bbe154438e/node_modules/setup-python/src/find-pypy.ts
var path5 = __toESM(require("path"));
// node_modules/.pnpm/github.com+actions+setup-python@2f078955e4d0f34cc7a8b0108b2eb7bbe154438e/node_modules/setup-python/src/install-pypy.ts
// node_modules/.pnpm/setup-python@https+++codeload.github.com+actions+setup-python+tar.gz+2f078955e4d0f34cc7a8b0108b2eb7bbe154438e/node_modules/setup-python/src/install-pypy.ts
var os3 = __toESM(require("os"));
var path4 = __toESM(require("path"));
var core4 = __toESM(require_core());
@ -90811,7 +90811,7 @@ function replaceX32toX86(architecture) {
return architecture;
}
// node_modules/.pnpm/github.com+actions+setup-python@2f078955e4d0f34cc7a8b0108b2eb7bbe154438e/node_modules/setup-python/src/find-pypy.ts
// node_modules/.pnpm/setup-python@https+++codeload.github.com+actions+setup-python+tar.gz+2f078955e4d0f34cc7a8b0108b2eb7bbe154438e/node_modules/setup-python/src/find-pypy.ts
var semver4 = __toESM(require_semver4());
var core5 = __toESM(require_core());
var tc4 = __toESM(require_tool_cache());
@ -91050,6 +91050,10 @@ async function calculateCacheKeys(pythonVersion, cacheDependencyPath) {
const hash = await (0, import_glob.hashFiles)(cacheDependencyPath);
const primaryKey = `setup-pdm-${import_node_process3.default.env.RUNNER_OS}-${import_node_process3.default.env.RUNNER_ARCH}-python-${pythonVersion}-${hash}`;
const restoreKey = `setup-pdm-${import_node_process3.default.env.RUNNER_OS}-${import_node_process3.default.env.RUNNER_ARCH}-python-${pythonVersion}-`;
const restoreExactMatch = core7.getBooleanInput("cache-restore-exact-match");
if (restoreExactMatch) {
return { primaryKey, restoreKeys: [] };
}
return { primaryKey, restoreKeys: [restoreKey] };
}
async function cacheDependencies(pdmBin, pythonVersion) {

4307
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -9,6 +9,12 @@ async function calculateCacheKeys(pythonVersion: string, cacheDependencyPath: st
const hash = await hashFiles(cacheDependencyPath)
const primaryKey = `setup-pdm-${process.env.RUNNER_OS}-${process.env.RUNNER_ARCH}-python-${pythonVersion}-${hash}`
const restoreKey = `setup-pdm-${process.env.RUNNER_OS}-${process.env.RUNNER_ARCH}-python-${pythonVersion}-`
const restoreExactMatch = core.getBooleanInput('cache-restore-exact-match')
if (restoreExactMatch) {
return { primaryKey, restoreKeys: [] }
}
return { primaryKey, restoreKeys: [restoreKey] }
}