Implement passing includePrerelase to semver
This commit is contained in:
parent
ba7e1e2155
commit
768b4eb7db
|
@ -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.`;
|
||||
}
|
||||
|
|
|
@ -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 =
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue