From 676975d9aaccb55b3621a6d481497820a9942577 Mon Sep 17 00:00:00 2001 From: Sergey Dolin Date: Fri, 9 Dec 2022 11:41:54 +0100 Subject: [PATCH] Use early return pattern --- dist/cache-save/index.js | 16 ++++++---------- dist/setup/index.js | 16 ++++++---------- src/cache-utils.ts | 23 ++++++++++------------- 3 files changed, 22 insertions(+), 33 deletions(-) diff --git a/dist/cache-save/index.js b/dist/cache-save/index.js index 876629ef..5f499403 100644 --- a/dist/cache-save/index.js +++ b/dist/cache-save/index.js @@ -61185,16 +61185,12 @@ 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; - } - return true; + if (cache.isFeatureAvailable()) + 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 b6c3e23f..af122147 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -73139,16 +73139,12 @@ 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; - } - return true; + if (cache.isFeatureAvailable()) + 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 ccd4e987..065d347e 100644 --- a/src/cache-utils.ts +++ b/src/cache-utils.ts @@ -105,19 +105,16 @@ 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; }