diff --git a/dist/index.js b/dist/index.js index 3d48ec6adc..98eaf1ae0b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -9115,18 +9115,16 @@ function run() { // // dotnet-version is optional, but needs to be provided for most use cases. // If supplied, install / use from the tool cache. - // If not supplied, look for version in ./global.json. + // global-version-file may be specified to point to a specific global.json + // and will be used to install an additional version. + // If neither supplied, look for version in ./global.json. // If a valid version still can't be identified, nothing will be installed. // Proxy, auth, (etc) are still set up, even if no version is identified // let versions = core.getMultilineInput('dotnet-version'); - if (!versions.length) { - // Try to fall back to global.json - core.debug('No version found, trying to find version from global.json'); - const globalJsonPath = path.join(process.cwd(), 'global.json'); - if (fs.existsSync(globalJsonPath)) { - versions.push(getVersionFromGlobalJson(globalJsonPath)); - } + const globalJsonVersion = getVersionFromGlobalJson(versions.length > 0); + if (globalJsonVersion) { + versions.push(globalJsonVersion); } if (versions.length) { const includePrerelease = (core.getInput('include-prerelease') || 'false').toLowerCase() === @@ -9152,20 +9150,39 @@ function run() { }); } exports.run = run; -function getVersionFromGlobalJson(globalJsonPath) { - let version = ''; +function getVersionFromGlobalJson(hasVersions) { + const globalJsonFileInput = core.getInput('global-json-file'); + if (!globalJsonFileInput) { + if (hasVersions) { + // Don't check for a global.json if dotnet-version was specified and + // global-json-file was not + return null; + } + // Falling back to global.json + core.debug('No version found, trying to find version from global.json'); + } + const globalJsonPath = globalJsonFileInput + ? path.join(process.cwd(), globalJsonFileInput) + : path.join(process.cwd(), 'global.json'); + if (!fs.existsSync(globalJsonPath)) { + if (globalJsonFileInput) { + throw new Error(`The specified global.json file at: ${globalJsonFileInput} does not exist`); + } + return null; + } const globalJson = JSON.parse( // .trim() is necessary to strip BOM https://github.com/nodejs/node/issues/20649 fs.readFileSync(globalJsonPath, { encoding: 'utf8' }).trim()); if (globalJson.sdk && globalJson.sdk.version) { - version = globalJson.sdk.version; + let version = globalJson.sdk.version; const rollForward = globalJson.sdk.rollForward; if (rollForward && rollForward === 'latestFeature') { const [major, minor] = version.split('.'); version = `${major}.${minor}`; } + return version; } - return version; + return null; } run();