Fix review point

This commit is contained in:
IvanZosimov 2022-08-17 10:19:49 +02:00
parent 7c495956c6
commit 48c496df53
2 changed files with 18 additions and 53 deletions

29
dist/index.js vendored
View File

@ -208,7 +208,7 @@ exports.DotnetQualityValidator = DotnetQualityValidator;
class DotnetVersionResolver {
constructor(version) {
this.inputVersion = version.trim();
this.resolvedArgument = { type: '', value: '' };
this.resolvedArgument = { type: '', value: '', qualityFlag: false };
}
resolveVersionInput() {
var _a;
@ -223,6 +223,7 @@ 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];
}
@ -231,7 +232,7 @@ class DotnetVersionResolver {
}
}
}
createLineArgument() {
createVersionObject() {
this.resolveVersionInput();
if (IS_WINDOWS) {
if (this.resolvedArgument.type === 'channel') {
@ -265,7 +266,7 @@ class DotnetCoreInstaller {
const installationDirectoryWindows = 'C:\\Program` Files\\dotnet';
const installationDirectoryLinux = '/usr/share/dotnet';
const versionResolver = new DotnetVersionResolver(this.version);
const versionObject = versionResolver.createLineArgument();
const versionObject = versionResolver.createVersionObject();
var envVariables = {};
for (let key in process.env) {
if (process.env[key]) {
@ -279,8 +280,8 @@ class DotnetCoreInstaller {
.replace(/'/g, "''");
let command = `& '${escapedScript}'`;
command += ` ${versionObject.type} ${versionObject.value}`;
if (this.quality) {
command += ` ${this.resolveQuality(versionObject).type} ${this.resolveQuality(versionObject).value}`;
if (this.quality && versionObject.qualityFlag) {
command += ` -Quality ${this.quality}`;
}
if (process.env['https_proxy'] != null) {
command += ` -ProxyAddress ${process.env['https_proxy']}`;
@ -319,8 +320,8 @@ class DotnetCoreInstaller {
const scriptPath = yield io.which(escapedScript, true);
let scriptArguments = [];
scriptArguments.push(versionObject.type, versionObject.value);
if (this.quality) {
scriptArguments.push(this.resolveQuality(versionObject).type, this.resolveQuality(versionObject).value);
if (this.quality && versionObject.qualityFlag) {
scriptArguments.push("--quality", this.quality);
}
if (IS_LINUX) {
scriptArguments.push('--install-dir', installationDirectoryLinux);
@ -340,20 +341,6 @@ class DotnetCoreInstaller {
}
});
}
resolveQuality(versionObject) {
let resolvedArgument = { type: '', value: '' };
if (versionObject.type == '-Channel') {
resolvedArgument = { type: '-Quality', value: `${this.quality}` };
}
else if (versionObject.type == '--channel') {
resolvedArgument = { type: '--quality', value: `${this.quality}` };
}
else {
core.warning("Input 'dotnet-quality' can't be used with the specified exact version of .NET. 'dotnet-quality' input will be ignored.");
this.quality = "";
}
return resolvedArgument;
}
static addToPath() {
if (process.env['DOTNET_INSTALL_DIR']) {
core.addPath(process.env['DOTNET_INSTALL_DIR']);

View File

@ -33,11 +33,11 @@ export class DotnetQualityValidator {
export class DotnetVersionResolver {
private inputVersion: string;
private resolvedArgument: {type: string; value: string};
private resolvedArgument: {type: string; value: string, qualityFlag: boolean};
constructor(version: string) {
this.inputVersion = version.trim();
this.resolvedArgument = {type: '', value: ''};
this.resolvedArgument = {type: '', value: '', qualityFlag: false};
}
private resolveVersionInput(): void {
@ -53,6 +53,7 @@ export class DotnetVersionResolver {
this.resolvedArgument.value = this.inputVersion;
} else {
this.resolvedArgument.type = 'channel';
this.resolvedArgument.qualityFlag = true;
if (ReplacingRegEx.test(this.inputVersion)) {
this.resolvedArgument.value = this.inputVersion.match(
ReplacingRegEx
@ -63,7 +64,7 @@ export class DotnetVersionResolver {
}
}
public createLineArgument(): {type: string; value: string} {
public createVersionObject(): {type: string; value: string, qualityFlag: boolean} {
this.resolveVersionInput();
if (IS_WINDOWS) {
if (this.resolvedArgument.type === 'channel') {
@ -98,7 +99,7 @@ export class DotnetCoreInstaller {
const installationDirectoryLinux = '/usr/share/dotnet';
const versionResolver = new DotnetVersionResolver(this.version);
const versionObject = versionResolver.createLineArgument();
const versionObject = versionResolver.createVersionObject();
var envVariables: {[key: string]: string} = {};
for (let key in process.env) {
@ -115,10 +116,8 @@ export class DotnetCoreInstaller {
command += ` ${versionObject.type} ${versionObject.value}`;
if (this.quality) {
command += ` ${this.resolveQuality(versionObject).type} ${
this.resolveQuality(versionObject).value
}`;
if (this.quality && versionObject.qualityFlag) {
command += ` -Quality ${this.quality}`;
}
if (process.env['https_proxy'] != null) {
@ -169,13 +168,10 @@ export class DotnetCoreInstaller {
scriptArguments.push(versionObject.type, versionObject.value);
if (this.quality) {
scriptArguments.push(
this.resolveQuality(versionObject).type,
this.resolveQuality(versionObject).value
);
if (this.quality && versionObject.qualityFlag) {
scriptArguments.push("--quality", this.quality);
}
if (IS_LINUX) {
scriptArguments.push('--install-dir', installationDirectoryLinux);
}
@ -196,24 +192,6 @@ export class DotnetCoreInstaller {
}
}
private resolveQuality(versionObject: {
type: string;
value: string;
}): {type: string; value: string} {
let resolvedArgument: {type: string; value: string} = {type: '', value: ''};
if (versionObject.type == '-Channel') {
resolvedArgument = {type: '-Quality', value: `${this.quality}`};
} else if (versionObject.type == '--channel') {
resolvedArgument = {type: '--quality', value: `${this.quality}`};
} else {
core.warning(
"Input 'dotnet-quality' can't be used with the specified exact version of .NET. 'dotnet-quality' input will be ignored."
);
this.quality = "";
}
return resolvedArgument;
}
static addToPath() {
if (process.env['DOTNET_INSTALL_DIR']) {
core.addPath(process.env['DOTNET_INSTALL_DIR']);