Skip to content

Commit

Permalink
Fallback to global.json if no version specified
Browse files Browse the repository at this point in the history
  • Loading branch information
Danny McCormick committed Aug 12, 2019
1 parent d6004ce commit 3280df5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
13 changes: 12 additions & 1 deletion lib/setup-dotnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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* () {
Expand All @@ -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();
Expand Down
16 changes: 15 additions & 1 deletion src/setup-dotnet.ts
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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();
Expand Down

0 comments on commit 3280df5

Please sign in to comment.