refactor getCacheDirectoryPath to utilize side-effect of map

This commit is contained in:
Sergey Dolin 2023-02-20 16:11:41 +01:00
parent c09fdc8076
commit 4e2636afea
3 changed files with 30 additions and 30 deletions

View file

@ -40,23 +40,17 @@ export const getCacheDirectoryPath = async (
)
);
pathOutputs
.filter(output => output.status === 'rejected')
.forEach(output =>
core.warning(
`getting cache directory path failed: ${
(output as PromiseRejectedResult).reason
}`
)
);
const results = pathOutputs.map(item => {
if (item.status === 'fulfilled') {
return item.value;
} else {
core.info(`[warning]getting cache directory path failed: ${item.reason}`);
}
const cachePaths = pathOutputs
.filter(
output =>
output.status === 'fulfilled' &&
(output as PromiseFulfilledResult<string>).value
)
.map(output => (output as PromiseFulfilledResult<string>).value);
return '';
});
const cachePaths = results.filter(item => item);
if (!cachePaths.length) {
throw new Error(`Could not get cache folder paths.`);