From 3280df5864040d5b9d594ab87dcf807b0a91a522 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Mon, 12 Aug 2019 10:51:47 -0400 Subject: [PATCH] Fallback to global.json if no version specified --- lib/setup-dotnet.js | 13 ++++++++++++- src/setup-dotnet.ts | 16 +++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/setup-dotnet.js b/lib/setup-dotnet.js index 7983c51..f49fd89 100644 --- a/lib/setup-dotnet.js +++ b/lib/setup-dotnet.js @@ -17,6 +17,7 @@ var __importStar = (this && this.__importStar) || function (mod) { Object.defineProperty(exports, "__esModule", { value: true }); const core = __importStar(require("@actions/core")); const installer = __importStar(require("./installer")); +const fs = __importStar(require("fs")); const path = __importStar(require("path")); function run() { return __awaiter(this, void 0, void 0, function* () { @@ -25,7 +26,17 @@ 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... // - const version = core.getInput('version'); + let version = core.getInput('version'); + if (!version) { + // Try to fall back to global.json + const globalJsonPath = path.join(process.cwd(), 'global.json'); + if (fs.existsSync(globalJsonPath)) { + const globalJson = JSON.parse(fs.readFileSync(globalJsonPath, { encoding: 'utf8' })); + if (globalJson.sdk && globalJson.sdk.version) { + version = globalJson.sdk.version; + } + } + } if (version) { const dotnetInstaller = new installer.DotnetCoreInstaller(version); yield dotnetInstaller.installDotnet(); diff --git a/src/setup-dotnet.ts b/src/setup-dotnet.ts index 212d01b..54da1f6 100644 --- a/src/setup-dotnet.ts +++ b/src/setup-dotnet.ts @@ -1,5 +1,6 @@ import * as core from '@actions/core'; import * as installer from './installer'; +import * as fs from 'fs'; import * as path from 'path'; async function run() { @@ -8,7 +9,20 @@ 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... // - const version = core.getInput('version'); + let version = core.getInput('version'); + if (!version) { + // Try to fall back to global.json + const globalJsonPath = path.join(process.cwd(), 'global.json'); + if (fs.existsSync(globalJsonPath)) { + const globalJson = JSON.parse( + fs.readFileSync(globalJsonPath, {encoding: 'utf8'}) + ); + if (globalJson.sdk && globalJson.sdk.version) { + version = globalJson.sdk.version; + } + } + } + if (version) { const dotnetInstaller = new installer.DotnetCoreInstaller(version); await dotnetInstaller.installDotnet();