Added cache-hit output

This commit is contained in:
dhvcc 2022-04-03 02:33:19 +03:00
parent 422c071dab
commit c933f3c50e
4 changed files with 50 additions and 0 deletions

View file

@ -1,5 +1,6 @@
import * as cache from '@actions/cache';
import * as core from '@actions/core';
import {PromiseReturnType} from '../utils';
export enum State {
STATE_CACHE_PRIMARY_KEY = 'cache-primary-key',
@ -41,12 +42,19 @@ abstract class CacheDistributor {
restoreKey
);
this.handleMatchResult(matchedKey);
}
public handleMatchResult(
matchedKey: PromiseReturnType<typeof cache.restoreCache>
) {
if (matchedKey) {
core.saveState(State.CACHE_MATCHED_KEY, matchedKey);
core.info(`Cache restored from key: ${matchedKey}`);
} else {
core.info(`${this.packageManager} cache is not found`);
}
core.setOutput('cache-hit', Boolean(matchedKey));
}
}

View file

@ -119,3 +119,12 @@ export function isCacheFeatureAvailable(): boolean {
return true;
}
// Awaited (typescript 4.5+) polyfill. Not ideal, so use with care
export type AwaitedPolyfill<T> = T extends PromiseLike<infer U>
? AwaitedPolyfill<U>
: T;
// Extract return type from promise
export type PromiseReturnType<
T extends (...args: any) => any
> = AwaitedPolyfill<ReturnType<T>>;