Pretty printed code
This commit is contained in:
parent
3894eede2d
commit
7b228edf43
|
@ -16,60 +16,59 @@ import * as installer from '../src/installer';
|
||||||
const IS_WINDOWS = process.platform === 'win32';
|
const IS_WINDOWS = process.platform === 'win32';
|
||||||
|
|
||||||
describe('version tests', () => {
|
describe('version tests', () => {
|
||||||
each([
|
each(['3.1.999', '3.1.101-preview']).test(
|
||||||
'3.1.999',
|
"Exact version '%s' should be the same",
|
||||||
'3.1.101-preview'
|
vers => {
|
||||||
]).test("Exact version '%s' should be the same", vers => {
|
|
||||||
let versInfo = new installer.DotNetVersionInfo(vers);
|
let versInfo = new installer.DotNetVersionInfo(vers);
|
||||||
|
|
||||||
expect(versInfo.isExactVersion()).toBe(true);
|
expect(versInfo.isExactVersion()).toBe(true);
|
||||||
expect(versInfo.version()).toBe(vers);
|
expect(versInfo.version()).toBe(vers);
|
||||||
})
|
}
|
||||||
|
);
|
||||||
|
|
||||||
each([
|
each([['3.1.x', '3.1'], ['1.1.*', '1.1'], ['2.0', '2.0']]).test(
|
||||||
['3.1.x', '3.1'],
|
"Generic version '%s' should be '%s'",
|
||||||
['1.1.*', '1.1'],
|
(vers, resVers) => {
|
||||||
['2.0', '2.0']
|
|
||||||
]).test("Generic version '%s' should be '%s'", (vers, resVers) => {
|
|
||||||
let versInfo = new installer.DotNetVersionInfo(vers);
|
let versInfo = new installer.DotNetVersionInfo(vers);
|
||||||
|
|
||||||
expect(versInfo.isExactVersion()).toBe(false);
|
expect(versInfo.isExactVersion()).toBe(false);
|
||||||
expect(versInfo.version()).toBe(resVers);
|
expect(versInfo.version()).toBe(resVers);
|
||||||
})
|
}
|
||||||
|
);
|
||||||
|
|
||||||
each([
|
each([
|
||||||
"",
|
'',
|
||||||
".",
|
'.',
|
||||||
"..",
|
'..',
|
||||||
" . ",
|
' . ',
|
||||||
". ",
|
'. ',
|
||||||
" .",
|
' .',
|
||||||
" . . ",
|
' . . ',
|
||||||
" .. ",
|
' .. ',
|
||||||
" . ",
|
' . ',
|
||||||
"-1.-1",
|
'-1.-1',
|
||||||
"-1",
|
'-1',
|
||||||
"-1.-1.-1",
|
'-1.-1.-1',
|
||||||
"..3",
|
'..3',
|
||||||
"1..3",
|
'1..3',
|
||||||
"1..",
|
'1..',
|
||||||
".2.3",
|
'.2.3',
|
||||||
".2.x",
|
'.2.x',
|
||||||
"1",
|
'1',
|
||||||
"2.x",
|
'2.x',
|
||||||
"*.*.1",
|
'*.*.1',
|
||||||
"*.1",
|
'*.1',
|
||||||
"*.",
|
'*.',
|
||||||
"1.2.",
|
'1.2.',
|
||||||
"1.2.-abc",
|
'1.2.-abc',
|
||||||
"a.b",
|
'a.b',
|
||||||
"a.b.c",
|
'a.b.c',
|
||||||
"a.b.c-preview",
|
'a.b.c-preview',
|
||||||
" 0 . 1 . 2 ",
|
' 0 . 1 . 2 '
|
||||||
]).test("Malformed version '%s' should throw", vers => {
|
]).test("Malformed version '%s' should throw", vers => {
|
||||||
expect(() => new installer.DotNetVersionInfo(vers)).toThrow();
|
expect(() => new installer.DotNetVersionInfo(vers)).toThrow();
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
describe('installer tests', () => {
|
describe('installer tests', () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
|
@ -88,7 +87,10 @@ describe('installer tests', () => {
|
||||||
|
|
||||||
it('Resolving a normal generic version works', async () => {
|
it('Resolving a normal generic version works', async () => {
|
||||||
const dotnetInstaller = new installer.DotnetCoreInstaller('3.1.x');
|
const dotnetInstaller = new installer.DotnetCoreInstaller('3.1.x');
|
||||||
let versInfo = await dotnetInstaller.resolveInfos(["win-x64"],new installer.DotNetVersionInfo('3.1.x'));
|
let versInfo = await dotnetInstaller.resolveInfos(
|
||||||
|
['win-x64'],
|
||||||
|
new installer.DotNetVersionInfo('3.1.x')
|
||||||
|
);
|
||||||
|
|
||||||
expect(versInfo.resolvedVersion.startsWith('3.1.'));
|
expect(versInfo.resolvedVersion.startsWith('3.1.'));
|
||||||
}, 100000);
|
}, 100000);
|
||||||
|
@ -96,7 +98,10 @@ describe('installer tests', () => {
|
||||||
it('Resolving a nonexistent generic version fails', async () => {
|
it('Resolving a nonexistent generic version fails', async () => {
|
||||||
const dotnetInstaller = new installer.DotnetCoreInstaller('999.1.x');
|
const dotnetInstaller = new installer.DotnetCoreInstaller('999.1.x');
|
||||||
try {
|
try {
|
||||||
await dotnetInstaller.resolveInfos(["win-x64"],new installer.DotNetVersionInfo('999.1.x'));
|
await dotnetInstaller.resolveInfos(
|
||||||
|
['win-x64'],
|
||||||
|
new installer.DotNetVersionInfo('999.1.x')
|
||||||
|
);
|
||||||
fail();
|
fail();
|
||||||
} catch {
|
} catch {
|
||||||
expect(true);
|
expect(true);
|
||||||
|
@ -105,7 +110,10 @@ describe('installer tests', () => {
|
||||||
|
|
||||||
it('Resolving a exact version works', async () => {
|
it('Resolving a exact version works', async () => {
|
||||||
const dotnetInstaller = new installer.DotnetCoreInstaller('3.1.201');
|
const dotnetInstaller = new installer.DotnetCoreInstaller('3.1.201');
|
||||||
let versInfo = await dotnetInstaller.resolveInfos(["win-x64"],new installer.DotNetVersionInfo('3.1.201'));
|
let versInfo = await dotnetInstaller.resolveInfos(
|
||||||
|
['win-x64'],
|
||||||
|
new installer.DotNetVersionInfo('3.1.201')
|
||||||
|
);
|
||||||
|
|
||||||
expect(versInfo.resolvedVersion).toBe('3.1.201');
|
expect(versInfo.resolvedVersion).toBe('3.1.201');
|
||||||
}, 100000);
|
}, 100000);
|
||||||
|
|
|
@ -31,12 +31,10 @@ if (!tempDirectory) {
|
||||||
* Represents the inputted version information
|
* Represents the inputted version information
|
||||||
*/
|
*/
|
||||||
export class DotNetVersionInfo {
|
export class DotNetVersionInfo {
|
||||||
|
|
||||||
private fullversion: string;
|
private fullversion: string;
|
||||||
private isExactVersionSet: boolean = false;
|
private isExactVersionSet: boolean = false;
|
||||||
|
|
||||||
constructor(version: string) {
|
constructor(version: string) {
|
||||||
|
|
||||||
// Check for exact match
|
// Check for exact match
|
||||||
if (semver.valid(semver.clean(version) || '') != null) {
|
if (semver.valid(semver.clean(version) || '') != null) {
|
||||||
this.fullversion = semver.clean(version) as string;
|
this.fullversion = semver.clean(version) as string;
|
||||||
|
@ -48,10 +46,9 @@ export class DotNetVersionInfo {
|
||||||
//Note: No support for previews when using generic
|
//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)
|
if (parts.length < 2 || parts.length > 3) this.throwInvalidVersionFormat();
|
||||||
this.throwInvalidVersionFormat();
|
|
||||||
|
|
||||||
if(parts.length == 3 && parts[2] !== "x" && parts[2] !== "*") {
|
if (parts.length == 3 && parts[2] !== 'x' && parts[2] !== '*') {
|
||||||
this.throwInvalidVersionFormat();
|
this.throwInvalidVersionFormat();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,15 +59,12 @@ export class DotNetVersionInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
private getVersionNumberOrThrow(input: string): number {
|
private getVersionNumberOrThrow(input: string): number {
|
||||||
try
|
try {
|
||||||
{
|
if (!input || input.trim() === '') this.throwInvalidVersionFormat();
|
||||||
if(!input || input.trim() === "")
|
|
||||||
this.throwInvalidVersionFormat();
|
|
||||||
|
|
||||||
let number = Number(input);
|
let number = Number(input);
|
||||||
|
|
||||||
if(Number.isNaN(number) || number < 0)
|
if (Number.isNaN(number) || number < 0) this.throwInvalidVersionFormat();
|
||||||
this.throwInvalidVersionFormat();
|
|
||||||
|
|
||||||
return number;
|
return number;
|
||||||
} catch {
|
} catch {
|
||||||
|
@ -80,7 +74,7 @@ export class DotNetVersionInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
private throwInvalidVersionFormat() {
|
private throwInvalidVersionFormat() {
|
||||||
throw 'Invalid version format! Supported: 1.2.3, 1.2, 1.2.x, 1.2.*'
|
throw 'Invalid version format! Supported: 1.2.3, 1.2, 1.2.x, 1.2.*';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -125,7 +119,7 @@ export class DotnetCoreInstaller {
|
||||||
|
|
||||||
public async installDotnet() {
|
public async installDotnet() {
|
||||||
// Check cache
|
// Check cache
|
||||||
let toolPath: string = "";
|
let toolPath: string = '';
|
||||||
let osSuffixes = await this.detectMachineOS();
|
let osSuffixes = await this.detectMachineOS();
|
||||||
let parts = osSuffixes[0].split('-');
|
let parts = osSuffixes[0].split('-');
|
||||||
if (parts.length > 1) {
|
if (parts.length > 1) {
|
||||||
|
@ -139,7 +133,10 @@ export class DotnetCoreInstaller {
|
||||||
if (!toolPath) {
|
if (!toolPath) {
|
||||||
// download, extract, cache
|
// download, extract, cache
|
||||||
console.log('Getting a download url', this.versionInfo.version());
|
console.log('Getting a download url', this.versionInfo.version());
|
||||||
let resolvedVersionInfo = await this.resolveInfos(osSuffixes, this.versionInfo);
|
let resolvedVersionInfo = await this.resolveInfos(
|
||||||
|
osSuffixes,
|
||||||
|
this.versionInfo
|
||||||
|
);
|
||||||
|
|
||||||
//Check if cache exists for resolved version
|
//Check if cache exists for resolved version
|
||||||
toolPath = this.getLocalTool(resolvedVersionInfo.resolvedVersion);
|
toolPath = this.getLocalTool(resolvedVersionInfo.resolvedVersion);
|
||||||
|
@ -281,7 +278,6 @@ export class DotnetCoreInstaller {
|
||||||
osSuffixes: string[],
|
osSuffixes: string[],
|
||||||
versionInfo: DotNetVersionInfo
|
versionInfo: DotNetVersionInfo
|
||||||
): Promise<ResolvedVersionInfo> {
|
): Promise<ResolvedVersionInfo> {
|
||||||
|
|
||||||
const httpClient = new hc.HttpClient('actions/setup-dotnet', [], {
|
const httpClient = new hc.HttpClient('actions/setup-dotnet', [], {
|
||||||
allowRetries: true,
|
allowRetries: true,
|
||||||
maxRetries: 3
|
maxRetries: 3
|
||||||
|
@ -297,8 +293,14 @@ 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(releaseInfo['sdk']['version'], versionInfo.version()) ||
|
semver.satisfies(
|
||||||
semver.satisfies(releaseInfo['sdk']['version-display'], versionInfo.version())
|
releaseInfo['sdk']['version'],
|
||||||
|
versionInfo.version()
|
||||||
|
) ||
|
||||||
|
semver.satisfies(
|
||||||
|
releaseInfo['sdk']['version-display'],
|
||||||
|
versionInfo.version()
|
||||||
|
)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -306,11 +308,15 @@ export class DotnetCoreInstaller {
|
||||||
if (!versionInfo.isExactVersion()) {
|
if (!versionInfo.isExactVersion()) {
|
||||||
let latestSdk: string = releasesResult['latest-sdk'];
|
let latestSdk: string = releasesResult['latest-sdk'];
|
||||||
|
|
||||||
releasesInfo = releasesInfo.filter((releaseInfo: any) => semver.lte(releaseInfo['sdk']['version'], latestSdk));
|
releasesInfo = releasesInfo.filter((releaseInfo: any) =>
|
||||||
|
semver.lte(releaseInfo['sdk']['version'], latestSdk)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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'])
|
||||||
|
);
|
||||||
|
|
||||||
let downloadedVersion: string = '';
|
let downloadedVersion: string = '';
|
||||||
let downloadUrls: string[] = [];
|
let downloadUrls: string[] = [];
|
||||||
|
@ -344,7 +350,9 @@ export class DotnetCoreInstaller {
|
||||||
if (versionInfo.isExactVersion()) {
|
if (versionInfo.isExactVersion()) {
|
||||||
console.log('Using fallback');
|
console.log('Using fallback');
|
||||||
|
|
||||||
downloadUrls = await this.getFallbackDownloadUrls(versionInfo.version());
|
downloadUrls = await this.getFallbackDownloadUrls(
|
||||||
|
versionInfo.version()
|
||||||
|
);
|
||||||
downloadedVersion = versionInfo.version();
|
downloadedVersion = versionInfo.version();
|
||||||
} else {
|
} else {
|
||||||
console.log('Unable to use fallback, version is generic!');
|
console.log('Unable to use fallback, version is generic!');
|
||||||
|
|
Loading…
Reference in New Issue