From 5c91ca7feeec282c41ca3a20a6092ed306501b53 Mon Sep 17 00:00:00 2001 From: AraHaan Date: Tue, 18 May 2021 22:46:04 -0400 Subject: [PATCH] Added run-restore option. Fixes https://github.com/actions/setup-dotnet/issues/199. --- action.yml | 3 +++ src/setup-dotnet.ts | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/action.yml b/action.yml index ab0fe9e..6689b92 100644 --- a/action.yml +++ b/action.yml @@ -16,6 +16,9 @@ inputs: 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.' required: False + run-restore: + description: 'Optionally run dotnet restore on the project after the target .NET SDK is installed.' + required: False runs: using: 'node12' main: 'dist/index.js' diff --git a/src/setup-dotnet.ts b/src/setup-dotnet.ts index 2a0914f..46a1526 100644 --- a/src/setup-dotnet.ts +++ b/src/setup-dotnet.ts @@ -1,4 +1,5 @@ import * as core from '@actions/core'; +import * as exec from '@actions/exec'; import * as installer from './installer'; import * as fs from 'fs'; 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 // let version = core.getInput('dotnet-version'); + let runrestore = core.getInput('run-restore'); if (!version) { // Try to fall back to global.json core.debug('No version found, trying to find version from global.json'); @@ -39,6 +41,35 @@ export async function run() { includePrerelease ); 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');