mirror of
https://code.forgejo.org/actions/cache.git
synced 2025-04-22 11:25:31 +00:00
Consuming 3.0 actions/cache (#834)
* Consuming 3.0 actions/cache * formatting and error * updated package version * resolve package * dist * review comment * dist * dist
This commit is contained in:
parent
baed3516c3
commit
354a2ae15e
9 changed files with 124 additions and 152 deletions
|
@ -29,38 +29,29 @@ async function run(): Promise<void> {
|
|||
required: true
|
||||
});
|
||||
|
||||
try {
|
||||
const cacheKey = await cache.restoreCache(
|
||||
cachePaths,
|
||||
primaryKey,
|
||||
restoreKeys
|
||||
const cacheKey = await cache.restoreCache(
|
||||
cachePaths,
|
||||
primaryKey,
|
||||
restoreKeys
|
||||
);
|
||||
|
||||
if (!cacheKey) {
|
||||
core.info(
|
||||
`Cache not found for input keys: ${[
|
||||
primaryKey,
|
||||
...restoreKeys
|
||||
].join(", ")}`
|
||||
);
|
||||
if (!cacheKey) {
|
||||
core.info(
|
||||
`Cache not found for input keys: ${[
|
||||
primaryKey,
|
||||
...restoreKeys
|
||||
].join(", ")}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Store the matched cache key
|
||||
utils.setCacheState(cacheKey);
|
||||
|
||||
const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheKey);
|
||||
utils.setCacheHitOutput(isExactKeyMatch);
|
||||
|
||||
core.info(`Cache restored from key: ${cacheKey}`);
|
||||
} catch (error: unknown) {
|
||||
const typedError = error as Error;
|
||||
if (typedError.name === cache.ValidationError.name) {
|
||||
throw error;
|
||||
} else {
|
||||
utils.logWarning(typedError.message);
|
||||
utils.setCacheHitOutput(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Store the matched cache key
|
||||
utils.setCacheState(cacheKey);
|
||||
|
||||
const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheKey);
|
||||
utils.setCacheHitOutput(isExactKeyMatch);
|
||||
core.info(`Cache restored from key: ${cacheKey}`);
|
||||
} catch (error: unknown) {
|
||||
core.setFailed((error as Error).message);
|
||||
}
|
||||
|
|
18
src/save.ts
18
src/save.ts
|
@ -44,20 +44,12 @@ async function run(): Promise<void> {
|
|||
required: true
|
||||
});
|
||||
|
||||
try {
|
||||
await cache.saveCache(cachePaths, primaryKey, {
|
||||
uploadChunkSize: utils.getInputAsInt(Inputs.UploadChunkSize)
|
||||
});
|
||||
const cacheId = await cache.saveCache(cachePaths, primaryKey, {
|
||||
uploadChunkSize: utils.getInputAsInt(Inputs.UploadChunkSize)
|
||||
});
|
||||
|
||||
if (cacheId != -1) {
|
||||
core.info(`Cache saved with key: ${primaryKey}`);
|
||||
} catch (error: unknown) {
|
||||
const typedError = error as Error;
|
||||
if (typedError.name === cache.ValidationError.name) {
|
||||
throw error;
|
||||
} else if (typedError.name === cache.ReserveCacheError.name) {
|
||||
core.info(typedError.message);
|
||||
} else {
|
||||
utils.logWarning(typedError.message);
|
||||
}
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
utils.logWarning((error as Error).message);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue