Skip to content

Commit 3280df5

Browse files
author
Danny McCormick
committed
Fallback to global.json if no version specified
1 parent d6004ce commit 3280df5

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

lib/setup-dotnet.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
1717
Object.defineProperty(exports, "__esModule", { value: true });
1818
const core = __importStar(require("@actions/core"));
1919
const installer = __importStar(require("./installer"));
20+
const fs = __importStar(require("fs"));
2021
const path = __importStar(require("path"));
2122
function run() {
2223
return __awaiter(this, void 0, void 0, function* () {
@@ -25,7 +26,17 @@ function run() {
2526
// Version is optional. If supplied, install / use from the tool cache
2627
// If not supplied then task is still used to setup proxy, auth, etc...
2728
//
28-
const version = core.getInput('version');
29+
let version = core.getInput('version');
30+
if (!version) {
31+
// Try to fall back to global.json
32+
const globalJsonPath = path.join(process.cwd(), 'global.json');
33+
if (fs.existsSync(globalJsonPath)) {
34+
const globalJson = JSON.parse(fs.readFileSync(globalJsonPath, { encoding: 'utf8' }));
35+
if (globalJson.sdk && globalJson.sdk.version) {
36+
version = globalJson.sdk.version;
37+
}
38+
}
39+
}
2940
if (version) {
3041
const dotnetInstaller = new installer.DotnetCoreInstaller(version);
3142
yield dotnetInstaller.installDotnet();

src/setup-dotnet.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as core from '@actions/core';
22
import * as installer from './installer';
3+
import * as fs from 'fs';
34
import * as path from 'path';
45

56
async function run() {
@@ -8,7 +9,20 @@ async function run() {
89
// Version is optional. If supplied, install / use from the tool cache
910
// If not supplied then task is still used to setup proxy, auth, etc...
1011
//
11-
const version = core.getInput('version');
12+
let version = core.getInput('version');
13+
if (!version) {
14+
// Try to fall back to global.json
15+
const globalJsonPath = path.join(process.cwd(), 'global.json');
16+
if (fs.existsSync(globalJsonPath)) {
17+
const globalJson = JSON.parse(
18+
fs.readFileSync(globalJsonPath, {encoding: 'utf8'})
19+
);
20+
if (globalJson.sdk && globalJson.sdk.version) {
21+
version = globalJson.sdk.version;
22+
}
23+
}
24+
}
25+
1226
if (version) {
1327
const dotnetInstaller = new installer.DotnetCoreInstaller(version);
1428
await dotnetInstaller.installDotnet();

0 commit comments

Comments
 (0)