From fe51dba85839d8477f9ebc8125af63693a080a65 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Wed, 17 Aug 2022 11:02:09 +0200 Subject: [PATCH] Fix review points --- dist/index.js | 40 +++++++++++++++------------------- src/installer.ts | 56 +++++++++++++++++++++++++----------------------- 2 files changed, 46 insertions(+), 50 deletions(-) diff --git a/dist/index.js b/dist/index.js index bfd0e7d..35f612a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -182,7 +182,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.DotnetCoreInstaller = exports.DotnetVersionResolver = exports.DotnetQualityValidator = void 0; +exports.logWarning = exports.DotnetCoreInstaller = exports.DotnetVersionResolver = exports.DotnetQualityValidator = void 0; // Load tempDirectory before it gets wiped by tool-cache const core = __importStar(__nccwpck_require__(2186)); const exec = __importStar(__nccwpck_require__(1514)); @@ -215,7 +215,7 @@ class DotnetVersionResolver { const ValidatingRegEx = /^\d+.\d+/i; const ReplacingRegEx = /^(\d+.\d+).[x/*]$/i; if (!ValidatingRegEx.test(this.inputVersion)) { - throw new Error(`dotnet-version was supplied in invalid format: ${this.inputVersion}! Supported: A.B.C, A.B.C-D, A.B, A.B.x, A.B.X, A.B.*`); + throw new Error(`'dotnet-version' was supplied in invalid format: ${this.inputVersion}! Supported syntax: A.B.C, A.B.C-D, A.B, A.B.x, A.B.X, A.B.*`); } if (semver_1.default.valid(this.inputVersion)) { this.resolvedArgument.type = 'version'; @@ -224,31 +224,20 @@ class DotnetVersionResolver { else { this.resolvedArgument.type = 'channel'; this.resolvedArgument.qualityFlag = true; - if (ReplacingRegEx.test(this.inputVersion)) { - this.resolvedArgument.value = (_a = this.inputVersion.match(ReplacingRegEx)) === null || _a === void 0 ? void 0 : _a[1]; - } - else { - this.resolvedArgument.value = this.inputVersion; - } + this.resolvedArgument.value = ReplacingRegEx.test(this.inputVersion) + ? (_a = this.inputVersion.match(ReplacingRegEx)) === null || _a === void 0 ? void 0 : _a[1] + : this.inputVersion; } } createVersionObject() { this.resolveVersionInput(); if (IS_WINDOWS) { - if (this.resolvedArgument.type === 'channel') { - this.resolvedArgument.type = '-Channel'; - } - else { - this.resolvedArgument.type = '-Version'; - } + this.resolvedArgument.type = + this.resolvedArgument.type === 'channel' ? '-Channel' : '-Version'; } else { - if (this.resolvedArgument.type === 'channel') { - this.resolvedArgument.type = '--channel'; - } - else { - this.resolvedArgument.type = '--version'; - } + this.resolvedArgument.type = + this.resolvedArgument.type === 'channel' ? '--channel' : '--version'; } return this.resolvedArgument; } @@ -285,7 +274,7 @@ class DotnetCoreInstaller { command += ` -Quality ${this.quality}`; } else { - core.warning(`'dotnet-quality' input can't be used with exact version: ${versionObject.value} of .NET. 'dotnet-quality' input is ignored.`); + logWarning(`'dotnet-quality' input can't be used with exact version: ${versionObject.value} of .NET. 'dotnet-quality' input is ignored.`); } } if (process.env['https_proxy'] != null) { @@ -327,10 +316,10 @@ class DotnetCoreInstaller { scriptArguments.push(versionObject.type, versionObject.value); if (this.quality) { if (versionObject.qualityFlag) { - scriptArguments.push("--quality", this.quality); + scriptArguments.push('--quality', this.quality); } else { - core.warning(`'dotnet-quality' input can't be used with exact version: ${versionObject.value} of .NET. 'dotnet-quality' input is ignored.`); + logWarning(`'dotnet-quality' input can't be used with exact version: ${versionObject.value} of .NET. 'dotnet-quality' input is ignored.`); } } if (IS_LINUX) { @@ -372,6 +361,11 @@ class DotnetCoreInstaller { } } exports.DotnetCoreInstaller = DotnetCoreInstaller; +function logWarning(message) { + const warningPrefix = '[warning]'; + core.info(`${warningPrefix}${message}`); +} +exports.logWarning = logWarning; /***/ }), diff --git a/src/installer.ts b/src/installer.ts index b0875c3..889cda6 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -7,7 +7,6 @@ import {chmodSync} from 'fs'; import * as path from 'path'; import semver from 'semver'; import {ExecOptions} from '@actions/exec/lib/interfaces'; -import {timingSafeEqual} from 'crypto'; const IS_WINDOWS = process.platform === 'win32'; const IS_LINUX = process.platform === 'linux'; @@ -33,7 +32,7 @@ export class DotnetQualityValidator { export class DotnetVersionResolver { private inputVersion: string; - private resolvedArgument: {type: string; value: string, qualityFlag: boolean}; + private resolvedArgument: {type: string; value: string; qualityFlag: boolean}; constructor(version: string) { this.inputVersion = version.trim(); @@ -45,7 +44,7 @@ export class DotnetVersionResolver { const ReplacingRegEx = /^(\d+.\d+).[x/*]$/i; if (!ValidatingRegEx.test(this.inputVersion)) { throw new Error( - `dotnet-version was supplied in invalid format: ${this.inputVersion}! Supported: A.B.C, A.B.C-D, A.B, A.B.x, A.B.X, A.B.*` + `'dotnet-version' was supplied in invalid format: ${this.inputVersion}! Supported syntax: A.B.C, A.B.C-D, A.B, A.B.x, A.B.X, A.B.*` ); } if (semver.valid(this.inputVersion)) { @@ -54,30 +53,24 @@ export class DotnetVersionResolver { } else { this.resolvedArgument.type = 'channel'; this.resolvedArgument.qualityFlag = true; - if (ReplacingRegEx.test(this.inputVersion)) { - this.resolvedArgument.value = this.inputVersion.match( - ReplacingRegEx - )?.[1]!; - } else { - this.resolvedArgument.value = this.inputVersion; - } + this.resolvedArgument.value = ReplacingRegEx.test(this.inputVersion) + ? this.inputVersion.match(ReplacingRegEx)?.[1]! + : this.inputVersion; } } - public createVersionObject(): {type: string; value: string, qualityFlag: boolean} { + public createVersionObject(): { + type: string; + value: string; + qualityFlag: boolean; + } { this.resolveVersionInput(); if (IS_WINDOWS) { - if (this.resolvedArgument.type === 'channel') { - this.resolvedArgument.type = '-Channel'; - } else { - this.resolvedArgument.type = '-Version'; - } + this.resolvedArgument.type = + this.resolvedArgument.type === 'channel' ? '-Channel' : '-Version'; } else { - if (this.resolvedArgument.type === 'channel') { - this.resolvedArgument.type = '--channel'; - } else { - this.resolvedArgument.type = '--version'; - } + this.resolvedArgument.type = + this.resolvedArgument.type === 'channel' ? '--channel' : '--version'; } return this.resolvedArgument; } @@ -120,10 +113,12 @@ export class DotnetCoreInstaller { if (versionObject.qualityFlag) { command += ` -Quality ${this.quality}`; } else { - core.warning(`'dotnet-quality' input can't be used with exact version: ${versionObject.value} of .NET. 'dotnet-quality' input is ignored.`); + logWarning( + `'dotnet-quality' input can't be used with exact version: ${versionObject.value} of .NET. 'dotnet-quality' input is ignored.` + ); } } - + if (process.env['https_proxy'] != null) { command += ` -ProxyAddress ${process.env['https_proxy']}`; } @@ -173,13 +168,15 @@ export class DotnetCoreInstaller { scriptArguments.push(versionObject.type, versionObject.value); if (this.quality) { - if (versionObject.qualityFlag){ - scriptArguments.push("--quality", this.quality); + if (versionObject.qualityFlag) { + scriptArguments.push('--quality', this.quality); } else { - core.warning(`'dotnet-quality' input can't be used with exact version: ${versionObject.value} of .NET. 'dotnet-quality' input is ignored.`); + logWarning( + `'dotnet-quality' input can't be used with exact version: ${versionObject.value} of .NET. 'dotnet-quality' input is ignored.` + ); } } - + if (IS_LINUX) { scriptArguments.push('--install-dir', installationDirectoryLinux); } @@ -227,3 +224,8 @@ export class DotnetCoreInstaller { console.log(process.env['PATH']); } } + +export function logWarning(message: string): void { + const warningPrefix = '[warning]'; + core.info(`${warningPrefix}${message}`); +}