Add inputs restore-cache and save-cache (#568)

Closes: #555
This commit is contained in:
Kevin Stillhammer
2025-09-14 14:55:08 +02:00
committed by GitHub
parent f67343ac2e
commit dc724a12b6
8 changed files with 149 additions and 9 deletions

View File

@ -8,6 +8,7 @@ import {
cacheSuffix,
pruneCache,
pythonVersion as pythonVersionInput,
restoreCache as shouldRestoreCache,
workingDirectory,
} from "../utils/inputs";
import { getArch, getPlatform } from "../utils/platforms";
@ -18,6 +19,12 @@ const CACHE_VERSION = "1";
export async function restoreCache(): Promise<void> {
const cacheKey = await computeKeys();
core.saveState(STATE_CACHE_KEY, cacheKey);
if (!shouldRestoreCache) {
core.info("restore-cache is false. Skipping restore cache step.");
return;
}
let matchedKey: string | undefined;
core.info(
@ -32,8 +39,6 @@ export async function restoreCache(): Promise<void> {
return;
}
core.saveState(STATE_CACHE_KEY, cacheKey);
handleMatchResult(matchedKey, cacheKey);
}

View File

@ -11,12 +11,17 @@ import {
enableCache,
ignoreNothingToCache,
pruneCache as shouldPruneCache,
saveCache as shouldSaveCache,
} from "./utils/inputs";
export async function run(): Promise<void> {
try {
if (enableCache) {
await saveCache();
if (shouldSaveCache) {
await saveCache();
} else {
core.info("save-cache is false. Skipping save cache step.");
}
// node will stay alive if any promises are not resolved,
// which is a possibility if HTTP requests are dangling
// due to retries or timeouts. We know that if we got here

View File

@ -8,6 +8,8 @@ export const pythonVersion = core.getInput("python-version");
export const activateEnvironment = core.getBooleanInput("activate-environment");
export const checkSum = core.getInput("checksum");
export const enableCache = getEnableCache();
export const restoreCache = core.getInput("restore-cache") === "true";
export const saveCache = core.getInput("save-cache") === "true";
export const cacheSuffix = core.getInput("cache-suffix") || "";
export const cacheLocalPath = getCacheLocalPath();
export const cacheDependencyGlob = getCacheDependencyGlob();