Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback to global.json if no version specified #15

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
damccorm marked this conversation as resolved.
Show resolved Hide resolved
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');
damccorm marked this conversation as resolved.
Show resolved Hide resolved
if (!version) {
// Try to fall back to global.json
damccorm marked this conversation as resolved.
Show resolved Hide resolved
const globalJsonPath = path.join(process.cwd(), 'global.json');
damccorm marked this conversation as resolved.
Show resolved Hide resolved
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