From f927de6ff293d5dc731c06bc77d473a191f1cac0 Mon Sep 17 00:00:00 2001 From: Hargun Kaur <56452820+hkaur008@users.noreply.github.com> Date: Mon, 25 Oct 2021 04:27:22 +0000 Subject: [PATCH] separate function for resolving version file added --- src/main.ts | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/main.ts b/src/main.ts index edc6598c..eb181dc3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -13,25 +13,7 @@ export async function run() { // Version is optional. If supplied, install / use from the tool cache // If not supplied then task is still used to setup proxy, auth, etc... // - let version = core.getInput('node-version'); - if (!version) { - version = core.getInput('version'); - - if (!version) { - const versionFile = core.getInput('node-version-file'); - - if (!!versionFile) { - const versionFilePath = path.join( - process.env.GITHUB_WORKSPACE!, - versionFile - ); - version = installer.parseNodeVersionFile( - fs.readFileSync(versionFilePath, 'utf8') - ); - core.info(`Resolved ${versionFile} as ${version}`); - } - } - } + let version = resolveVersionInput(); let arch = core.getInput('architecture'); const cache = core.getInput('cache'); @@ -90,3 +72,25 @@ function isGhes(): boolean { ); return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; } + +function resolveVersionInput(): string { + let version = core.getInput('node-version') || core.getInput('version'); + if (version) { + return version; + } + + const versionFileInput = core.getInput('node-version-file'); + if (versionFileInput) { + const versionFilePath = path.join( + process.env.GITHUB_WORKSPACE!, + versionFileInput + ); + version = installer.parseNodeVersionFile( + fs.readFileSync(versionFilePath, 'utf8') + ); + core.info(`Resolved ${versionFileInput} as ${version}`); + return version; + } + + return null as any; +} \ No newline at end of file