Merge ead76a044caac473d3f7a8f721e288f08d26adf4 into 2216f56ae1eec353f06abd464e2ec435fa5f5d43

This commit is contained in:
Nikolai Laevskii 2023-10-18 05:52:27 +00:00 committed by GitHub
commit 3dfa873938
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 114 additions and 26 deletions

View File

@ -51,7 +51,9 @@ describe('installer tests', () => {
}); });
const dotnetInstaller = new installer.DotnetCoreInstaller( const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion, await new installer.DotnetVersionResolver(
inputVersion
).createDotnetVersion(),
inputQuality inputQuality
); );
await expect(dotnetInstaller.installDotnet()).rejects.toThrow( await expect(dotnetInstaller.installDotnet()).rejects.toThrow(
@ -73,7 +75,9 @@ describe('installer tests', () => {
maxSatisfyingSpy.mockImplementation(() => inputVersion); maxSatisfyingSpy.mockImplementation(() => inputVersion);
const dotnetInstaller = new installer.DotnetCoreInstaller( const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion, await new installer.DotnetVersionResolver(
inputVersion
).createDotnetVersion(),
inputQuality inputQuality
); );
const installedVersion = await dotnetInstaller.installDotnet(); const installedVersion = await dotnetInstaller.installDotnet();
@ -96,7 +100,9 @@ describe('installer tests', () => {
maxSatisfyingSpy.mockImplementation(() => inputVersion); maxSatisfyingSpy.mockImplementation(() => inputVersion);
const dotnetInstaller = new installer.DotnetCoreInstaller( const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion, await new installer.DotnetVersionResolver(
inputVersion
).createDotnetVersion(),
inputQuality inputQuality
); );
@ -119,6 +125,48 @@ describe('installer tests', () => {
expect(scriptArguments).toContain(expectedArgument); expect(scriptArguments).toContain(expectedArgument);
}); });
it(`should supply 'runtime' argument to the installation script if runtimeOnly parameter is true`, async () => {
const inputVersion = '6.0.300';
const inputQuality = '' as QualityOptions;
const stdout = `Fictitious dotnet version ${inputVersion} is installed`;
const resolvedVersion = await new installer.DotnetVersionResolver(
inputVersion
).createDotnetVersion();
getExecOutputSpy.mockImplementation(() => {
return Promise.resolve({
exitCode: 0,
stdout: `${stdout}`,
stderr: ''
});
});
maxSatisfyingSpy.mockImplementation(() => inputVersion);
const dotnetInstaller = new installer.DotnetCoreInstaller(
resolvedVersion,
inputQuality,
true
);
await dotnetInstaller.installDotnet();
/**
* First time script would be called to
* install runtime of the latest version in order
* to provide latest CLI, here we are checking only the
* second one that installs actual requested runtime
*/
const callIndex = 1;
const scriptArguments = (
getExecOutputSpy.mock.calls[callIndex][1] as string[]
).join(' ');
const expectedArgument = IS_WINDOWS ? `-Runtime` : `--runtime`;
expect(scriptArguments).toContain(expectedArgument);
});
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;
@ -133,7 +181,9 @@ describe('installer tests', () => {
maxSatisfyingSpy.mockImplementation(() => inputVersion); maxSatisfyingSpy.mockImplementation(() => inputVersion);
const dotnetInstaller = new installer.DotnetCoreInstaller( const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion, await new installer.DotnetVersionResolver(
inputVersion
).createDotnetVersion(),
inputQuality inputQuality
); );
@ -159,7 +209,9 @@ describe('installer tests', () => {
maxSatisfyingSpy.mockImplementation(() => inputVersion); maxSatisfyingSpy.mockImplementation(() => inputVersion);
const dotnetInstaller = new installer.DotnetCoreInstaller( const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion, await new installer.DotnetVersionResolver(
inputVersion
).createDotnetVersion(),
inputQuality inputQuality
); );
@ -186,7 +238,9 @@ describe('installer tests', () => {
maxSatisfyingSpy.mockImplementation(() => inputVersion); maxSatisfyingSpy.mockImplementation(() => inputVersion);
const dotnetInstaller = new installer.DotnetCoreInstaller( const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion, await new installer.DotnetVersionResolver(
inputVersion
).createDotnetVersion(),
inputQuality inputQuality
); );
@ -226,7 +280,9 @@ describe('installer tests', () => {
maxSatisfyingSpy.mockImplementation(() => inputVersion); maxSatisfyingSpy.mockImplementation(() => inputVersion);
const dotnetInstaller = new installer.DotnetCoreInstaller( const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion, await new installer.DotnetVersionResolver(
inputVersion
).createDotnetVersion(),
inputQuality inputQuality
); );
@ -267,7 +323,9 @@ describe('installer tests', () => {
maxSatisfyingSpy.mockImplementation(() => inputVersion); maxSatisfyingSpy.mockImplementation(() => inputVersion);
const dotnetInstaller = new installer.DotnetCoreInstaller( const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion, await new installer.DotnetVersionResolver(
inputVersion
).createDotnetVersion(),
inputQuality inputQuality
); );
@ -305,7 +363,9 @@ describe('installer tests', () => {
maxSatisfyingSpy.mockImplementation(() => inputVersion); maxSatisfyingSpy.mockImplementation(() => inputVersion);
const dotnetInstaller = new installer.DotnetCoreInstaller( const dotnetInstaller = new installer.DotnetCoreInstaller(
inputVersion, await new installer.DotnetVersionResolver(
inputVersion
).createDotnetVersion(),
inputQuality inputQuality
); );

View File

@ -9,6 +9,10 @@ inputs:
description: 'Optional SDK version(s) to use. If not provided, will install global.json version when available. Examples: 2.2.104, 3.1, 3.1.x, 3.x, 6.0.2xx' description: 'Optional SDK version(s) to use. If not provided, will install global.json version when available. Examples: 2.2.104, 3.1, 3.1.x, 3.x, 6.0.2xx'
dotnet-quality: dotnet-quality:
description: 'Optional quality of the build. The possible values are: daily, signed, validated, preview, ga.' description: 'Optional quality of the build. The possible values are: daily, signed, validated, preview, ga.'
runtime-only:
description: 'Optional input to install only the runtime, not the SDK.'
required: false
default: false
global-json-file: global-json-file:
description: 'Optional global.json location, if your global.json isn''t located in the root of the repo.' description: 'Optional global.json location, if your global.json isn''t located in the root of the repo.'
source-url: source-url:

20
dist/setup/index.js vendored
View File

@ -73035,14 +73035,13 @@ 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(dotnetVersion, quality, runtimeOnly = false) {
this.version = version; this.dotnetVersion = dotnetVersion;
this.quality = quality; this.quality = quality;
this.runtimeOnly = runtimeOnly;
} }
installDotnet() { installDotnet() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const versionResolver = new DotnetVersionResolver(this.version);
const dotnetVersion = yield versionResolver.createDotnetVersion();
/** /**
* Install dotnet runitme first in order to get * Install dotnet runitme first in order to get
* the latest stable version of dotnet CLI * the latest stable version of dotnet CLI
@ -73066,12 +73065,15 @@ class DotnetCoreInstaller {
* Install dotnet over the latest version of * Install dotnet over the latest version of
* dotnet CLI * dotnet CLI
*/ */
const dotnetInstallOutput = yield new DotnetInstallScript() const dotnetInstallScript = new DotnetInstallScript()
// Don't overwrite CLI because it should be already installed // Don't overwrite CLI because it should be already installed
.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(this.dotnetVersion, this.quality);
.execute(); if (this.runtimeOnly) {
dotnetInstallScript.useArguments(utils_1.IS_WINDOWS ? '-Runtime' : '--runtime', 'dotnet');
}
const dotnetInstallOutput = yield dotnetInstallScript.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}`);
} }
@ -73194,9 +73196,11 @@ function run() {
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;
let dotnetVersionResolver;
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); dotnetVersionResolver = new installer_1.DotnetVersionResolver(version);
dotnetInstaller = new installer_1.DotnetCoreInstaller(yield dotnetVersionResolver.createDotnetVersion(), quality, core.getBooleanInput('runtime-only'));
const installedVersion = yield dotnetInstaller.installDotnet(); const installedVersion = yield dotnetInstaller.installDotnet();
installedDotnetVersions.push(installedVersion); installedDotnetVersions.push(installedVersion);
} }

View File

@ -253,12 +253,13 @@ export class DotnetCoreInstaller {
DotnetInstallDir.setEnvironmentVariable(); DotnetInstallDir.setEnvironmentVariable();
} }
constructor(private version: string, private quality: QualityOptions) {} constructor(
private readonly dotnetVersion: DotnetVersion,
private readonly quality: QualityOptions,
private readonly runtimeOnly = false
) {}
public async installDotnet(): Promise<string | null> { public async installDotnet(): Promise<string | null> {
const versionResolver = new DotnetVersionResolver(this.version);
const dotnetVersion = await versionResolver.createDotnetVersion();
/** /**
* Install dotnet runitme first in order to get * Install dotnet runitme first in order to get
* the latest stable version of dotnet CLI * the latest stable version of dotnet CLI
@ -288,14 +289,22 @@ export class DotnetCoreInstaller {
* Install dotnet over the latest version of * Install dotnet over the latest version of
* dotnet CLI * dotnet CLI
*/ */
const dotnetInstallOutput = await new DotnetInstallScript() const dotnetInstallScript = new DotnetInstallScript()
// Don't overwrite CLI because it should be already installed // Don't overwrite CLI because it should be already installed
.useArguments( .useArguments(
IS_WINDOWS ? '-SkipNonVersionedFiles' : '--skip-non-versioned-files' IS_WINDOWS ? '-SkipNonVersionedFiles' : '--skip-non-versioned-files'
) )
// Use version provided by user // Use version provided by user
.useVersion(dotnetVersion, this.quality) .useVersion(this.dotnetVersion, this.quality);
.execute();
if (this.runtimeOnly) {
dotnetInstallScript.useArguments(
IS_WINDOWS ? '-Runtime' : '--runtime',
'dotnet'
);
}
const dotnetInstallOutput = await dotnetInstallScript.execute();
if (dotnetInstallOutput.exitCode) { if (dotnetInstallOutput.exitCode) {
throw new Error( throw new Error(

View File

@ -1,5 +1,9 @@
import * as core from '@actions/core'; import * as core from '@actions/core';
import {DotnetCoreInstaller, DotnetInstallDir} from './installer'; import {
DotnetCoreInstaller,
DotnetInstallDir,
DotnetVersionResolver
} from './installer';
import * as fs from 'fs'; import * as fs from 'fs';
import path from 'path'; import path from 'path';
import semver from 'semver'; import semver from 'semver';
@ -67,9 +71,16 @@ export async function run() {
} }
let dotnetInstaller: DotnetCoreInstaller; let dotnetInstaller: DotnetCoreInstaller;
let dotnetVersionResolver: DotnetVersionResolver;
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); dotnetVersionResolver = new DotnetVersionResolver(version);
dotnetInstaller = new DotnetCoreInstaller(
await dotnetVersionResolver.createDotnetVersion(),
quality,
core.getBooleanInput('runtime-only')
);
const installedVersion = await dotnetInstaller.installDotnet(); const installedVersion = await dotnetInstaller.installDotnet();
installedDotnetVersions.push(installedVersion); installedDotnetVersions.push(installedVersion);
} }