mirror of
https://github.com/actions/setup-python.git
synced 2025-07-01 15:13:46 +00:00
Added cache-hit output
This commit is contained in:
parent
422c071dab
commit
c933f3c50e
4 changed files with 50 additions and 0 deletions
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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>>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue