mirror of
https://code.forgejo.org/actions/cache.git
synced 2025-04-23 01:03:57 +08:00
added ts code
This commit is contained in:
parent
73cb7e0405
commit
54f20c8e9b
4 changed files with 10 additions and 1 deletions
|
@ -17,6 +17,8 @@ inputs:
|
||||||
outputs:
|
outputs:
|
||||||
cache-hit:
|
cache-hit:
|
||||||
description: 'A boolean value to indicate an exact match was found for the primary key'
|
description: 'A boolean value to indicate an exact match was found for the primary key'
|
||||||
|
cache-restored:
|
||||||
|
description: 'A boolean value to indicate an exact or partial match was found resulting in a restore'
|
||||||
runs:
|
runs:
|
||||||
using: 'node16'
|
using: 'node16'
|
||||||
main: 'dist/restore/index.js'
|
main: 'dist/restore/index.js'
|
||||||
|
|
|
@ -6,7 +6,8 @@ export enum Inputs {
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum Outputs {
|
export enum Outputs {
|
||||||
CacheHit = "cache-hit"
|
CacheHit = "cache-hit",
|
||||||
|
CacheRestored = "cache-restored"
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum State {
|
export enum State {
|
||||||
|
|
|
@ -52,6 +52,7 @@ async function run(): Promise<void> {
|
||||||
utils.setCacheState(cacheKey);
|
utils.setCacheState(cacheKey);
|
||||||
|
|
||||||
const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheKey);
|
const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheKey);
|
||||||
|
utils.setCacheRestoredOutput(true);
|
||||||
utils.setCacheHitOutput(isExactKeyMatch);
|
utils.setCacheHitOutput(isExactKeyMatch);
|
||||||
|
|
||||||
core.info(`Cache restored from key: ${cacheKey}`);
|
core.info(`Cache restored from key: ${cacheKey}`);
|
||||||
|
@ -60,6 +61,7 @@ async function run(): Promise<void> {
|
||||||
throw error;
|
throw error;
|
||||||
} else {
|
} else {
|
||||||
utils.logWarning(error.message);
|
utils.logWarning(error.message);
|
||||||
|
utils.setCacheRestoredOutput(false);
|
||||||
utils.setCacheHitOutput(false);
|
utils.setCacheHitOutput(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,10 @@ export function setCacheHitOutput(isCacheHit: boolean): void {
|
||||||
core.setOutput(Outputs.CacheHit, isCacheHit.toString());
|
core.setOutput(Outputs.CacheHit, isCacheHit.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setCacheRestoredOutput(isCacheRestored: boolean): void {
|
||||||
|
core.setOutput(Outputs.CacheRestored, isCacheRestored.toString());
|
||||||
|
}
|
||||||
|
|
||||||
export function setOutputAndState(key: string, cacheKey?: string): void {
|
export function setOutputAndState(key: string, cacheKey?: string): void {
|
||||||
setCacheHitOutput(isExactKeyMatch(key, cacheKey));
|
setCacheHitOutput(isExactKeyMatch(key, cacheKey));
|
||||||
// Store the matched cache key if it exists
|
// Store the matched cache key if it exists
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue