Skip to content

Commit c53709e

Browse files
Add arguments for verbose output to installer script
1 parent c2fa09f commit c53709e

File tree

5 files changed

+103
-5
lines changed

5 files changed

+103
-5
lines changed

__tests__/installer.test.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,72 @@ describe('installer tests', () => {
251251
}
252252
);
253253

254+
it(`should supply 'verbose' argument to the installation script if verbose input is set to true`, async () => {
255+
const inputVersion = '10.0.101';
256+
const inputQuality = '' as QualityOptions;
257+
const inputVerbose = true;
258+
const stdout = `Fictitious dotnet version ${inputVersion} is installed`;
259+
260+
getExecOutputSpy.mockImplementation(() => {
261+
return Promise.resolve({
262+
exitCode: 0,
263+
stdout: `${stdout}`,
264+
stderr: ''
265+
});
266+
});
267+
maxSatisfyingSpy.mockImplementation(() => inputVersion);
268+
269+
const dotnetInstaller = new installer.DotnetCoreInstaller(
270+
inputVersion,
271+
inputQuality,
272+
undefined,
273+
inputVerbose
274+
);
275+
276+
await dotnetInstaller.installDotnet();
277+
278+
const scriptArguments = getExecOutputSpy.mock.calls.map(call =>
279+
(call[1] as string[]).join(' ')
280+
);
281+
const expectedArgument = IS_WINDOWS ? '-Verbose' : '--verbose';
282+
283+
expect(scriptArguments[0]).toContain(expectedArgument);
284+
expect(scriptArguments[1]).toContain(expectedArgument);
285+
});
286+
287+
it(`should not supply 'verbose' argument to the installation script if verbose input is set to false`, async () => {
288+
const inputVersion = '10.0.101';
289+
const inputQuality = '' as QualityOptions;
290+
const inputVerbose = false;
291+
const stdout = `Fictitious dotnet version ${inputVersion} is installed`;
292+
293+
getExecOutputSpy.mockImplementation(() => {
294+
return Promise.resolve({
295+
exitCode: 0,
296+
stdout: `${stdout}`,
297+
stderr: ''
298+
});
299+
});
300+
maxSatisfyingSpy.mockImplementation(() => inputVersion);
301+
302+
const dotnetInstaller = new installer.DotnetCoreInstaller(
303+
inputVersion,
304+
inputQuality,
305+
undefined,
306+
inputVerbose
307+
);
308+
309+
await dotnetInstaller.installDotnet();
310+
311+
const scriptArguments = getExecOutputSpy.mock.calls.map(call =>
312+
(call[1] as string[]).join(' ')
313+
);
314+
const expectedArgument = IS_WINDOWS ? '-Verbose' : '--verbose';
315+
316+
expect(scriptArguments[0]).not.toContain(expectedArgument);
317+
expect(scriptArguments[1]).not.toContain(expectedArgument);
318+
});
319+
254320
if (IS_WINDOWS) {
255321
it(`should supply '-ProxyAddress' argument to the installation script if env.variable 'https_proxy' is set`, async () => {
256322
process.env['https_proxy'] = 'https://proxy.com';

action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ inputs:
2020
cache:
2121
description: 'Optional input to enable caching of the NuGet global-packages folder'
2222
required: false
23-
default: false
23+
default: 'false'
2424
cache-dependency-path:
2525
description: 'Used to specify the path to a dependency file: packages.lock.json. Supports wildcards or a list of file names for caching multiple dependencies.'
2626
required: false
@@ -30,6 +30,10 @@ inputs:
3030
architecture:
3131
description: 'Optional architecture for the .NET install. Supported values: x64, x86, arm64, amd64, arm, s390x, ppc64le, riscv64. If not set, the installer auto-detects the current system architecture.'
3232
required: false
33+
verbose:
34+
description: 'Optional input to enable verbose output of installer script'
35+
required: false
36+
default: 'false'
3337
outputs:
3438
cache-hit:
3539
description: 'A boolean value to indicate if a cache was hit.'

dist/setup/index.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54938,6 +54938,12 @@ class DotnetInstallScript {
5493854938
}
5493954939
return this;
5494054940
}
54941+
useVerbose(verbose) {
54942+
if (verbose) {
54943+
this.useArguments(utils_1.IS_WINDOWS ? '-Verbose' : '--verbose');
54944+
}
54945+
return this;
54946+
}
5494154947
async execute() {
5494254948
const getExecOutputOptions = {
5494354949
ignoreReturnCode: true,
@@ -54987,13 +54993,15 @@ class DotnetCoreInstaller {
5498754993
version;
5498854994
quality;
5498954995
architecture;
54996+
verbose;
5499054997
static {
5499154998
DotnetInstallDir.setEnvironmentVariable();
5499254999
}
54993-
constructor(version, quality, architecture) {
55000+
constructor(version, quality, architecture, verbose) {
5499455001
this.version = version;
5499555002
this.quality = quality;
5499655003
this.architecture = architecture;
55004+
this.verbose = verbose;
5499755005
}
5499855006
async installDotnet() {
5499955007
const versionResolver = new DotnetVersionResolver(this.version);
@@ -55020,6 +55028,8 @@ class DotnetCoreInstaller {
5502055028
// Use latest stable version
5502155029
.useArguments(utils_1.IS_WINDOWS ? '-Channel' : '--channel', 'LTS')
5502255030
.useArguments(...architectureArguments)
55031+
// Enable verbose output depending on user input
55032+
.useVerbose(this.verbose)
5502355033
.execute();
5502455034
if (runtimeInstallOutput.exitCode) {
5502555035
/**
@@ -55039,6 +55049,8 @@ class DotnetCoreInstaller {
5503955049
// Use version provided by user
5504055050
.useVersion(dotnetVersion, this.quality)
5504155051
.useArguments(...architectureArguments)
55052+
// Enable verbose output depending on user input
55053+
.useVerbose(this.verbose)
5504255054
.execute();
5504355055
if (dotnetInstallOutput.exitCode) {
5504455056
throw new Error(`Failed to install dotnet, exit code: ${dotnetInstallOutput.exitCode}. ${dotnetInstallOutput.stderr}`);
@@ -55167,13 +55179,14 @@ async function run() {
5516755179
}
5516855180
if (versions.length) {
5516955181
const quality = core.getInput('dotnet-quality');
55182+
const verbose = core.getBooleanInput('verbose');
5517055183
if (quality && !qualityOptions.includes(quality)) {
5517155184
throw new Error(`Value '${quality}' is not supported for the 'dotnet-quality' option. Supported values are: daily, signed, validated, preview, ga.`);
5517255185
}
5517355186
let dotnetInstaller;
5517455187
const uniqueVersions = new Set(versions);
5517555188
for (const version of uniqueVersions) {
55176-
dotnetInstaller = new installer_1.DotnetCoreInstaller(version, quality, architecture);
55189+
dotnetInstaller = new installer_1.DotnetCoreInstaller(version, quality, architecture, verbose);
5517755190
const installedVersion = await dotnetInstaller.installDotnet();
5517855191
installedDotnetVersions.push(installedVersion);
5517955192
}

src/installer.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,14 @@ export class DotnetInstallScript {
213213
return this;
214214
}
215215

216+
public useVerbose(verbose?: boolean) {
217+
if (verbose) {
218+
this.useArguments(IS_WINDOWS ? '-Verbose' : '--verbose');
219+
}
220+
221+
return this;
222+
}
223+
216224
public async execute() {
217225
const getExecOutputOptions = {
218226
ignoreReturnCode: true,
@@ -279,7 +287,8 @@ export class DotnetCoreInstaller {
279287
constructor(
280288
private version: string,
281289
private quality: QualityOptions,
282-
private architecture?: string
290+
private architecture?: string,
291+
private verbose?: boolean
283292
) {}
284293

285294
public async installDotnet(): Promise<string | null> {
@@ -311,6 +320,8 @@ export class DotnetCoreInstaller {
311320
// Use latest stable version
312321
.useArguments(IS_WINDOWS ? '-Channel' : '--channel', 'LTS')
313322
.useArguments(...architectureArguments)
323+
// Enable verbose output depending on user input
324+
.useVerbose(this.verbose)
314325
.execute();
315326

316327
if (runtimeInstallOutput.exitCode) {
@@ -336,6 +347,8 @@ export class DotnetCoreInstaller {
336347
// Use version provided by user
337348
.useVersion(dotnetVersion, this.quality)
338349
.useArguments(...architectureArguments)
350+
// Enable verbose output depending on user input
351+
.useVerbose(this.verbose)
339352
.execute();
340353

341354
if (dotnetInstallOutput.exitCode) {

src/setup-dotnet.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export async function run() {
7777

7878
if (versions.length) {
7979
const quality = core.getInput('dotnet-quality') as QualityOptions;
80+
const verbose = core.getBooleanInput('verbose');
8081

8182
if (quality && !qualityOptions.includes(quality)) {
8283
throw new Error(
@@ -90,7 +91,8 @@ export async function run() {
9091
dotnetInstaller = new DotnetCoreInstaller(
9192
version,
9293
quality,
93-
architecture
94+
architecture,
95+
verbose
9496
);
9597
const installedVersion = await dotnetInstaller.installDotnet();
9698
installedDotnetVersions.push(installedVersion);

0 commit comments

Comments
 (0)