From 5a3778b347383a5aeec7494a5eeb7602b8bc8ee9 Mon Sep 17 00:00:00 2001 From: Haneen Mahdin Date: Sat, 30 Jul 2022 09:48:07 +0530 Subject: [PATCH] Add support for specifying versions for package managers (#529) --- src/cache-utils.ts | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/cache-utils.ts b/src/cache-utils.ts index ccd4e987..901d199e 100644 --- a/src/cache-utils.ts +++ b/src/cache-utils.ts @@ -47,17 +47,35 @@ export const getCommandOutput = async (toolCommand: string) => { return stdout.trim(); }; +const resolvePackageManagerVersionInput = ( + packageManager: string +): string | undefined => { + let version = core.getInput(`${packageManager}-version`); + + if (version !== '') { + core.info(`Using ${packageManager} with version ${version}.`); + + return version; + } +}; + const getPackageManagerVersion = async ( packageManager: string, command: string ) => { - const stdOut = await getCommandOutput(`${packageManager} ${command}`); + let packageManagerVersion = resolvePackageManagerVersionInput(packageManager); - if (!stdOut) { - throw new Error(`Could not retrieve version of ${packageManager}`); + if (packageManagerVersion) { + return packageManagerVersion; + } else { + const stdOut = await getCommandOutput(`${packageManager} ${command}`); + + if (!stdOut) { + throw new Error(`Could not retrieve version of ${packageManager}`); + } + + return stdOut; } - - return stdOut; }; export const getPackageManagerInfo = async (packageManager: string) => {