Skip to content

Commit

Permalink
Use early return pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
dsame committed Dec 9, 2022
1 parent d1b197b commit 676975d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 33 deletions.
16 changes: 6 additions & 10 deletions dist/cache-save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
16 changes: 6 additions & 10 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
23 changes: 10 additions & 13 deletions src/cache-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
);

core.warning(
'The runner was not able to contact the cache service. Caching will be skipped'
);

return true;
return false;
}

0 comments on commit 676975d

Please sign in to comment.