From 32b1479849920420bf1a849e4ae25fa9edab782e Mon Sep 17 00:00:00 2001 From: jongwooo Date: Mon, 12 Dec 2022 21:09:02 +0900 Subject: [PATCH] refactor: Use early return pattern Signed-off-by: jongwooo --- dist/cleanup/index.js | 16 +++++++--------- dist/setup/index.js | 16 +++++++--------- src/util.ts | 21 ++++++++++----------- 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index 169ba9f3..5adbf1d3 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -68706,16 +68706,14 @@ function isGhes() { } exports.isGhes = isGhes; function isCacheFeatureAvailable() { - if (!cache.isFeatureAvailable()) { - if (isGhes()) { - throw new Error('Caching is only supported on GHES version >= 3.5. If you are on a version >= 3.5, please check with your GHES admin if the 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('Caching is only supported on GHES version >= 3.5. If you are on a version >= 3.5, please check with your GHES admin if the 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 63cf6543..4dc3a413 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -105399,16 +105399,14 @@ function isGhes() { } exports.isGhes = isGhes; function isCacheFeatureAvailable() { - if (!cache.isFeatureAvailable()) { - if (isGhes()) { - throw new Error('Caching is only supported on GHES version >= 3.5. If you are on a version >= 3.5, please check with your GHES admin if the 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('Caching is only supported on GHES version >= 3.5. If you are on a version >= 3.5, please check with your GHES admin if the 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/util.ts b/src/util.ts index 10f18c5f..de3cf618 100644 --- a/src/util.ts +++ b/src/util.ts @@ -85,17 +85,16 @@ export function isGhes(): boolean { } export function isCacheFeatureAvailable(): boolean { - if (!cache.isFeatureAvailable()) { - if (isGhes()) { - throw new Error( - 'Caching is only supported on GHES version >= 3.5. If you are on a version >= 3.5, please check with your GHES admin if the 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( + 'Caching is only supported on GHES version >= 3.5. If you are on a version >= 3.5, please check with your GHES admin if the 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; }