Remove hard dependency from installer

This commit is contained in:
Nikolai Laevskii 2023-09-08 15:21:18 +02:00
parent 3edc8ffab8
commit fd2f9a08fe
5 changed files with 245 additions and 235 deletions

View File

@ -51,7 +51,7 @@ 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 +73,7 @@ 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 +96,7 @@ 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
); );
@ -133,7 +133,7 @@ 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 +159,7 @@ 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 +186,7 @@ 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 +226,7 @@ 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 +267,7 @@ 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 +305,7 @@ 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
); );

12
dist/setup/index.js vendored
View File

@ -72993,14 +72993,12 @@ 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) {
this.version = version; this.dotnetVersion = dotnetVersion;
this.quality = quality; this.quality = quality;
} }
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
@ -73028,7 +73026,7 @@ class DotnetCoreInstaller {
// 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(); .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}`);
@ -73152,9 +73150,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);
const installedVersion = yield dotnetInstaller.installDotnet(); const installedVersion = yield dotnetInstaller.installDotnet();
installedDotnetVersions.push(installedVersion); installedDotnetVersions.push(installedVersion);
} }

View File

@ -253,12 +253,12 @@ export class DotnetCoreInstaller {
DotnetInstallDir.setEnvironmentVariable(); DotnetInstallDir.setEnvironmentVariable();
} }
constructor(private version: string, private quality: QualityOptions) {} constructor(
private readonly dotnetVersion: DotnetVersion,
private readonly quality: QualityOptions
) {}
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
@ -294,7 +294,7 @@ export class DotnetCoreInstaller {
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(); .execute();
if (dotnetInstallOutput.exitCode) { if (dotnetInstallOutput.exitCode) {

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,15 @@ 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
);
const installedVersion = await dotnetInstaller.installDotnet(); const installedVersion = await dotnetInstaller.installDotnet();
installedDotnetVersions.push(installedVersion); installedDotnetVersions.push(installedVersion);
} }