Introduce isCacheEnabled

In order to hande empty 'cache' input
This commit is contained in:
Sergey Dolin 2023-01-30 14:48:41 +01:00
parent fbed9d5d06
commit 72e3f80a4a

View file

@ -1,7 +1,12 @@
import * as cache from '@actions/cache';
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import {supportedPackageManagers, PackageManagerInfo} from './package-managers';
import {
supportedPackageManagers,
PackageManagerInfo,
getCurrentPackageManager
} from './package-managers';
import {findDependencyFile} from './cache-restore';
export const getCommandOutput = async (toolCommand: string) => {
let {stdout, stderr, exitCode} = await exec.getExecOutput(
@ -73,3 +78,16 @@ export function isCacheFeatureAvailable(): boolean {
);
return false;
}
export async function isCacheEnabled() {
const cacheInput = core.getInput('cache');
if (cacheInput) {
return core.getBooleanInput('cache');
}
const packageManager = getCurrentPackageManager();
const packageManagerInfo = await getPackageManagerInfo(packageManager);
const cachePaths = findDependencyFile(packageManagerInfo);
return cachePaths.length > 0;
}