added ts code

This commit is contained in:
Mikhail Katychev 2022-02-16 12:17:31 -06:00
parent 73cb7e0405
commit 54f20c8e9b
No known key found for this signature in database
GPG key ID: 9E8549CD2CEB5E59
4 changed files with 10 additions and 1 deletions

View file

@ -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'

View file

@ -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 {

View file

@ -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);
} }
} }

View file

@ -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