mirror of
https://github.com/actions/setup-dotnet.git
synced 2025-08-18 14:45:09 +00:00
fallback to global json if no version
This commit is contained in:
parent
21cbb73d4e
commit
07ddfd314e
@ -23,11 +23,12 @@ const path = __importStar(require("path"));
|
|||||||
const semver = __importStar(require("semver"));
|
const semver = __importStar(require("semver"));
|
||||||
const IS_WINDOWS = process.platform === 'win32';
|
const IS_WINDOWS = process.platform === 'win32';
|
||||||
class DotnetCoreInstaller {
|
class DotnetCoreInstaller {
|
||||||
constructor(version) {
|
constructor(version = "", jsonfile = "") {
|
||||||
if (semver.valid(semver.clean(version) || '') == null) {
|
if (semver.valid(semver.clean(version) || '') == null) {
|
||||||
throw 'Implicit version not permitted';
|
throw 'Implicit version not permitted';
|
||||||
}
|
}
|
||||||
this.version = version;
|
this.version = version;
|
||||||
|
this.jsonfile = jsonfile;
|
||||||
}
|
}
|
||||||
installDotnet() {
|
installDotnet() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
@ -37,7 +38,13 @@ class DotnetCoreInstaller {
|
|||||||
let escapedScript = path
|
let escapedScript = path
|
||||||
.join(__dirname, '..', 'externals', 'install-dotnet.ps1')
|
.join(__dirname, '..', 'externals', 'install-dotnet.ps1')
|
||||||
.replace(/'/g, "''");
|
.replace(/'/g, "''");
|
||||||
let command = `& '${escapedScript}' -Version ${this.version}`;
|
let command = `& '${escapedScript}'`;
|
||||||
|
if (this.version) {
|
||||||
|
command += ` -Version ${this.version}`;
|
||||||
|
}
|
||||||
|
if (this.jsonfile) {
|
||||||
|
command += ` -jsonfile ${this.jsonfile}`;
|
||||||
|
}
|
||||||
const powershellPath = yield io.which('powershell', true);
|
const powershellPath = yield io.which('powershell', true);
|
||||||
resultCode = yield exec.exec(`"${powershellPath}"`, [
|
resultCode = yield exec.exec(`"${powershellPath}"`, [
|
||||||
'-NoLogo',
|
'-NoLogo',
|
||||||
@ -62,7 +69,14 @@ class DotnetCoreInstaller {
|
|||||||
.replace(/'/g, "''");
|
.replace(/'/g, "''");
|
||||||
fs_1.chmodSync(escapedScript, '777');
|
fs_1.chmodSync(escapedScript, '777');
|
||||||
const scriptPath = yield io.which(escapedScript, true);
|
const scriptPath = yield io.which(escapedScript, true);
|
||||||
resultCode = yield exec.exec(`"${scriptPath}"`, ['--version', this.version], {
|
let scriptArguments = [];
|
||||||
|
if (this.version) {
|
||||||
|
scriptArguments.concat(['--version', this.version]);
|
||||||
|
}
|
||||||
|
if (this.jsonfile) {
|
||||||
|
scriptArguments.concat(['--jsonfile', this.jsonfile]);
|
||||||
|
}
|
||||||
|
resultCode = yield exec.exec(`"${scriptPath}"`, scriptArguments, {
|
||||||
listeners: {
|
listeners: {
|
||||||
stdout: (data) => {
|
stdout: (data) => {
|
||||||
output += data.toString();
|
output += data.toString();
|
||||||
|
@ -17,6 +17,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const core = __importStar(require("@actions/core"));
|
const core = __importStar(require("@actions/core"));
|
||||||
const installer = __importStar(require("./installer"));
|
const installer = __importStar(require("./installer"));
|
||||||
|
const fs = __importStar(require("fs"));
|
||||||
const path = __importStar(require("path"));
|
const path = __importStar(require("path"));
|
||||||
function run() {
|
function run() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
@ -31,6 +32,15 @@ function run() {
|
|||||||
const dotnetInstaller = new installer.DotnetCoreInstaller(version);
|
const dotnetInstaller = new installer.DotnetCoreInstaller(version);
|
||||||
yield dotnetInstaller.installDotnet();
|
yield dotnetInstaller.installDotnet();
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
// Try to fall back to global.json
|
||||||
|
core.debug('No version found, falling back to global.json');
|
||||||
|
const globalJsonPath = path.join(process.cwd(), 'global.json');
|
||||||
|
if (fs.existsSync(globalJsonPath)) {
|
||||||
|
const dotnetInstaller = new installer.DotnetCoreInstaller(undefined, globalJsonPath);
|
||||||
|
yield dotnetInstaller.installDotnet();
|
||||||
|
}
|
||||||
|
}
|
||||||
// TODO: setup proxy from runner proxy config
|
// TODO: setup proxy from runner proxy config
|
||||||
const matchersPath = path.join(__dirname, '..', '.github');
|
const matchersPath = path.join(__dirname, '..', '.github');
|
||||||
console.log(`##[add-matcher]${path.join(matchersPath, 'csc.json')}`);
|
console.log(`##[add-matcher]${path.join(matchersPath, 'csc.json')}`);
|
||||||
|
@ -9,11 +9,12 @@ import * as semver from 'semver';
|
|||||||
const IS_WINDOWS = process.platform === 'win32';
|
const IS_WINDOWS = process.platform === 'win32';
|
||||||
|
|
||||||
export class DotnetCoreInstaller {
|
export class DotnetCoreInstaller {
|
||||||
constructor(version: string) {
|
constructor(version: string = "", jsonfile: string = "") {
|
||||||
if (semver.valid(semver.clean(version) || '') == null) {
|
if (semver.valid(semver.clean(version) || '') == null) {
|
||||||
throw 'Implicit version not permitted';
|
throw 'Implicit version not permitted';
|
||||||
}
|
}
|
||||||
this.version = version;
|
this.version = version;
|
||||||
|
this.jsonfile = jsonfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async installDotnet() {
|
public async installDotnet() {
|
||||||
@ -24,7 +25,13 @@ export class DotnetCoreInstaller {
|
|||||||
let escapedScript = path
|
let escapedScript = path
|
||||||
.join(__dirname, '..', 'externals', 'install-dotnet.ps1')
|
.join(__dirname, '..', 'externals', 'install-dotnet.ps1')
|
||||||
.replace(/'/g, "''");
|
.replace(/'/g, "''");
|
||||||
let command = `& '${escapedScript}' -Version ${this.version}`;
|
let command = `& '${escapedScript}'`;
|
||||||
|
if (this.version) {
|
||||||
|
command += ` -Version ${this.version}`;
|
||||||
|
}
|
||||||
|
if (this.jsonfile) {
|
||||||
|
command += ` -jsonfile ${this.jsonfile}`;
|
||||||
|
}
|
||||||
|
|
||||||
const powershellPath = await io.which('powershell', true);
|
const powershellPath = await io.which('powershell', true);
|
||||||
resultCode = await exec.exec(
|
resultCode = await exec.exec(
|
||||||
@ -54,9 +61,18 @@ export class DotnetCoreInstaller {
|
|||||||
chmodSync(escapedScript, '777');
|
chmodSync(escapedScript, '777');
|
||||||
|
|
||||||
const scriptPath = await io.which(escapedScript, true);
|
const scriptPath = await io.which(escapedScript, true);
|
||||||
|
|
||||||
|
let scriptArguments: string[] = [];
|
||||||
|
if (this.version) {
|
||||||
|
scriptArguments.concat(['--version', this.version]);
|
||||||
|
}
|
||||||
|
if (this.jsonfile) {
|
||||||
|
scriptArguments.concat(['--jsonfile', this.jsonfile]);
|
||||||
|
}
|
||||||
|
|
||||||
resultCode = await exec.exec(
|
resultCode = await exec.exec(
|
||||||
`"${scriptPath}"`,
|
`"${scriptPath}"`,
|
||||||
['--version', this.version],
|
scriptArguments,
|
||||||
{
|
{
|
||||||
listeners: {
|
listeners: {
|
||||||
stdout: (data: Buffer) => {
|
stdout: (data: Buffer) => {
|
||||||
@ -73,4 +89,5 @@ export class DotnetCoreInstaller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private version: string;
|
private version: string;
|
||||||
|
private jsonfile: string;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as installer from './installer';
|
import * as installer from './installer';
|
||||||
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
@ -12,11 +13,19 @@ async function run() {
|
|||||||
`::warning::Use the v1 tag to get the last version, master may contain breaking changes and will not contain any required packages in the future. i.e. actions/setup-dotnet@v1`
|
`::warning::Use the v1 tag to get the last version, master may contain breaking changes and will not contain any required packages in the future. i.e. actions/setup-dotnet@v1`
|
||||||
);
|
);
|
||||||
|
|
||||||
let version = core.getInput('dotnet-version');
|
let version: string = core.getInput('dotnet-version');
|
||||||
|
|
||||||
if (version) {
|
if (version) {
|
||||||
const dotnetInstaller = new installer.DotnetCoreInstaller(version);
|
const dotnetInstaller = new installer.DotnetCoreInstaller(version);
|
||||||
await dotnetInstaller.installDotnet();
|
await dotnetInstaller.installDotnet();
|
||||||
|
} else {
|
||||||
|
// Try to fall back to global.json
|
||||||
|
core.debug('No version found, falling back to global.json');
|
||||||
|
const globalJsonPath = path.join(process.cwd(), 'global.json');
|
||||||
|
if (fs.existsSync(globalJsonPath)) {
|
||||||
|
const dotnetInstaller = new installer.DotnetCoreInstaller(undefined, globalJsonPath);
|
||||||
|
await dotnetInstaller.installDotnet();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: setup proxy from runner proxy config
|
// TODO: setup proxy from runner proxy config
|
||||||
|
Loading…
x
Reference in New Issue
Block a user