From 9499ca8787cc68722795e7bc62d02541fad046b7 Mon Sep 17 00:00:00 2001 From: Heath Stewart Date: Tue, 21 Apr 2020 16:27:45 -0700 Subject: [PATCH] Fix path resolution Looking for vswhere in the PATH was never triggered and had some bugs (like failing unconditionally if the code path was executed). --- dist/index.js | 16 ++++++++++------ src/main.ts | 27 +++++++++++++++++---------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/dist/index.js b/dist/index.js index 9336e8a..60c5bea 100644 --- a/dist/index.js +++ b/dist/index.js @@ -977,8 +977,7 @@ const path = __importStar(__webpack_require__(622)); const io = __importStar(__webpack_require__(1)); const IS_WINDOWS = process.platform === 'win32'; const VS_VERSION = core.getInput('vs-version') || 'latest'; -const VSWHERE_PATH = core.getInput('vswhere-path') || - path.join(process.env['ProgramFiles(x86)'], 'Microsoft Visual Studio\\Installer'); +const VSWHERE_PATH = core.getInput('vswhere-path'); // if a specific version of VS is requested let VSWHERE_EXEC = '-products * -requires Microsoft.Component.MSBuild -property installationPath -latest '; if (VS_VERSION !== 'latest') { @@ -1007,12 +1006,17 @@ function run() { vswhereToolExe = path.join(vsWhereInPath, 'vswhere.exe'); } catch (_a) { - // wasn't found because which threw - } - finally { - core.setFailed('setup-msbuild requires the path to where vswhere.exe exists'); + // check for VS-installed path + const vsWhereInInstallerPath = path.join(process.env['ProgramFiles(x86)'], 'Microsoft Visual Studio\\Installer\\vswhere.exe'); + if (fs.existsSync(vsWhereInInstallerPath)) { + vswhereToolExe = vsWhereInInstallerPath; + } } } + if (!fs.existsSync(vswhereToolExe)) { + core.setFailed('setup-msbuild requires the path to where vswhere.exe exists'); + return; + } core.debug(`Full tool exe: ${vswhereToolExe}`); let foundToolPath = ''; const options = {}; diff --git a/src/main.ts b/src/main.ts index de308d8..fe16239 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,12 +7,7 @@ import {ExecOptions} from '@actions/exec/lib/interfaces' const IS_WINDOWS = process.platform === 'win32' const VS_VERSION = core.getInput('vs-version') || 'latest' -const VSWHERE_PATH = - core.getInput('vswhere-path') || - path.join( - process.env['ProgramFiles(x86)'] as string, - 'Microsoft Visual Studio\\Installer' - ) +const VSWHERE_PATH = core.getInput('vswhere-path') // if a specific version of VS is requested let VSWHERE_EXEC = '-products * -requires Microsoft.Component.MSBuild -property installationPath -latest ' @@ -43,14 +38,26 @@ async function run(): Promise { core.debug(`Found tool in PATH: ${vsWhereInPath}`) vswhereToolExe = path.join(vsWhereInPath, 'vswhere.exe') } catch { - // wasn't found because which threw - } finally { - core.setFailed( - 'setup-msbuild requires the path to where vswhere.exe exists' + // check for VS-installed path + const vsWhereInInstallerPath = path.join( + process.env['ProgramFiles(x86)'] as string, + 'Microsoft Visual Studio\\Installer\\vswhere.exe' ) + + if (fs.existsSync(vsWhereInInstallerPath)) { + vswhereToolExe = vsWhereInInstallerPath + } } } + if (!fs.existsSync(vswhereToolExe)) { + core.setFailed( + 'setup-msbuild requires the path to where vswhere.exe exists' + ) + + return + } + core.debug(`Full tool exe: ${vswhereToolExe}`) let foundToolPath = ''