From f5115afcd8125f072a617e230e3266ece5d70d93 Mon Sep 17 00:00:00 2001 From: Haneen Mahdin Date: Sat, 30 Jul 2022 09:00:56 +0530 Subject: [PATCH 1/3] Fix type for error messages --- src/installer.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/installer.ts b/src/installer.ts index 193ff16a7..8128a7dc5 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -116,9 +116,9 @@ export async function getNode( `Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded` ); } else { - core.info(err.message); + core.info((err as Error).message); } - core.debug(err.stack); + core.debug((err as Error).stack!); core.info('Falling back to download directly from Node'); } @@ -334,7 +334,7 @@ async function resolveVersionFromManifest( return info?.resolvedVersion; } catch (err) { core.info('Unable to resolve version from manifest...'); - core.debug(err.message); + core.debug((err as Error).message); } } From 7884734703c17fc06a977b11ad2ac912d75e7ce9 Mon Sep 17 00:00:00 2001 From: Haneen Mahdin Date: Sat, 30 Jul 2022 09:04:33 +0530 Subject: [PATCH 2/3] Fix types for errors --- src/cache-save.ts | 2 +- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cache-save.ts b/src/cache-save.ts index 24565a8e6..ede5d83c7 100644 --- a/src/cache-save.ts +++ b/src/cache-save.ts @@ -17,7 +17,7 @@ export async function run() { const cacheLock = core.getInput('cache'); await cachePackages(cacheLock); } catch (error) { - core.setFailed(error.message); + core.setFailed((error as Error).message); } } diff --git a/src/main.ts b/src/main.ts index ac7e51f5c..41dcf844f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -72,7 +72,7 @@ export async function run() { `##[add-matcher]${path.join(matchersPath, 'eslint-compact.json')}` ); } catch (err) { - core.setFailed(err.message); + core.setFailed((err as Error).message); } } From 5a3778b347383a5aeec7494a5eeb7602b8bc8ee9 Mon Sep 17 00:00:00 2001 From: Haneen Mahdin Date: Sat, 30 Jul 2022 09:48:07 +0530 Subject: [PATCH 3/3] 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 ccd4e9876..901d199e3 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}`); - return stdOut; + if (!stdOut) { + throw new Error(`Could not retrieve version of ${packageManager}`); + } + + return stdOut; + } }; export const getPackageManagerInfo = async (packageManager: string) => {