From ec819f6ce5a3d3b4be0f8dce078c08f56e8b0e88 Mon Sep 17 00:00:00 2001 From: jongwooo Date: Mon, 12 Dec 2022 21:20:36 +0900 Subject: [PATCH] refactor: Use early return pattern Signed-off-by: jongwooo --- dist/cache-save/index.js | 16 +++++++--------- dist/setup/index.js | 16 +++++++--------- src/cache-utils.ts | 23 +++++++++++------------ 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/dist/cache-save/index.js b/dist/cache-save/index.js index e6e029d..338e2ca 100644 --- a/dist/cache-save/index.js +++ b/dist/cache-save/index.js @@ -60471,16 +60471,14 @@ function isGhes() { } exports.isGhes = isGhes; function isCacheFeatureAvailable() { - if (!cache.isFeatureAvailable()) { - if (isGhes()) { - throw new Error('Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.'); - } - else { - core.warning('The runner was not able to contact the cache service. Caching will be skipped'); - } - return false; + if (cache.isFeatureAvailable()) { + return true; } - return true; + if (isGhes()) { + throw new Error('Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.'); + } + core.warning('The runner was not able to contact the cache service. Caching will be skipped'); + return false; } exports.isCacheFeatureAvailable = isCacheFeatureAvailable; diff --git a/dist/setup/index.js b/dist/setup/index.js index 7b0f1c4..2d3ab78 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -63144,16 +63144,14 @@ function isGhes() { } exports.isGhes = isGhes; function isCacheFeatureAvailable() { - if (!cache.isFeatureAvailable()) { - if (isGhes()) { - throw new Error('Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.'); - } - else { - core.warning('The runner was not able to contact the cache service. Caching will be skipped'); - } - return false; + if (cache.isFeatureAvailable()) { + return true; } - return true; + if (isGhes()) { + throw new Error('Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.'); + } + core.warning('The runner was not able to contact the cache service. Caching will be skipped'); + return false; } exports.isCacheFeatureAvailable = isCacheFeatureAvailable; diff --git a/src/cache-utils.ts b/src/cache-utils.ts index 5741337..91b3bae 100644 --- a/src/cache-utils.ts +++ b/src/cache-utils.ts @@ -57,19 +57,18 @@ export function isGhes(): boolean { } export function isCacheFeatureAvailable(): boolean { - if (!cache.isFeatureAvailable()) { - if (isGhes()) { - throw new Error( - 'Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.' - ); - } else { - core.warning( - 'The runner was not able to contact the cache service. Caching will be skipped' - ); - } + if (cache.isFeatureAvailable()) { + return true; + } - return false; + if (isGhes()) { + throw new Error( + 'Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.' + ); } - return true; + core.warning( + 'The runner was not able to contact the cache service. Caching will be skipped' + ); + return false; }