Skip to content

Commit

Permalink
Remove PromiseReturnType, add matchedKey == primaryKey check
Browse files Browse the repository at this point in the history
  • Loading branch information
dhvcc committed Apr 3, 2022
1 parent 96d8243 commit a903fa1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
10 changes: 3 additions & 7 deletions src/cache-distributions/cache-distributor.ts
@@ -1,6 +1,5 @@
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',
Expand Down Expand Up @@ -42,19 +41,16 @@ abstract class CacheDistributor {
restoreKey
);

this.handleMatchResult(matchedKey);
this.handleMatchResult(matchedKey, primaryKey);
}

public handleMatchResult(
matchedKey: PromiseReturnType<typeof cache.restoreCache>
) {
if (matchedKey) {
public handleMatchResult(matchedKey: string | undefined, primaryKey: string) {
if (matchedKey == primaryKey) {
core.saveState(State.CACHE_MATCHED_KEY, matchedKey);
core.info(`Cache restored from key: ${matchedKey}`);
} else {
core.info(`${this.packageManager} cache is not found`);
}
core.info('cache was hit');
core.setOutput('cache-hit', Boolean(matchedKey));
}
}
Expand Down
9 changes: 0 additions & 9 deletions src/utils.ts
Expand Up @@ -119,12 +119,3 @@ 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>>;

0 comments on commit a903fa1

Please sign in to comment.