From 768b4eb7db215baebe4cbdb1e72ad73c00206679 Mon Sep 17 00:00:00 2001 From: GGG KILLER Date: Thu, 16 Jul 2020 19:23:46 -0300 Subject: [PATCH] Implement passing includePrerelase to semver --- dist/index.js | 24 +++++++++++++++++------- src/installer.ts | 25 ++++++++++++++++--------- src/setup-dotnet.ts | 9 ++++++++- 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/dist/index.js b/dist/index.js index 15f8a3b..e51206f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -7821,7 +7821,9 @@ function run() { } } if (version) { - const dotnetInstaller = new installer.DotnetCoreInstaller(version); + const includePrerelease = (core.getInput('include-prerelease') || 'false').toLowerCase() === + 'true'; + const dotnetInstaller = new installer.DotnetCoreInstaller(version, includePrerelease); yield dotnetInstaller.installDotnet(); } const sourceUrl = core.getInput('source-url'); @@ -16868,7 +16870,6 @@ class DotNetVersionInfo { this.isExactVersionSet = true; return; } - //Note: No support for previews when using generic let parts = version.split('.'); if (parts.length < 2 || parts.length > 3) this.throwInvalidVersionFormat(); @@ -16908,8 +16909,9 @@ class DotNetVersionInfo { } exports.DotNetVersionInfo = DotNetVersionInfo; class DotnetCoreInstaller { - constructor(version) { + constructor(version, includePrerelease = false) { this.version = version; + this.includePrerelease = includePrerelease; } installDotnet() { return __awaiter(this, void 0, void 0, function* () { @@ -17016,14 +17018,22 @@ class DotnetCoreInstaller { const releasesResult = releasesResponse.result || {}; let releasesInfo = releasesResult['releases']; releasesInfo = releasesInfo.filter((releaseInfo) => { - return (semver.satisfies(releaseInfo['sdk']['version'], versionInfo.version()) || - semver.satisfies(releaseInfo['sdk']['version-display'], versionInfo.version())); + return (semver.satisfies(releaseInfo['sdk']['version'], versionInfo.version(), { + includePrerelease: this.includePrerelease + }) || + semver.satisfies(releaseInfo['sdk']['version-display'], versionInfo.version(), { + includePrerelease: this.includePrerelease + })); }); // Exclude versions that are newer than the latest if using not exact let latestSdk = releasesResult['latest-sdk']; - releasesInfo = releasesInfo.filter((releaseInfo) => semver.lte(releaseInfo['sdk']['version'], latestSdk)); + releasesInfo = releasesInfo.filter((releaseInfo) => semver.lte(releaseInfo['sdk']['version'], latestSdk, { + includePrerelease: this.includePrerelease + })); // Sort for latest version - releasesInfo = releasesInfo.sort((a, b) => semver.rcompare(a['sdk']['version'], b['sdk']['version'])); + releasesInfo = releasesInfo.sort((a, b) => semver.rcompare(a['sdk']['version'], b['sdk']['version'], { + includePrerelease: this.includePrerelease + })); if (releasesInfo.length == 0) { throw `Could not find dotnet core version. Please ensure that specified version ${versionInfo.inputVersion} is valid.`; } diff --git a/src/installer.ts b/src/installer.ts index f0b48a2..d36a24e 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -29,7 +29,6 @@ export class DotNetVersionInfo { return; } - //Note: No support for previews when using generic let parts: string[] = version.split('.'); if (parts.length < 2 || parts.length > 3) this.throwInvalidVersionFormat(); @@ -76,8 +75,9 @@ export class DotNetVersionInfo { } export class DotnetCoreInstaller { - constructor(version: string) { + constructor(version: string, includePrerelease: boolean = false) { this.version = version; + this.includePrerelease = includePrerelease; } public async installDotnet() { @@ -212,13 +212,15 @@ export class DotnetCoreInstaller { let releasesInfo: any[] = releasesResult['releases']; releasesInfo = releasesInfo.filter((releaseInfo: any) => { return ( - semver.satisfies( - releaseInfo['sdk']['version'], - versionInfo.version() - ) || + semver.satisfies(releaseInfo['sdk']['version'], versionInfo.version(), { + includePrerelease: this.includePrerelease + }) || semver.satisfies( releaseInfo['sdk']['version-display'], - versionInfo.version() + versionInfo.version(), + { + includePrerelease: this.includePrerelease + } ) ); }); @@ -227,12 +229,16 @@ export class DotnetCoreInstaller { let latestSdk: string = releasesResult['latest-sdk']; releasesInfo = releasesInfo.filter((releaseInfo: any) => - semver.lte(releaseInfo['sdk']['version'], latestSdk) + semver.lte(releaseInfo['sdk']['version'], latestSdk, { + includePrerelease: this.includePrerelease + }) ); // Sort for latest version releasesInfo = releasesInfo.sort((a, b) => - semver.rcompare(a['sdk']['version'], b['sdk']['version']) + semver.rcompare(a['sdk']['version'], b['sdk']['version'], { + includePrerelease: this.includePrerelease + }) ); if (releasesInfo.length == 0) { @@ -273,6 +279,7 @@ export class DotnetCoreInstaller { } private version: string; + private includePrerelease: boolean; } const DotNetCoreIndexUrl: string = diff --git a/src/setup-dotnet.ts b/src/setup-dotnet.ts index ec804eb..51ace99 100644 --- a/src/setup-dotnet.ts +++ b/src/setup-dotnet.ts @@ -29,7 +29,14 @@ export async function run() { } if (version) { - const dotnetInstaller = new installer.DotnetCoreInstaller(version); + const includePrerelease: boolean = + (core.getInput('include-prerelease') || 'false').toLowerCase() === + 'true'; + + const dotnetInstaller = new installer.DotnetCoreInstaller( + version, + includePrerelease + ); await dotnetInstaller.installDotnet(); }