Implement passing includePrerelase to semver

This commit is contained in:
GGG KILLER 2020-07-16 19:23:46 -03:00
parent ba7e1e2155
commit 768b4eb7db
3 changed files with 41 additions and 17 deletions

24
dist/index.js vendored
View File

@ -7821,7 +7821,9 @@ function run() {
} }
} }
if (version) { 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(); yield dotnetInstaller.installDotnet();
} }
const sourceUrl = core.getInput('source-url'); const sourceUrl = core.getInput('source-url');
@ -16868,7 +16870,6 @@ class DotNetVersionInfo {
this.isExactVersionSet = true; this.isExactVersionSet = true;
return; return;
} }
//Note: No support for previews when using generic
let parts = version.split('.'); let parts = version.split('.');
if (parts.length < 2 || parts.length > 3) if (parts.length < 2 || parts.length > 3)
this.throwInvalidVersionFormat(); this.throwInvalidVersionFormat();
@ -16908,8 +16909,9 @@ class DotNetVersionInfo {
} }
exports.DotNetVersionInfo = DotNetVersionInfo; exports.DotNetVersionInfo = DotNetVersionInfo;
class DotnetCoreInstaller { class DotnetCoreInstaller {
constructor(version) { constructor(version, includePrerelease = false) {
this.version = version; this.version = version;
this.includePrerelease = includePrerelease;
} }
installDotnet() { installDotnet() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
@ -17016,14 +17018,22 @@ class DotnetCoreInstaller {
const releasesResult = releasesResponse.result || {}; const releasesResult = releasesResponse.result || {};
let releasesInfo = releasesResult['releases']; let releasesInfo = releasesResult['releases'];
releasesInfo = releasesInfo.filter((releaseInfo) => { releasesInfo = releasesInfo.filter((releaseInfo) => {
return (semver.satisfies(releaseInfo['sdk']['version'], versionInfo.version()) || return (semver.satisfies(releaseInfo['sdk']['version'], versionInfo.version(), {
semver.satisfies(releaseInfo['sdk']['version-display'], 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 // Exclude versions that are newer than the latest if using not exact
let latestSdk = releasesResult['latest-sdk']; 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 // 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) { if (releasesInfo.length == 0) {
throw `Could not find dotnet core version. Please ensure that specified version ${versionInfo.inputVersion} is valid.`; throw `Could not find dotnet core version. Please ensure that specified version ${versionInfo.inputVersion} is valid.`;
} }

View File

@ -29,7 +29,6 @@ export class DotNetVersionInfo {
return; return;
} }
//Note: No support for previews when using generic
let parts: string[] = version.split('.'); let parts: string[] = version.split('.');
if (parts.length < 2 || parts.length > 3) this.throwInvalidVersionFormat(); if (parts.length < 2 || parts.length > 3) this.throwInvalidVersionFormat();
@ -76,8 +75,9 @@ export class DotNetVersionInfo {
} }
export class DotnetCoreInstaller { export class DotnetCoreInstaller {
constructor(version: string) { constructor(version: string, includePrerelease: boolean = false) {
this.version = version; this.version = version;
this.includePrerelease = includePrerelease;
} }
public async installDotnet() { public async installDotnet() {
@ -212,13 +212,15 @@ export class DotnetCoreInstaller {
let releasesInfo: any[] = releasesResult['releases']; let releasesInfo: any[] = releasesResult['releases'];
releasesInfo = releasesInfo.filter((releaseInfo: any) => { releasesInfo = releasesInfo.filter((releaseInfo: any) => {
return ( return (
semver.satisfies( semver.satisfies(releaseInfo['sdk']['version'], versionInfo.version(), {
releaseInfo['sdk']['version'], includePrerelease: this.includePrerelease
versionInfo.version() }) ||
) ||
semver.satisfies( semver.satisfies(
releaseInfo['sdk']['version-display'], releaseInfo['sdk']['version-display'],
versionInfo.version() versionInfo.version(),
{
includePrerelease: this.includePrerelease
}
) )
); );
}); });
@ -227,12 +229,16 @@ export class DotnetCoreInstaller {
let latestSdk: string = releasesResult['latest-sdk']; let latestSdk: string = releasesResult['latest-sdk'];
releasesInfo = releasesInfo.filter((releaseInfo: any) => releasesInfo = releasesInfo.filter((releaseInfo: any) =>
semver.lte(releaseInfo['sdk']['version'], latestSdk) semver.lte(releaseInfo['sdk']['version'], latestSdk, {
includePrerelease: this.includePrerelease
})
); );
// Sort for latest version // Sort for latest version
releasesInfo = releasesInfo.sort((a, b) => 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) { if (releasesInfo.length == 0) {
@ -273,6 +279,7 @@ export class DotnetCoreInstaller {
} }
private version: string; private version: string;
private includePrerelease: boolean;
} }
const DotNetCoreIndexUrl: string = const DotNetCoreIndexUrl: string =

View File

@ -29,7 +29,14 @@ export async function run() {
} }
if (version) { 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(); await dotnetInstaller.installDotnet();
} }