Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add arguments for verbose output to installer script #542

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 59 additions & 9 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
const inputVersion = '3.1.100';
const inputQuality = '' as QualityOptions;
const inputVerbose = false;
const errorMessage = 'fictitious error message!';

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

const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion,
inputQuality
inputQuality,
inputVerbose
);
await expect(dotnetInstaller.installDotnet()).rejects.toThrow(
`Failed to install dotnet, exit code: 1. ${errorMessage}`
Expand All @@ -62,6 +64,7 @@ describe('installer tests', () => {
it('should return version of .NET SDK after installation complete', async () => {
const inputVersion = '3.1.100';
const inputQuality = '' as QualityOptions;
const inputVerbose = false;
const stdout = `Fictitious dotnet version ${inputVersion} is installed`;
getExecOutputSpy.mockImplementation(() => {
return Promise.resolve({
Expand All @@ -74,7 +77,8 @@ describe('installer tests', () => {

const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion,
inputQuality
inputQuality,
inputVerbose
);
const installedVersion = await dotnetInstaller.installDotnet();

Expand All @@ -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 () => {
const inputVersion = '6.0.300';
const inputQuality = '' as QualityOptions;
const inputVerbose = false;
const stdout = `Fictitious dotnet version ${inputVersion} is installed`;

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

const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion,
inputQuality
inputQuality,
inputVerbose
);

await dotnetInstaller.installDotnet();
Expand All @@ -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 () => {
const inputVersion = '6.0.300';
const inputQuality = 'ga' as QualityOptions;
const inputVerbose = false;
const stdout = `Fictitious dotnet version ${inputVersion} is installed`;
getExecOutputSpy.mockImplementation(() => {
return Promise.resolve({
Expand All @@ -134,7 +141,8 @@ describe('installer tests', () => {

const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion,
inputQuality
inputQuality,
inputVerbose
);

await dotnetInstaller.installDotnet();
Expand All @@ -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 () => {
const inputVersion = '3.1';
const inputQuality = 'ga' as QualityOptions;
const inputVerbose = false;
const stdout = `Fictitious dotnet version 3.1.100 is installed`;

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

const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion,
inputQuality
inputQuality,
inputVerbose
);

await dotnetInstaller.installDotnet();
Expand All @@ -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`,
async inputVersion => {
const inputQuality = 'ga' as QualityOptions;
const inputVerbose = false;
const exitCode = 0;
const stdout = `Fictitious dotnet version 6.0.0 is installed`;
getExecOutputSpy.mockImplementation(() => {
Expand All @@ -187,7 +198,8 @@ describe('installer tests', () => {

const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion,
inputQuality
inputQuality,
inputVerbose
);

await dotnetInstaller.installDotnet();
Expand All @@ -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`,
async inputVersion => {
const inputQuality = '' as QualityOptions;
const inputVerbose = false;
const exitCode = 0;
const stdout = `Fictitious dotnet version 6.0.0 is installed`;
getExecOutputSpy.mockImplementation(() => {
Expand All @@ -227,7 +240,8 @@ describe('installer tests', () => {

const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion,
inputQuality
inputQuality,
inputVerbose
);

await dotnetInstaller.installDotnet();
Expand All @@ -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) {
it(`should supply '-ProxyAddress' argument to the installation script if env.variable 'https_proxy' is set`, async () => {
process.env['https_proxy'] = 'https://proxy.com';
const inputVersion = '6.0.100';
const inputQuality = '' as QualityOptions;
const inputVerbose = false;
const stdout = `Fictitious dotnet version ${inputVersion} is installed`;

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

const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion,
inputQuality
inputQuality,
inputVerbose
);

await dotnetInstaller.installDotnet();
Expand All @@ -293,6 +341,7 @@ describe('installer tests', () => {
process.env['no_proxy'] = 'first.url,second.url';
const inputVersion = '6.0.100';
const inputQuality = '' as QualityOptions;
const inputVerbose = false;
const stdout = `Fictitious dotnet version 6.0.0 is installed`;

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

const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion,
inputQuality
inputQuality,
inputVerbose
);

await dotnetInstaller.installDotnet();
Expand Down
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ inputs:
cache:
description: 'Optional input to enable caching of the NuGet global-packages folder'
required: false
default: false
default: 'false'
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.'
required: false
verbose:
description: 'Optional input to enable verbose output of installer script'
required: false
default: 'false'
outputs:
cache-hit:
description: 'A boolean value to indicate if a cache was hit.'
Expand Down
16 changes: 14 additions & 2 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93879,6 +93879,12 @@ class DotnetInstallScript {
}
return this;
}
enableVerbose(verbose) {
if (verbose) {
this.useArguments(utils_1.IS_WINDOWS ? '-Verbose' : '--verbose');
}
return this;
}
execute() {
return __awaiter(this, void 0, void 0, function* () {
const getExecOutputOptions = {
Expand Down Expand Up @@ -93917,9 +93923,10 @@ DotnetInstallDir.dirPath = process.env['DOTNET_INSTALL_DIR']
? DotnetInstallDir.convertInstallPathToAbsolute(process.env['DOTNET_INSTALL_DIR'])
: DotnetInstallDir.default[utils_1.PLATFORM];
class DotnetCoreInstaller {
constructor(version, quality) {
constructor(version, quality, verbose) {
this.version = version;
this.quality = quality;
this.verbose = verbose;
}
installDotnet() {
return __awaiter(this, void 0, void 0, function* () {
Expand All @@ -93936,6 +93943,8 @@ class DotnetCoreInstaller {
.useArguments(utils_1.IS_WINDOWS ? '-Runtime' : '--runtime', 'dotnet')
// Use latest stable version
.useArguments(utils_1.IS_WINDOWS ? '-Channel' : '--channel', 'LTS')
// Enable verbose output depending on user input
.enableVerbose(this.verbose)
.execute();
if (runtimeInstallOutput.exitCode) {
/**
Expand All @@ -93953,6 +93962,8 @@ class DotnetCoreInstaller {
.useArguments(utils_1.IS_WINDOWS ? '-SkipNonVersionedFiles' : '--skip-non-versioned-files')
// Use version provided by user
.useVersion(dotnetVersion, this.quality)
// Enable verbose output depending on user input
.enableVerbose(this.verbose)
.execute();
if (dotnetInstallOutput.exitCode) {
throw new Error(`Failed to install dotnet, exit code: ${dotnetInstallOutput.exitCode}. ${dotnetInstallOutput.stderr}`);
Expand Down Expand Up @@ -94072,13 +94083,14 @@ function run() {
}
if (versions.length) {
const quality = core.getInput('dotnet-quality');
const verbose = core.getBooleanInput('verbose');
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.`);
}
let dotnetInstaller;
const uniqueVersions = new Set(versions);
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();
installedDotnetVersions.push(installedVersion);
}
Expand Down
15 changes: 14 additions & 1 deletion src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ export class DotnetInstallScript {
return this;
}

public enableVerbose(verbose: boolean) {
if (verbose) {
this.useArguments(IS_WINDOWS ? '-Verbose' : '--verbose');
}

return this;
}

public async execute() {
const getExecOutputOptions = {
ignoreReturnCode: true,
Expand Down Expand Up @@ -255,7 +263,8 @@ export class DotnetCoreInstaller {

constructor(
private version: string,
private quality: QualityOptions
private quality: QualityOptions,
private verbose: boolean
) {}

public async installDotnet(): Promise<string | null> {
Expand All @@ -275,6 +284,8 @@ export class DotnetCoreInstaller {
.useArguments(IS_WINDOWS ? '-Runtime' : '--runtime', 'dotnet')
// Use latest stable version
.useArguments(IS_WINDOWS ? '-Channel' : '--channel', 'LTS')
// Enable verbose output depending on user input
.enableVerbose(this.verbose)
.execute();

if (runtimeInstallOutput.exitCode) {
Expand All @@ -298,6 +309,8 @@ export class DotnetCoreInstaller {
)
// Use version provided by user
.useVersion(dotnetVersion, this.quality)
// Enable verbose output depending on user input
.enableVerbose(this.verbose)
.execute();

if (dotnetInstallOutput.exitCode) {
Expand Down
3 changes: 2 additions & 1 deletion src/setup-dotnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export async function run() {

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

if (quality && !qualityOptions.includes(quality)) {
throw new Error(
Expand All @@ -69,7 +70,7 @@ export async function run() {
let dotnetInstaller: DotnetCoreInstaller;
const uniqueVersions = new Set<string>(versions);
for (const version of uniqueVersions) {
dotnetInstaller = new DotnetCoreInstaller(version, quality);
dotnetInstaller = new DotnetCoreInstaller(version, quality, verbose);
const installedVersion = await dotnetInstaller.installDotnet();
installedDotnetVersions.push(installedVersion);
}
Expand Down