fix: warn instead of error when no python to cache (#762)

Fixes: #754
This commit is contained in:
Kevin Stillhammer
2026-02-06 16:00:33 +01:00
committed by GitHub
parent a3b3eaea92
commit 02182fa02a
4 changed files with 74 additions and 49 deletions

39
dist/save-cache/index.js generated vendored
View File

@@ -90852,11 +90852,25 @@ async function saveCache() {
await pruneCache();
}
const actualCachePath = getUvCachePath();
await saveCacheToKey(cacheKey, actualCachePath, restore_cache_1.STATE_CACHE_MATCHED_KEY, "uv cache", `Cache path ${actualCachePath} does not exist on disk. This likely indicates that there are no dependencies to cache. Consider disabling the cache input if it is not needed.`);
if (!fs.existsSync(actualCachePath)) {
if (inputs_1.ignoreNothingToCache) {
core.info("No cacheable uv cache paths were found. Ignoring because ignore-nothing-to-cache is enabled.");
}
else {
throw new Error(`Cache path ${actualCachePath} does not exist on disk. This likely indicates that there are no dependencies to cache. Consider disabling the cache input if it is not needed.`);
}
}
else {
await saveCacheToKey(cacheKey, actualCachePath, restore_cache_1.STATE_CACHE_MATCHED_KEY, "uv cache");
}
}
if (inputs_1.cachePython) {
if (!fs.existsSync(inputs_1.pythonDir)) {
core.warning(`Python cache path ${inputs_1.pythonDir} does not exist on disk. Skipping Python cache save because no managed Python installation was found. If you want uv to install managed Python instead of using a system interpreter, set UV_PYTHON_PREFERENCE=only-managed.`);
return;
}
const pythonCacheKey = `${cacheKey}-python`;
await saveCacheToKey(pythonCacheKey, inputs_1.pythonDir, restore_cache_1.STATE_PYTHON_CACHE_MATCHED_KEY, "Python cache", `Python cache path ${inputs_1.pythonDir} does not exist on disk. This likely indicates that there are no Python installations to cache. Consider disabling the cache input if it is not needed.`);
await saveCacheToKey(pythonCacheKey, inputs_1.pythonDir, restore_cache_1.STATE_PYTHON_CACHE_MATCHED_KEY, "Python cache");
}
}
async function pruneCache() {
@@ -90883,30 +90897,15 @@ function getUvCachePath() {
}
return inputs_1.cacheLocalPath.path;
}
async function saveCacheToKey(cacheKey, cachePath, stateKey, cacheName, pathNotExistErrorMessage) {
async function saveCacheToKey(cacheKey, cachePath, stateKey, cacheName) {
const matchedKey = core.getState(stateKey);
if (matchedKey === cacheKey) {
core.info(`${cacheName} hit occurred on key ${cacheKey}, not saving cache.`);
return;
}
core.info(`Including ${cacheName} path: ${cachePath}`);
if (!fs.existsSync(cachePath) && !inputs_1.ignoreNothingToCache) {
throw new Error(pathNotExistErrorMessage);
}
try {
await cache.saveCache([cachePath], cacheKey);
core.info(`${cacheName} saved with key: ${cacheKey}`);
}
catch (e) {
if (e instanceof Error &&
e.message ===
"Path Validation Error: Path(s) specified in the action for caching do(es) not exist, hence no cache is being saved.") {
core.info(`No cacheable ${cacheName} paths were found. Ignoring because ignore-nothing-to-save is enabled.`);
}
else {
throw e;
}
}
await cache.saveCache([cachePath], cacheKey);
core.info(`${cacheName} saved with key: ${cacheKey}`);
}
run();