From 0723c44a47decd0d90220bb60acafd27fd3b2049 Mon Sep 17 00:00:00 2001 From: dhvcc <1337kwiz@gmail.com> Date: Sun, 3 Apr 2022 18:52:43 +0300 Subject: [PATCH] Remove PromiseReturnType, add matchedKey == primaryKey check --- dist/cache-save/index.js | 7 +++---- dist/setup/index.js | 7 +++---- src/cache-distributions/cache-distributor.ts | 10 +++------- src/utils.ts | 9 --------- 4 files changed, 9 insertions(+), 24 deletions(-) diff --git a/dist/cache-save/index.js b/dist/cache-save/index.js index 478fd5ed0..12ea09fe9 100644 --- a/dist/cache-save/index.js +++ b/dist/cache-save/index.js @@ -37234,18 +37234,17 @@ class CacheDistributor { core.saveState(State.CACHE_PATHS, cachePath); core.saveState(State.STATE_CACHE_PRIMARY_KEY, primaryKey); const matchedKey = yield cache.restoreCache(cachePath, primaryKey, restoreKey); - this.handleMatchResult(matchedKey); + this.handleMatchResult(matchedKey, primaryKey); }); } - handleMatchResult(matchedKey) { - if (matchedKey) { + handleMatchResult(matchedKey, primaryKey) { + 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)); } } diff --git a/dist/setup/index.js b/dist/setup/index.js index fc44f28db..b7c141851 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -42579,18 +42579,17 @@ class CacheDistributor { core.saveState(State.CACHE_PATHS, cachePath); core.saveState(State.STATE_CACHE_PRIMARY_KEY, primaryKey); const matchedKey = yield cache.restoreCache(cachePath, primaryKey, restoreKey); - this.handleMatchResult(matchedKey); + this.handleMatchResult(matchedKey, primaryKey); }); } - handleMatchResult(matchedKey) { - if (matchedKey) { + handleMatchResult(matchedKey, primaryKey) { + 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)); } } diff --git a/src/cache-distributions/cache-distributor.ts b/src/cache-distributions/cache-distributor.ts index c939ec2eb..4aaba033a 100644 --- a/src/cache-distributions/cache-distributor.ts +++ b/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', @@ -42,19 +41,16 @@ abstract class CacheDistributor { restoreKey ); - this.handleMatchResult(matchedKey); + this.handleMatchResult(matchedKey, primaryKey); } - public handleMatchResult( - matchedKey: PromiseReturnType - ) { - 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)); } } diff --git a/src/utils.ts b/src/utils.ts index f0dca7e18..eb3a1ba68 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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 extends PromiseLike - ? AwaitedPolyfill - : T; -// Extract return type from promise -export type PromiseReturnType< - T extends (...args: any) => any -> = AwaitedPolyfill>;