Merge pull request #110 from GGG-KILLER/feature/include-prerelease

Include include-prerelease option to be able to match latest prerelease versions
This commit is contained in:
Maxim Lobanov 2021-05-05 15:53:38 +03:00 committed by GitHub
commit 7b2009794e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 17 deletions

View File

@ -13,6 +13,9 @@ inputs:
description: 'Optional OWNER for using packages from GitHub Package Registry organizations/users other than the current repository''s owner. Only used if a GPR URL is also provided in source-url'
config-file:
description: 'Optional NuGet.config location, if your NuGet.config isn''t located in the root of the repo.'
include-prerelease:
description: 'Whether prerelease versions should be matched with non-exact versions (for example 5.0.0-preview.6 being matched by 5, 5.0, 5.x or 5.0.x). Defaults to false if not provided.'
required: False
runs:
using: 'node12'
main: 'dist/index.js'

24
dist/index.js vendored
View File

@ -7838,7 +7838,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');
@ -16885,7 +16887,6 @@ class DotNetVersionInfo {
this.isExactVersionSet = true;
return;
}
//Note: No support for previews when using generic
const parts = version.split('.');
if (parts.length < 2 || parts.length > 3)
this.throwInvalidVersionFormat();
@ -16927,8 +16928,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* () {
@ -17035,14 +17037,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 new Error(`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;
}
//Note: No support for previews when using generic
const parts: string[] = version.split('.');
if (parts.length < 2 || parts.length > 3) this.throwInvalidVersionFormat();
@ -80,8 +79,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() {
@ -216,13 +216,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
}
)
);
});
@ -231,12 +233,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) {
@ -281,6 +287,7 @@ export class DotnetCoreInstaller {
}
private version: string;
private includePrerelease: boolean;
}
const DotNetCoreIndexUrl: string =

View File

@ -30,7 +30,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();
}