Skip to content

Commit 676975d

Browse files
committed
Use early return pattern
1 parent d1b197b commit 676975d

File tree

3 files changed

+22
-33
lines changed

3 files changed

+22
-33
lines changed

dist/cache-save/index.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61185,16 +61185,12 @@ function isGhes() {
6118561185
}
6118661186
exports.isGhes = isGhes;
6118761187
function isCacheFeatureAvailable() {
61188-
if (!cache.isFeatureAvailable()) {
61189-
if (isGhes()) {
61190-
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.');
61191-
}
61192-
else {
61193-
core.warning('The runner was not able to contact the cache service. Caching will be skipped');
61194-
}
61195-
return false;
61196-
}
61197-
return true;
61188+
if (cache.isFeatureAvailable())
61189+
return true;
61190+
if (isGhes())
61191+
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.');
61192+
core.warning('The runner was not able to contact the cache service. Caching will be skipped');
61193+
return false;
6119861194
}
6119961195
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
6120061196

dist/setup/index.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73139,16 +73139,12 @@ function isGhes() {
7313973139
}
7314073140
exports.isGhes = isGhes;
7314173141
function isCacheFeatureAvailable() {
73142-
if (!cache.isFeatureAvailable()) {
73143-
if (isGhes()) {
73144-
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.');
73145-
}
73146-
else {
73147-
core.warning('The runner was not able to contact the cache service. Caching will be skipped');
73148-
}
73149-
return false;
73150-
}
73151-
return true;
73142+
if (cache.isFeatureAvailable())
73143+
return true;
73144+
if (isGhes())
73145+
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.');
73146+
core.warning('The runner was not able to contact the cache service. Caching will be skipped');
73147+
return false;
7315273148
}
7315373149
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
7315473150

src/cache-utils.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,16 @@ export function isGhes(): boolean {
105105
}
106106

107107
export function isCacheFeatureAvailable(): boolean {
108-
if (!cache.isFeatureAvailable()) {
109-
if (isGhes()) {
110-
throw new Error(
111-
'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.'
112-
);
113-
} else {
114-
core.warning(
115-
'The runner was not able to contact the cache service. Caching will be skipped'
116-
);
117-
}
108+
if (cache.isFeatureAvailable()) return true;
118109

119-
return false;
120-
}
110+
if (isGhes())
111+
throw new Error(
112+
'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.'
113+
);
114+
115+
core.warning(
116+
'The runner was not able to contact the cache service. Caching will be skipped'
117+
);
121118

122-
return true;
119+
return false;
123120
}

0 commit comments

Comments
 (0)