Add arguments for verbose output to installer script

This commit is contained in:
Andreas Böhm 2024-06-18 09:36:25 +02:00
parent dbebe359e4
commit 18ac412645
5 changed files with 94 additions and 14 deletions

View File

@ -40,6 +40,7 @@ describe('installer tests', () => {
it('should throw the error in case of non-zero exit code of the installation script. The error message should contain logs.', async () => { it('should throw the error in case of non-zero exit code of the installation script. The error message should contain logs.', async () => {
const inputVersion = '3.1.100'; const inputVersion = '3.1.100';
const inputQuality = '' as QualityOptions; const inputQuality = '' as QualityOptions;
const inputVerbose = false;
const errorMessage = 'fictitious error message!'; const errorMessage = 'fictitious error message!';
getExecOutputSpy.mockImplementation(() => { getExecOutputSpy.mockImplementation(() => {
@ -52,7 +53,8 @@ describe('installer tests', () => {
const dotnetInstaller = new installer.DotnetCoreInstaller( const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion, inputVersion,
inputQuality inputQuality,
inputVerbose
); );
await expect(dotnetInstaller.installDotnet()).rejects.toThrow( await expect(dotnetInstaller.installDotnet()).rejects.toThrow(
`Failed to install dotnet, exit code: 1. ${errorMessage}` `Failed to install dotnet, exit code: 1. ${errorMessage}`
@ -62,6 +64,7 @@ describe('installer tests', () => {
it('should return version of .NET SDK after installation complete', async () => { it('should return version of .NET SDK after installation complete', async () => {
const inputVersion = '3.1.100'; const inputVersion = '3.1.100';
const inputQuality = '' as QualityOptions; const inputQuality = '' as QualityOptions;
const inputVerbose = false;
const stdout = `Fictitious dotnet version ${inputVersion} is installed`; const stdout = `Fictitious dotnet version ${inputVersion} is installed`;
getExecOutputSpy.mockImplementation(() => { getExecOutputSpy.mockImplementation(() => {
return Promise.resolve({ return Promise.resolve({
@ -74,7 +77,8 @@ describe('installer tests', () => {
const dotnetInstaller = new installer.DotnetCoreInstaller( const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion, inputVersion,
inputQuality inputQuality,
inputVerbose
); );
const installedVersion = await dotnetInstaller.installDotnet(); const installedVersion = await dotnetInstaller.installDotnet();
@ -84,6 +88,7 @@ describe('installer tests', () => {
it(`should supply 'version' argument to the installation script if supplied version is in A.B.C syntax`, async () => { it(`should supply 'version' argument to the installation script if supplied version is in A.B.C syntax`, async () => {
const inputVersion = '6.0.300'; const inputVersion = '6.0.300';
const inputQuality = '' as QualityOptions; const inputQuality = '' as QualityOptions;
const inputVerbose = false;
const stdout = `Fictitious dotnet version ${inputVersion} is installed`; const stdout = `Fictitious dotnet version ${inputVersion} is installed`;
getExecOutputSpy.mockImplementation(() => { getExecOutputSpy.mockImplementation(() => {
@ -97,7 +102,8 @@ describe('installer tests', () => {
const dotnetInstaller = new installer.DotnetCoreInstaller( const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion, inputVersion,
inputQuality inputQuality,
inputVerbose
); );
await dotnetInstaller.installDotnet(); await dotnetInstaller.installDotnet();
@ -122,6 +128,7 @@ describe('installer tests', () => {
it(`should warn if the 'quality' input is set and the supplied version is in A.B.C syntax`, async () => { it(`should warn if the 'quality' input is set and the supplied version is in A.B.C syntax`, async () => {
const inputVersion = '6.0.300'; const inputVersion = '6.0.300';
const inputQuality = 'ga' as QualityOptions; const inputQuality = 'ga' as QualityOptions;
const inputVerbose = false;
const stdout = `Fictitious dotnet version ${inputVersion} is installed`; const stdout = `Fictitious dotnet version ${inputVersion} is installed`;
getExecOutputSpy.mockImplementation(() => { getExecOutputSpy.mockImplementation(() => {
return Promise.resolve({ return Promise.resolve({
@ -134,7 +141,8 @@ describe('installer tests', () => {
const dotnetInstaller = new installer.DotnetCoreInstaller( const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion, inputVersion,
inputQuality inputQuality,
inputVerbose
); );
await dotnetInstaller.installDotnet(); await dotnetInstaller.installDotnet();
@ -147,6 +155,7 @@ describe('installer tests', () => {
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 () => { 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 () => {
const inputVersion = '3.1'; const inputVersion = '3.1';
const inputQuality = 'ga' as QualityOptions; const inputQuality = 'ga' as QualityOptions;
const inputVerbose = false;
const stdout = `Fictitious dotnet version 3.1.100 is installed`; const stdout = `Fictitious dotnet version 3.1.100 is installed`;
getExecOutputSpy.mockImplementation(() => { getExecOutputSpy.mockImplementation(() => {
@ -160,7 +169,8 @@ describe('installer tests', () => {
const dotnetInstaller = new installer.DotnetCoreInstaller( const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion, inputVersion,
inputQuality inputQuality,
inputVerbose
); );
await dotnetInstaller.installDotnet(); await dotnetInstaller.installDotnet();
@ -174,6 +184,7 @@ describe('installer tests', () => {
`should supply 'quality' argument to the installation script if quality input is set and version (%s) is not in A.B.C syntax`, `should supply 'quality' argument to the installation script if quality input is set and version (%s) is not in A.B.C syntax`,
async inputVersion => { async inputVersion => {
const inputQuality = 'ga' as QualityOptions; const inputQuality = 'ga' as QualityOptions;
const inputVerbose = false;
const exitCode = 0; const exitCode = 0;
const stdout = `Fictitious dotnet version 6.0.0 is installed`; const stdout = `Fictitious dotnet version 6.0.0 is installed`;
getExecOutputSpy.mockImplementation(() => { getExecOutputSpy.mockImplementation(() => {
@ -187,7 +198,8 @@ describe('installer tests', () => {
const dotnetInstaller = new installer.DotnetCoreInstaller( const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion, inputVersion,
inputQuality inputQuality,
inputVerbose
); );
await dotnetInstaller.installDotnet(); await dotnetInstaller.installDotnet();
@ -214,6 +226,7 @@ describe('installer tests', () => {
`should supply 'channel' argument to the installation script if version (%s) isn't in A.B.C syntax`, `should supply 'channel' argument to the installation script if version (%s) isn't in A.B.C syntax`,
async inputVersion => { async inputVersion => {
const inputQuality = '' as QualityOptions; const inputQuality = '' as QualityOptions;
const inputVerbose = false;
const exitCode = 0; const exitCode = 0;
const stdout = `Fictitious dotnet version 6.0.0 is installed`; const stdout = `Fictitious dotnet version 6.0.0 is installed`;
getExecOutputSpy.mockImplementation(() => { getExecOutputSpy.mockImplementation(() => {
@ -227,7 +240,8 @@ describe('installer tests', () => {
const dotnetInstaller = new installer.DotnetCoreInstaller( const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion, inputVersion,
inputQuality inputQuality,
inputVerbose
); );
await dotnetInstaller.installDotnet(); await dotnetInstaller.installDotnet();
@ -250,11 +264,44 @@ describe('installer tests', () => {
} }
); );
it(`should supply 'verbose' argument to the installation script if verbose input is set`, async () => {
const inputVersion = '6.0.300';
const inputQuality = '' as QualityOptions;
const inputVerbose = true;
const stdout = `Fictitious dotnet version ${inputVersion} is installed`;
getExecOutputSpy.mockImplementation(() => {
return Promise.resolve({
exitCode: 0,
stdout: `${stdout}`,
stderr: ''
});
});
maxSatisfyingSpy.mockImplementation(() => inputVersion);
const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion,
inputQuality,
inputVerbose
);
await dotnetInstaller.installDotnet();
const scriptArguments = getExecOutputSpy.mock.calls.map(call =>
(call[1] as string[]).join(' ')
);
const expectedArgument = IS_WINDOWS ? '-Verbose' : '--verbose';
expect(scriptArguments[0]).toContain(expectedArgument);
expect(scriptArguments[1]).toContain(expectedArgument);
});
if (IS_WINDOWS) { if (IS_WINDOWS) {
it(`should supply '-ProxyAddress' argument to the installation script if env.variable 'https_proxy' is set`, async () => { it(`should supply '-ProxyAddress' argument to the installation script if env.variable 'https_proxy' is set`, async () => {
process.env['https_proxy'] = 'https://proxy.com'; process.env['https_proxy'] = 'https://proxy.com';
const inputVersion = '6.0.100'; const inputVersion = '6.0.100';
const inputQuality = '' as QualityOptions; const inputQuality = '' as QualityOptions;
const inputVerbose = false;
const stdout = `Fictitious dotnet version ${inputVersion} is installed`; const stdout = `Fictitious dotnet version ${inputVersion} is installed`;
getExecOutputSpy.mockImplementation(() => { getExecOutputSpy.mockImplementation(() => {
@ -268,7 +315,8 @@ describe('installer tests', () => {
const dotnetInstaller = new installer.DotnetCoreInstaller( const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion, inputVersion,
inputQuality inputQuality,
inputVerbose
); );
await dotnetInstaller.installDotnet(); await dotnetInstaller.installDotnet();
@ -293,6 +341,7 @@ describe('installer tests', () => {
process.env['no_proxy'] = 'first.url,second.url'; process.env['no_proxy'] = 'first.url,second.url';
const inputVersion = '6.0.100'; const inputVersion = '6.0.100';
const inputQuality = '' as QualityOptions; const inputQuality = '' as QualityOptions;
const inputVerbose = false;
const stdout = `Fictitious dotnet version 6.0.0 is installed`; const stdout = `Fictitious dotnet version 6.0.0 is installed`;
getExecOutputSpy.mockImplementation(() => { getExecOutputSpy.mockImplementation(() => {
@ -306,7 +355,8 @@ describe('installer tests', () => {
const dotnetInstaller = new installer.DotnetCoreInstaller( const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion, inputVersion,
inputQuality inputQuality,
inputVerbose
); );
await dotnetInstaller.installDotnet(); await dotnetInstaller.installDotnet();

View File

@ -20,10 +20,14 @@ inputs:
cache: cache:
description: 'Optional input to enable caching of the NuGet global-packages folder' description: 'Optional input to enable caching of the NuGet global-packages folder'
required: false required: false
default: false default: 'false'
cache-dependency-path: cache-dependency-path:
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.' 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.'
required: false required: false
verbose:
description: 'Optional input to enable verbose output of installer script'
required: false
default: 'false'
outputs: outputs:
cache-hit: cache-hit:
description: 'A boolean value to indicate if a cache was hit.' description: 'A boolean value to indicate if a cache was hit.'

16
dist/setup/index.js vendored
View File

@ -93879,6 +93879,12 @@ class DotnetInstallScript {
} }
return this; return this;
} }
enableVerbose(verbose) {
if (verbose) {
this.useArguments(utils_1.IS_WINDOWS ? '-Verbose' : '--verbose');
}
return this;
}
execute() { execute() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const getExecOutputOptions = { const getExecOutputOptions = {
@ -93917,9 +93923,10 @@ DotnetInstallDir.dirPath = process.env['DOTNET_INSTALL_DIR']
? DotnetInstallDir.convertInstallPathToAbsolute(process.env['DOTNET_INSTALL_DIR']) ? DotnetInstallDir.convertInstallPathToAbsolute(process.env['DOTNET_INSTALL_DIR'])
: DotnetInstallDir.default[utils_1.PLATFORM]; : DotnetInstallDir.default[utils_1.PLATFORM];
class DotnetCoreInstaller { class DotnetCoreInstaller {
constructor(version, quality) { constructor(version, quality, verbose) {
this.version = version; this.version = version;
this.quality = quality; this.quality = quality;
this.verbose = verbose;
} }
installDotnet() { installDotnet() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
@ -93936,6 +93943,8 @@ class DotnetCoreInstaller {
.useArguments(utils_1.IS_WINDOWS ? '-Runtime' : '--runtime', 'dotnet') .useArguments(utils_1.IS_WINDOWS ? '-Runtime' : '--runtime', 'dotnet')
// Use latest stable version // Use latest stable version
.useArguments(utils_1.IS_WINDOWS ? '-Channel' : '--channel', 'LTS') .useArguments(utils_1.IS_WINDOWS ? '-Channel' : '--channel', 'LTS')
// Enable verbose output depending on user input
.enableVerbose(this.verbose)
.execute(); .execute();
if (runtimeInstallOutput.exitCode) { if (runtimeInstallOutput.exitCode) {
/** /**
@ -93953,6 +93962,8 @@ class DotnetCoreInstaller {
.useArguments(utils_1.IS_WINDOWS ? '-SkipNonVersionedFiles' : '--skip-non-versioned-files') .useArguments(utils_1.IS_WINDOWS ? '-SkipNonVersionedFiles' : '--skip-non-versioned-files')
// Use version provided by user // Use version provided by user
.useVersion(dotnetVersion, this.quality) .useVersion(dotnetVersion, this.quality)
// Enable verbose output depending on user input
.enableVerbose(this.verbose)
.execute(); .execute();
if (dotnetInstallOutput.exitCode) { if (dotnetInstallOutput.exitCode) {
throw new Error(`Failed to install dotnet, exit code: ${dotnetInstallOutput.exitCode}. ${dotnetInstallOutput.stderr}`); throw new Error(`Failed to install dotnet, exit code: ${dotnetInstallOutput.exitCode}. ${dotnetInstallOutput.stderr}`);
@ -94072,13 +94083,14 @@ function run() {
} }
if (versions.length) { if (versions.length) {
const quality = core.getInput('dotnet-quality'); const quality = core.getInput('dotnet-quality');
const verbose = core.getBooleanInput('verbose');
if (quality && !qualityOptions.includes(quality)) { if (quality && !qualityOptions.includes(quality)) {
throw new Error(`Value '${quality}' is not supported for the 'dotnet-quality' option. Supported values are: daily, signed, validated, preview, ga.`); throw new Error(`Value '${quality}' is not supported for the 'dotnet-quality' option. Supported values are: daily, signed, validated, preview, ga.`);
} }
let dotnetInstaller; let dotnetInstaller;
const uniqueVersions = new Set(versions); const uniqueVersions = new Set(versions);
for (const version of uniqueVersions) { for (const version of uniqueVersions) {
dotnetInstaller = new installer_1.DotnetCoreInstaller(version, quality); dotnetInstaller = new installer_1.DotnetCoreInstaller(version, quality, verbose);
const installedVersion = yield dotnetInstaller.installDotnet(); const installedVersion = yield dotnetInstaller.installDotnet();
installedDotnetVersions.push(installedVersion); installedDotnetVersions.push(installedVersion);
} }

View File

@ -201,6 +201,14 @@ export class DotnetInstallScript {
return this; return this;
} }
public enableVerbose(verbose: boolean) {
if (verbose) {
this.useArguments(IS_WINDOWS ? '-Verbose' : '--verbose');
}
return this;
}
public async execute() { public async execute() {
const getExecOutputOptions = { const getExecOutputOptions = {
ignoreReturnCode: true, ignoreReturnCode: true,
@ -255,7 +263,8 @@ export class DotnetCoreInstaller {
constructor( constructor(
private version: string, private version: string,
private quality: QualityOptions private quality: QualityOptions,
private verbose: boolean
) {} ) {}
public async installDotnet(): Promise<string | null> { public async installDotnet(): Promise<string | null> {
@ -275,6 +284,8 @@ export class DotnetCoreInstaller {
.useArguments(IS_WINDOWS ? '-Runtime' : '--runtime', 'dotnet') .useArguments(IS_WINDOWS ? '-Runtime' : '--runtime', 'dotnet')
// Use latest stable version // Use latest stable version
.useArguments(IS_WINDOWS ? '-Channel' : '--channel', 'LTS') .useArguments(IS_WINDOWS ? '-Channel' : '--channel', 'LTS')
// Enable verbose output depending on user input
.enableVerbose(this.verbose)
.execute(); .execute();
if (runtimeInstallOutput.exitCode) { if (runtimeInstallOutput.exitCode) {
@ -298,6 +309,8 @@ export class DotnetCoreInstaller {
) )
// Use version provided by user // Use version provided by user
.useVersion(dotnetVersion, this.quality) .useVersion(dotnetVersion, this.quality)
// Enable verbose output depending on user input
.enableVerbose(this.verbose)
.execute(); .execute();
if (dotnetInstallOutput.exitCode) { if (dotnetInstallOutput.exitCode) {

View File

@ -59,6 +59,7 @@ export async function run() {
if (versions.length) { if (versions.length) {
const quality = core.getInput('dotnet-quality') as QualityOptions; const quality = core.getInput('dotnet-quality') as QualityOptions;
const verbose = core.getBooleanInput('verbose');
if (quality && !qualityOptions.includes(quality)) { if (quality && !qualityOptions.includes(quality)) {
throw new Error( throw new Error(
@ -69,7 +70,7 @@ export async function run() {
let dotnetInstaller: DotnetCoreInstaller; let dotnetInstaller: DotnetCoreInstaller;
const uniqueVersions = new Set<string>(versions); const uniqueVersions = new Set<string>(versions);
for (const version of uniqueVersions) { for (const version of uniqueVersions) {
dotnetInstaller = new DotnetCoreInstaller(version, quality); dotnetInstaller = new DotnetCoreInstaller(version, quality, verbose);
const installedVersion = await dotnetInstaller.installDotnet(); const installedVersion = await dotnetInstaller.installDotnet();
installedDotnetVersions.push(installedVersion); installedDotnetVersions.push(installedVersion);
} }