From c5ee7a11347f49e1cfc6eaa7dd656f660ca0ea19 Mon Sep 17 00:00:00 2001 From: litetex Date: Thu, 9 Apr 2020 19:26:10 +0200 Subject: [PATCH] Cleanup * Doc * Refactored and removed some stuff --- __tests__/installer.test.ts | 3 ++- src/installer.ts | 34 ++++++++++------------------------ 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index ff9604c..3e933ba 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -3,6 +3,7 @@ import fs = require('fs'); import os = require('os'); import path = require('path'); import hc = require('@actions/http-client'); + import each from 'jest-each'; const toolDir = path.join(__dirname, 'runner', 'tools'); @@ -119,7 +120,7 @@ describe('installer tests', () => { } else { expect(fs.existsSync(path.join(dotnetDir, 'dotnet'))).toBe(true); } - }, 400000); + }, 400000); //This needs some time to download on "slower" internet connections it('Throws if no location contains correct dotnet version', async () => { let thrown = false; diff --git a/src/installer.ts b/src/installer.ts index 36cea8c..d8cf0bd 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -29,27 +29,21 @@ if (!tempDirectory) { tempDirectory = path.join(baseLocation, 'actions', 'temp'); } +/** + * Represents the inputted version information + */ export class DotNetVersionInfo { private fullversion : string; private isExactVersionSet: boolean = false; - private major: number; - private minor: number; - private patch?: number; - constructor(version: string) { // Check for exact match if(semver.valid(semver.clean(version) || '') != null) { - this.fullversion = semver.clean(version) as string; this.isExactVersionSet = true; - this.major = semver.major(this.fullversion); - this.minor = semver.minor(this.fullversion); - this.patch = semver.patch(this.fullversion); - return; } @@ -63,21 +57,10 @@ export class DotNetVersionInfo { this.throwInvalidVersionFormat(); } - this.major = this.getVersionNumberOrThrow(parts[0]); - this.minor = this.getVersionNumberOrThrow(parts[1]); + let major = this.getVersionNumberOrThrow(parts[0]); + let minor = this.getVersionNumberOrThrow(parts[1]); - /* - let regexResult = version.match(/^(\d+\.)(\d+)?(\.\*|\.x|)$/); - if(regexResult == null) { - throw 'Invalid version format! Supported: 1.2.3, 1.2, 1.2.x, 1.2.*'; - } - - let parts : string[] = (regexResult as RegExpMatchArray).slice(1); - - this.major = +(parts[0].replace('.','')); - this.minor = +(parts[1].replace('.',''));*/ - - this.fullversion = this.major + '.' + this.minor; + this.fullversion = major + '.' + minor; } private getVersionNumberOrThrow(input: string) : number { @@ -114,6 +97,9 @@ export class DotNetVersionInfo { } } +/** + * Represents a resolved version from the Web-Api + */ class ResolvedVersionInfo { downloadUrls: string[]; resolvedVersion: string; @@ -292,7 +278,7 @@ export class DotnetCoreInstaller { // OsSuffixes - The suffix which is a part of the file name ex- linux-x64, windows-x86 // Type - SDK / Runtime - // Version - Version of the SDK/Runtime + // versionInfo - versionInfo of the SDK/Runtime async resolveInfos( osSuffixes: string[], versionInfo: DotNetVersionInfo