Skip to content

Commit 04a7bc7

Browse files
Add arguments for verbose output to installer script
1 parent 131b410 commit 04a7bc7

File tree

5 files changed

+95
-14
lines changed

5 files changed

+95
-14
lines changed

__tests__/installer.test.ts

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ describe('installer tests', () => {
4040
it('should throw the error in case of non-zero exit code of the installation script. The error message should contain logs.', async () => {
4141
const inputVersion = '10.0.101';
4242
const inputQuality = '' as QualityOptions;
43+
const inputVerbose = false;
4344
const errorMessage = 'fictitious error message!';
4445

4546
getExecOutputSpy.mockImplementation(() => {
@@ -52,7 +53,8 @@ describe('installer tests', () => {
5253

5354
const dotnetInstaller = new installer.DotnetCoreInstaller(
5455
inputVersion,
55-
inputQuality
56+
inputQuality,
57+
inputVerbose
5658
);
5759
await expect(dotnetInstaller.installDotnet()).rejects.toThrow(
5860
`Failed to install dotnet, exit code: 1. ${errorMessage}`
@@ -62,6 +64,7 @@ describe('installer tests', () => {
6264
it('should return version of .NET SDK after installation complete', async () => {
6365
const inputVersion = '10.0.101';
6466
const inputQuality = '' as QualityOptions;
67+
const inputVerbose = false;
6568
const stdout = `Fictitious dotnet version ${inputVersion} is installed`;
6669
getExecOutputSpy.mockImplementation(() => {
6770
return Promise.resolve({
@@ -74,7 +77,8 @@ describe('installer tests', () => {
7477

7578
const dotnetInstaller = new installer.DotnetCoreInstaller(
7679
inputVersion,
77-
inputQuality
80+
inputQuality,
81+
inputVerbose
7882
);
7983
const installedVersion = await dotnetInstaller.installDotnet();
8084

@@ -84,6 +88,7 @@ describe('installer tests', () => {
8488
it(`should supply 'version' argument to the installation script if supplied version is in A.B.C syntax`, async () => {
8589
const inputVersion = '10.0.101';
8690
const inputQuality = '' as QualityOptions;
91+
const inputVerbose = false;
8792
const stdout = `Fictitious dotnet version ${inputVersion} is installed`;
8893

8994
getExecOutputSpy.mockImplementation(() => {
@@ -97,7 +102,8 @@ describe('installer tests', () => {
97102

98103
const dotnetInstaller = new installer.DotnetCoreInstaller(
99104
inputVersion,
100-
inputQuality
105+
inputQuality,
106+
inputVerbose
101107
);
102108

103109
await dotnetInstaller.installDotnet();
@@ -122,6 +128,7 @@ describe('installer tests', () => {
122128
it(`should warn if the 'quality' input is set and the supplied version is in A.B.C syntax`, async () => {
123129
const inputVersion = '10.0.101';
124130
const inputQuality = 'ga' as QualityOptions;
131+
const inputVerbose = false;
125132
const stdout = `Fictitious dotnet version ${inputVersion} is installed`;
126133
getExecOutputSpy.mockImplementation(() => {
127134
return Promise.resolve({
@@ -134,7 +141,8 @@ describe('installer tests', () => {
134141

135142
const dotnetInstaller = new installer.DotnetCoreInstaller(
136143
inputVersion,
137-
inputQuality
144+
inputQuality,
145+
inputVerbose
138146
);
139147

140148
await dotnetInstaller.installDotnet();
@@ -147,6 +155,7 @@ describe('installer tests', () => {
147155
it(`should warn if the 'quality' input is set and version isn't in A.B.C syntax but major tag is lower then 6`, async () => {
148156
const inputVersion = '3.1';
149157
const inputQuality = 'ga' as QualityOptions;
158+
const inputVerbose = false;
150159
const stdout = `Fictitious dotnet version ${inputVersion} is installed`;
151160

152161
getExecOutputSpy.mockImplementation(() => {
@@ -160,7 +169,8 @@ describe('installer tests', () => {
160169

161170
const dotnetInstaller = new installer.DotnetCoreInstaller(
162171
inputVersion,
163-
inputQuality
172+
inputQuality,
173+
inputVerbose
164174
);
165175

166176
await dotnetInstaller.installDotnet();
@@ -174,6 +184,7 @@ describe('installer tests', () => {
174184
`should supply 'quality' argument to the installation script if quality input is set and version (%s) is not in A.B.C syntax`,
175185
async inputVersion => {
176186
const inputQuality = 'ga' as QualityOptions;
187+
const inputVerbose = false;
177188
const exitCode = 0;
178189
const stdout = `Fictitious dotnet version ${inputVersion} is installed`;
179190
getExecOutputSpy.mockImplementation(() => {
@@ -187,7 +198,8 @@ describe('installer tests', () => {
187198

188199
const dotnetInstaller = new installer.DotnetCoreInstaller(
189200
inputVersion,
190-
inputQuality
201+
inputQuality,
202+
inputVerbose
191203
);
192204

193205
await dotnetInstaller.installDotnet();
@@ -214,6 +226,7 @@ describe('installer tests', () => {
214226
`should supply 'channel' argument to the installation script if version (%s) isn't in A.B.C syntax`,
215227
async inputVersion => {
216228
const inputQuality = '' as QualityOptions;
229+
const inputVerbose = false;
217230
const exitCode = 0;
218231
const stdout = `Fictitious dotnet version ${inputVersion} is installed`;
219232
getExecOutputSpy.mockImplementation(() => {
@@ -227,7 +240,8 @@ describe('installer tests', () => {
227240

228241
const dotnetInstaller = new installer.DotnetCoreInstaller(
229242
inputVersion,
230-
inputQuality
243+
inputQuality,
244+
inputVerbose
231245
);
232246

233247
await dotnetInstaller.installDotnet();
@@ -250,11 +264,44 @@ describe('installer tests', () => {
250264
}
251265
);
252266

267+
it(`should supply 'verbose' argument to the installation script if verbose input is set`, async () => {
268+
const inputVersion = '10.0.101';
269+
const inputQuality = '' as QualityOptions;
270+
const inputVerbose = true;
271+
const stdout = `Fictitious dotnet version ${inputVersion} is installed`;
272+
273+
getExecOutputSpy.mockImplementation(() => {
274+
return Promise.resolve({
275+
exitCode: 0,
276+
stdout: `${stdout}`,
277+
stderr: ''
278+
});
279+
});
280+
maxSatisfyingSpy.mockImplementation(() => inputVersion);
281+
282+
const dotnetInstaller = new installer.DotnetCoreInstaller(
283+
inputVersion,
284+
inputQuality,
285+
inputVerbose
286+
);
287+
288+
await dotnetInstaller.installDotnet();
289+
290+
const scriptArguments = getExecOutputSpy.mock.calls.map(call =>
291+
(call[1] as string[]).join(' ')
292+
);
293+
const expectedArgument = IS_WINDOWS ? '-Verbose' : '--verbose';
294+
295+
expect(scriptArguments[0]).toContain(expectedArgument);
296+
expect(scriptArguments[1]).toContain(expectedArgument);
297+
});
298+
253299
if (IS_WINDOWS) {
254300
it(`should supply '-ProxyAddress' argument to the installation script if env.variable 'https_proxy' is set`, async () => {
255301
process.env['https_proxy'] = 'https://proxy.com';
256302
const inputVersion = '10.0.101';
257303
const inputQuality = '' as QualityOptions;
304+
const inputVerbose = false;
258305
const stdout = `Fictitious dotnet version ${inputVersion} is installed`;
259306

260307
getExecOutputSpy.mockImplementation(() => {
@@ -268,7 +315,8 @@ describe('installer tests', () => {
268315

269316
const dotnetInstaller = new installer.DotnetCoreInstaller(
270317
inputVersion,
271-
inputQuality
318+
inputQuality,
319+
inputVerbose
272320
);
273321

274322
await dotnetInstaller.installDotnet();
@@ -293,6 +341,7 @@ describe('installer tests', () => {
293341
process.env['no_proxy'] = 'first.url,second.url';
294342
const inputVersion = '10.0.101';
295343
const inputQuality = '' as QualityOptions;
344+
const inputVerbose = false;
296345
const stdout = `Fictitious dotnet version ${inputVersion} is installed`;
297346

298347
getExecOutputSpy.mockImplementation(() => {
@@ -306,7 +355,8 @@ describe('installer tests', () => {
306355

307356
const dotnetInstaller = new installer.DotnetCoreInstaller(
308357
inputVersion,
309-
inputQuality
358+
inputQuality,
359+
inputVerbose
310360
);
311361

312362
await dotnetInstaller.installDotnet();

action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@ 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
2727
workloads:
2828
description: 'Optional SDK workloads to install for additional platform support. Examples: wasm-tools, maui, aspire.'
2929
required: false
30+
verbose:
31+
description: 'Optional input to enable verbose output of installer script'
32+
required: false
33+
default: 'false'
3034
outputs:
3135
cache-hit:
3236
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
@@ -57004,6 +57004,12 @@ class DotnetInstallScript {
5700457004
}
5700557005
return this;
5700657006
}
57007+
enableVerbose(verbose) {
57008+
if (verbose) {
57009+
this.useArguments(utils_1.IS_WINDOWS ? '-Verbose' : '--verbose');
57010+
}
57011+
return this;
57012+
}
5700757013
async execute() {
5700857014
const getExecOutputOptions = {
5700957015
ignoreReturnCode: true,
@@ -57042,12 +57048,14 @@ exports.DotnetInstallDir = DotnetInstallDir;
5704257048
class DotnetCoreInstaller {
5704357049
version;
5704457050
quality;
57051+
verbose;
5704557052
static {
5704657053
DotnetInstallDir.setEnvironmentVariable();
5704757054
}
57048-
constructor(version, quality) {
57055+
constructor(version, quality, verbose) {
5704957056
this.version = version;
5705057057
this.quality = quality;
57058+
this.verbose = verbose;
5705157059
}
5705257060
async installDotnet() {
5705357061
const versionResolver = new DotnetVersionResolver(this.version);
@@ -57063,6 +57071,8 @@ class DotnetCoreInstaller {
5706357071
.useArguments(utils_1.IS_WINDOWS ? '-Runtime' : '--runtime', 'dotnet')
5706457072
// Use latest stable version
5706557073
.useArguments(utils_1.IS_WINDOWS ? '-Channel' : '--channel', 'LTS')
57074+
// Enable verbose output depending on user input
57075+
.enableVerbose(this.verbose)
5706657076
.execute();
5706757077
if (runtimeInstallOutput.exitCode) {
5706857078
/**
@@ -57080,6 +57090,8 @@ class DotnetCoreInstaller {
5708057090
.useArguments(utils_1.IS_WINDOWS ? '-SkipNonVersionedFiles' : '--skip-non-versioned-files')
5708157091
// Use version provided by user
5708257092
.useVersion(dotnetVersion, this.quality)
57093+
// Enable verbose output depending on user input
57094+
.enableVerbose(this.verbose)
5708357095
.execute();
5708457096
if (dotnetInstallOutput.exitCode) {
5708557097
throw new Error(`Failed to install dotnet, exit code: ${dotnetInstallOutput.exitCode}. ${dotnetInstallOutput.stderr}`);
@@ -57196,13 +57208,14 @@ async function run() {
5719657208
}
5719757209
if (versions.length) {
5719857210
const quality = core.getInput('dotnet-quality');
57211+
const verbose = core.getBooleanInput('verbose');
5719957212
if (quality && !qualityOptions.includes(quality)) {
5720057213
throw new Error(`Value '${quality}' is not supported for the 'dotnet-quality' option. Supported values are: daily, signed, validated, preview, ga.`);
5720157214
}
5720257215
let dotnetInstaller;
5720357216
const uniqueVersions = new Set(versions);
5720457217
for (const version of uniqueVersions) {
57205-
dotnetInstaller = new installer_1.DotnetCoreInstaller(version, quality);
57218+
dotnetInstaller = new installer_1.DotnetCoreInstaller(version, quality, verbose);
5720657219
const installedVersion = await dotnetInstaller.installDotnet();
5720757220
installedDotnetVersions.push(installedVersion);
5720857221
}

src/installer.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,14 @@ export class DotnetInstallScript {
203203
return this;
204204
}
205205

206+
public enableVerbose(verbose: boolean) {
207+
if (verbose) {
208+
this.useArguments(IS_WINDOWS ? '-Verbose' : '--verbose');
209+
}
210+
211+
return this;
212+
}
213+
206214
public async execute() {
207215
const getExecOutputOptions = {
208216
ignoreReturnCode: true,
@@ -257,7 +265,8 @@ export class DotnetCoreInstaller {
257265

258266
constructor(
259267
private version: string,
260-
private quality: QualityOptions
268+
private quality: QualityOptions,
269+
private verbose: boolean
261270
) {}
262271

263272
public async installDotnet(): Promise<string | null> {
@@ -277,6 +286,8 @@ export class DotnetCoreInstaller {
277286
.useArguments(IS_WINDOWS ? '-Runtime' : '--runtime', 'dotnet')
278287
// Use latest stable version
279288
.useArguments(IS_WINDOWS ? '-Channel' : '--channel', 'LTS')
289+
// Enable verbose output depending on user input
290+
.enableVerbose(this.verbose)
280291
.execute();
281292

282293
if (runtimeInstallOutput.exitCode) {
@@ -300,6 +311,8 @@ export class DotnetCoreInstaller {
300311
)
301312
// Use version provided by user
302313
.useVersion(dotnetVersion, this.quality)
314+
// Enable verbose output depending on user input
315+
.enableVerbose(this.verbose)
303316
.execute();
304317

305318
if (dotnetInstallOutput.exitCode) {

src/setup-dotnet.ts

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

6161
if (versions.length) {
6262
const quality = core.getInput('dotnet-quality') as QualityOptions;
63+
const verbose = core.getBooleanInput('verbose');
6364

6465
if (quality && !qualityOptions.includes(quality)) {
6566
throw new Error(
@@ -70,7 +71,7 @@ export async function run() {
7071
let dotnetInstaller: DotnetCoreInstaller;
7172
const uniqueVersions = new Set<string>(versions);
7273
for (const version of uniqueVersions) {
73-
dotnetInstaller = new DotnetCoreInstaller(version, quality);
74+
dotnetInstaller = new DotnetCoreInstaller(version, quality, verbose);
7475
const installedVersion = await dotnetInstaller.installDotnet();
7576
installedDotnetVersions.push(installedVersion);
7677
}

0 commit comments

Comments
 (0)