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