Added run-restore option.

Fixes https://github.com/actions/setup-dotnet/issues/199.
This commit is contained in:
AraHaan 2021-05-18 22:46:04 -04:00
parent bf3c3eb1fd
commit 5c91ca7fee
2 changed files with 34 additions and 0 deletions

View File

@ -16,6 +16,9 @@ inputs:
include-prerelease: include-prerelease:
description: 'Whether prerelease versions should be matched with non-exact versions (for example 5.0.0-preview.6 being matched by 5, 5.0, 5.x or 5.0.x). Defaults to false if not provided.' description: 'Whether prerelease versions should be matched with non-exact versions (for example 5.0.0-preview.6 being matched by 5, 5.0, 5.x or 5.0.x). Defaults to false if not provided.'
required: False required: False
run-restore:
description: 'Optionally run dotnet restore on the project after the target .NET SDK is installed.'
required: False
runs: runs:
using: 'node12' using: 'node12'
main: 'dist/index.js' main: 'dist/index.js'

View File

@ -1,4 +1,5 @@
import * as core from '@actions/core'; import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as installer from './installer'; import * as installer from './installer';
import * as fs from 'fs'; import * as fs from 'fs';
import * as path from 'path'; import * as path from 'path';
@ -14,6 +15,7 @@ export async function run() {
// Proxy, auth, (etc) are still set up, even if no version is identified // Proxy, auth, (etc) are still set up, even if no version is identified
// //
let version = core.getInput('dotnet-version'); let version = core.getInput('dotnet-version');
let runrestore = core.getInput('run-restore');
if (!version) { if (!version) {
// Try to fall back to global.json // Try to fall back to global.json
core.debug('No version found, trying to find version from global.json'); core.debug('No version found, trying to find version from global.json');
@ -39,6 +41,35 @@ export async function run() {
includePrerelease includePrerelease
); );
await dotnetInstaller.installDotnet(); await dotnetInstaller.installDotnet();
if (runrestore)
{
var options: ExecOptions = {
listeners: {
stdout: (data: Buffer) => {
output += data.toString();
}
},
env: envVariables
};
const powershellPath = await io.which('powershell', true);
let resultCode = await exec.exec(
`"${powershellPath}"`,
[
'-NoLogo',
'-Sta',
'-NoProfile',
'-NonInteractive',
'-ExecutionPolicy',
'Unrestricted',
'-Command',
'dotnet restore'
],
options
);
if (resultCode != 0) {
throw new Error(`Failed to restore projects. Err Code=${resultCode} ${output}`);
}
}
} }
const sourceUrl: string = core.getInput('source-url'); const sourceUrl: string = core.getInput('source-url');