Check paths first.

This commit is contained in:
Miles Johnson 2024-05-03 11:27:37 -07:00
parent e00bf43167
commit e6a829b5bd
3 changed files with 16 additions and 3 deletions

View file

@ -1,3 +1,7 @@
# 1.2.0
- Updated to not save the cache if one of the required paths does not exist.
# 1.1.0 # 1.1.0
- Added a `cache-base` input. When provided, will only save cache on this branch/ref, but will - Added a `cache-base` input. When provided, will only save cache on this branch/ref, but will

View file

@ -8,7 +8,7 @@ inputs:
description: 'Comma-separated list of global binaries to install into Cargo.' description: 'Comma-separated list of global binaries to install into Cargo.'
cache: cache:
description: 'Toggle caching of ~/.cargo/registry and /target/<cache-target> directories.' description: 'Toggle caching of ~/.cargo/registry and /target/<cache-target> directories.'
default: true default: 'true'
cache-base: cache-base:
description: description:
'Base branch/ref to save a warmup cache on. Other branches/refs will restore from this base.' 'Base branch/ref to save a warmup cache on. Other branches/refs will restore from this base.'
@ -21,7 +21,7 @@ inputs:
description: 'Comma-separated list of additional components to install.' description: 'Comma-separated list of additional components to install.'
inherit-toolchain: inherit-toolchain:
description: 'Inherit all toolchain settings from the rust-toolchain.toml file.' description: 'Inherit all toolchain settings from the rust-toolchain.toml file.'
default: false default: 'false'
targets: targets:
description: 'Comma-separated list of additional targets to install.' description: 'Comma-separated list of additional targets to install.'
profile: profile:

View file

@ -165,12 +165,21 @@ export async function saveCache() {
return; return;
} }
const cachePaths = getCachePaths();
for (const cachePath of cachePaths) {
if (!fs.existsSync(cachePath)) {
core.info(`Cache path ${cachePath} does not exist, skipping save`);
return;
}
}
await cleanCargoRegistry(); await cleanCargoRegistry();
await cleanTargetProfile(); await cleanTargetProfile();
core.info(`Saving cache with key ${primaryKey}`); core.info(`Saving cache with key ${primaryKey}`);
await cache.saveCache(getCachePaths(), primaryKey); await cache.saveCache(cachePaths, primaryKey);
} }
export async function restoreCache() { export async function restoreCache() {