mirror of
https://github.com/actions/setup-dotnet.git
synced 2025-08-18 14:45:09 +00:00
Fix review points
This commit is contained in:
parent
6ae0f1e285
commit
0eefb3d008
@ -5,20 +5,23 @@ import * as io from '@actions/io';
|
|||||||
import hc = require('@actions/http-client');
|
import hc = require('@actions/http-client');
|
||||||
import {chmodSync} from 'fs';
|
import {chmodSync} from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import semver from 'semver';
|
||||||
import {ExecOptions} from '@actions/exec/lib/interfaces';
|
import {ExecOptions} from '@actions/exec/lib/interfaces';
|
||||||
|
import {timingSafeEqual} from 'crypto';
|
||||||
|
|
||||||
const IS_WINDOWS = process.platform === 'win32';
|
const IS_WINDOWS = process.platform === 'win32';
|
||||||
const IS_LINUX = process.platform === 'linux';
|
const IS_LINUX = process.platform === 'linux';
|
||||||
|
|
||||||
export class DotnetQualityResolver {
|
export class DotnetQualityValidator {
|
||||||
private quality: string;
|
private quality: string;
|
||||||
private qualityOptions: string[];
|
private qualityOptions: string[];
|
||||||
|
|
||||||
constructor(quality: string) {
|
constructor(quality: string) {
|
||||||
this.quality = quality;
|
this.quality = quality;
|
||||||
this.qualityOptions = ['daily', 'signed', 'validated', 'preview', 'GA'];
|
this.qualityOptions = ['daily', 'signed', 'validated', 'preview', 'GA'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public resolveQuality() {
|
public validateQuality() {
|
||||||
if (!this.qualityOptions.includes(this.quality)) {
|
if (!this.qualityOptions.includes(this.quality)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`${this.quality} is not a supported value for 'dotnet-quality' option. Supported values are: daily, signed, validated, preview, ga.`
|
`${this.quality} is not a supported value for 'dotnet-quality' option. Supported values are: daily, signed, validated, preview, ga.`
|
||||||
@ -27,6 +30,7 @@ export class DotnetQualityResolver {
|
|||||||
return this.quality;
|
return this.quality;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DotnetVersionResolver {
|
export class DotnetVersionResolver {
|
||||||
private inputVersion: string;
|
private inputVersion: string;
|
||||||
private resolvedArgument: {type: string; value: string};
|
private resolvedArgument: {type: string; value: string};
|
||||||
@ -37,24 +41,25 @@ export class DotnetVersionResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private resolveVersionInput(): void {
|
private resolveVersionInput(): void {
|
||||||
const RegExXY = /^\d+.\d+$/;
|
const ValidatingRegEx = /^\d+.\d+/i;
|
||||||
const RegExXYx = /^(\d+.\d+).[x/*]$/i;
|
const ReplacingRegEx = /^(\d+.\d+).[x/*]$/i;
|
||||||
const RegExXYZxx = /^(\d+.\d+.\d{1})[x*]{2}$/i;
|
if (!ValidatingRegEx.test(this.inputVersion)) {
|
||||||
|
throw new Error(
|
||||||
if (RegExXY.test(this.inputVersion)) {
|
'Invalid version format! Supported: A.B.C, A.B.C-D, A.B, A.B.x, A.B.X, A.B.*'
|
||||||
this.resolvedArgument.type = 'channel';
|
);
|
||||||
this.resolvedArgument.value = this.inputVersion;
|
}
|
||||||
} else if (RegExXYx.test(this.inputVersion)) {
|
if (semver.valid(this.inputVersion)) {
|
||||||
this.resolvedArgument.type = 'channel';
|
|
||||||
this.resolvedArgument.value = this.inputVersion.match(RegExXYx)?.[1]!;
|
|
||||||
} else if (RegExXYZxx.test(this.inputVersion)) {
|
|
||||||
this.resolvedArgument.type = 'channel';
|
|
||||||
this.resolvedArgument.value = this.inputVersion
|
|
||||||
.match(RegExXYZxx)?.[1]
|
|
||||||
.concat('xx')!;
|
|
||||||
} else {
|
|
||||||
this.resolvedArgument.type = 'version';
|
this.resolvedArgument.type = 'version';
|
||||||
this.resolvedArgument.value = this.inputVersion;
|
this.resolvedArgument.value = this.inputVersion;
|
||||||
|
} else {
|
||||||
|
this.resolvedArgument.type = 'channel';
|
||||||
|
if (ReplacingRegEx.test(this.inputVersion)) {
|
||||||
|
this.resolvedArgument.value = this.inputVersion.match(
|
||||||
|
ReplacingRegEx
|
||||||
|
)?.[1]!;
|
||||||
|
} else {
|
||||||
|
this.resolvedArgument.value = this.inputVersion;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,9 +97,8 @@ export class DotnetCoreInstaller {
|
|||||||
const installationDirectoryWindows = 'C:\\Program` Files\\dotnet';
|
const installationDirectoryWindows = 'C:\\Program` Files\\dotnet';
|
||||||
const installationDirectoryLinux = '/usr/share/dotnet';
|
const installationDirectoryLinux = '/usr/share/dotnet';
|
||||||
|
|
||||||
const versionObject = new DotnetVersionResolver(
|
const versionResolver = new DotnetVersionResolver(this.version);
|
||||||
this.version
|
const versionObject = versionResolver.createLineArgument();
|
||||||
).createLineArgument();
|
|
||||||
|
|
||||||
var envVariables: {[key: string]: string} = {};
|
var envVariables: {[key: string]: string} = {};
|
||||||
for (let key in process.env) {
|
for (let key in process.env) {
|
||||||
@ -109,18 +113,12 @@ export class DotnetCoreInstaller {
|
|||||||
.replace(/'/g, "''");
|
.replace(/'/g, "''");
|
||||||
let command = `& '${escapedScript}'`;
|
let command = `& '${escapedScript}'`;
|
||||||
|
|
||||||
if (versionObject) {
|
command += ` ${versionObject.type} ${versionObject.value}`;
|
||||||
command += ` ${versionObject.type} ${versionObject.value}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.quality) {
|
if (this.quality) {
|
||||||
if (versionObject.type == '-Channel') {
|
command += `${this.resolveQuality(versionObject).type} ${
|
||||||
command += ` -Quality ${this.quality}`;
|
this.resolveQuality(versionObject).value
|
||||||
} else {
|
}`;
|
||||||
core.warning(
|
|
||||||
"Input 'dotnet-quality' can't be used with the specified exact version of .NET. 'dotnet-quality' input will be ignored."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.env['https_proxy'] != null) {
|
if (process.env['https_proxy'] != null) {
|
||||||
@ -169,18 +167,13 @@ export class DotnetCoreInstaller {
|
|||||||
|
|
||||||
let scriptArguments: string[] = [];
|
let scriptArguments: string[] = [];
|
||||||
|
|
||||||
if (versionObject) {
|
scriptArguments.push(versionObject.type, versionObject.value);
|
||||||
scriptArguments.push(versionObject.type, versionObject.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.quality) {
|
if (this.quality) {
|
||||||
if (versionObject.type == '--channel') {
|
scriptArguments.push(
|
||||||
scriptArguments.push('--quality', this.quality);
|
this.resolveQuality(versionObject).type,
|
||||||
} else {
|
this.resolveQuality(versionObject).value
|
||||||
core.warning(
|
);
|
||||||
"Input 'dotnet-quality' can't be used with the specified exact version of .NET. 'dotnet-quality' input will be ignored."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_LINUX) {
|
if (IS_LINUX) {
|
||||||
@ -203,6 +196,23 @@ 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."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return resolvedArgument;
|
||||||
|
}
|
||||||
|
|
||||||
static addToPath() {
|
static addToPath() {
|
||||||
if (process.env['DOTNET_INSTALL_DIR']) {
|
if (process.env['DOTNET_INSTALL_DIR']) {
|
||||||
core.addPath(process.env['DOTNET_INSTALL_DIR']);
|
core.addPath(process.env['DOTNET_INSTALL_DIR']);
|
||||||
|
@ -38,9 +38,10 @@ export async function run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (versions.length) {
|
if (versions.length) {
|
||||||
const quality = new installer.DotnetQualityResolver(
|
const qualityValidator = new installer.DotnetQualityValidator(
|
||||||
core.getInput('dotnet-quality')
|
core.getInput('dotnet-quality')
|
||||||
).resolveQuality();
|
);
|
||||||
|
const quality = qualityValidator.validateQuality();
|
||||||
|
|
||||||
let dotnetInstaller!: installer.DotnetCoreInstaller;
|
let dotnetInstaller!: installer.DotnetCoreInstaller;
|
||||||
for (const version of new Set<string>(versions)) {
|
for (const version of new Set<string>(versions)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user