3
0
Fork 0
mirror of https://code.forgejo.org/actions/cache.git synced 2025-04-23 03:45:31 +00:00

Allow refreshing cache also with granular save.

This commit is contained in:
Gregorio Litenstein 2023-04-07 21:53:06 -04:00
parent df9df7396d
commit ed8571e5e3
No known key found for this signature in database
GPG key ID: 4EB52A1A9CE2C63F
6 changed files with 153 additions and 10 deletions

View file

@ -82,7 +82,6 @@ export async function restoreImpl(
} else {
core.info(`Cache restored from key: ${cacheKey}`);
}
return cacheKey;
} catch (error: unknown) {
core.setFailed((error as Error).message);

View file

@ -48,10 +48,26 @@ export async function saveImpl(
{ required: false }
);
// If matched restore key is same as primary key, either try to refresh the cache, or just notify and do not save (NO-OP in case of SaveOnly action)
// If matched restore key is same as primary key, either try to refresh the cache, or just notify and do not save.
const restoredKey = stateProvider.getCacheState();
let restoredKey = stateProvider.getCacheState();
if (refreshCache && !restoredKey) {
// If getCacheState didn't give us a key, we're likely using granular actions. Do a lookup to see if we need to refresh or just do a regular save.
const cachePaths = utils.getInputAsArray(Inputs.Path, {
required: true
});
const enableCrossOsArchive = utils.getInputAsBool(
Inputs.EnableCrossOsArchive
);
restoredKey = await cache.restoreCache(
cachePaths,
primaryKey,
[],
{ lookupOnly: true },
enableCrossOsArchive
);
}
if (utils.isExactKeyMatch(primaryKey, restoredKey)) {
const { GITHUB_TOKEN, GITHUB_REPOSITORY } = process.env || null;
if (GITHUB_TOKEN && GITHUB_REPOSITORY && refreshCache === true) {