Fix review points

This commit is contained in:
IvanZosimov 2022-09-22 15:26:13 +02:00
parent 1d59406933
commit 2d9890d842
7 changed files with 460 additions and 1168 deletions

View File

@ -3,7 +3,7 @@ import * as os from 'os';
import fs from 'fs';
import path from 'path';
import each from 'jest-each';
import * as hc from '@actions/core/node_modules/@actions/http-client';
import * as hc from '@actions/http-client';
import * as installer from '../src/installer';
import {IS_WINDOWS} from '../src/utils';
@ -153,38 +153,6 @@ describe('DotnetCoreInstaller tests', () => {
}, 30000);
});
describe('DotnetQualityValidator tests', () => {
it("returns quality if it's supplied and valid", () => {
const qualityInput = 'preview';
const dotnetQualityValidator = new installer.DotnetQualityValidator(
qualityInput
);
const result = dotnetQualityValidator.validateQuality();
expect(result).toBe('preview');
});
each(['', undefined]).test(
"input value '%s' should be returned as it is",
version => {
const dotnetQualityValidator = new installer.DotnetQualityValidator(
version
);
const result = dotnetQualityValidator.validateQuality();
expect(result).toBe(version);
}
);
it('throws if quality is supplied and invalid', () => {
const qualityInput = 'invalid';
const dotnetQualityValidator = new installer.DotnetQualityValidator(
qualityInput
);
expect(() => dotnetQualityValidator.validateQuality()).toThrow();
});
});
describe('DotnetVersionResolver tests', () => {
each([
'3.1',

1233
dist/index.js vendored

File diff suppressed because it is too large Load Diff

36
package-lock.json generated
View File

@ -12,7 +12,7 @@
"@actions/core": "^1.9.1",
"@actions/exec": "^1.0.4",
"@actions/github": "^1.1.0",
"@actions/http-client": "^1.0.8",
"@actions/http-client": "^2.0.1",
"@actions/io": "^1.0.2",
"fast-xml-parser": "^3.15.1",
"semver": "^6.3.0",
@ -41,14 +41,6 @@
"uuid": "^8.3.2"
}
},
"node_modules/@actions/core/node_modules/@actions/http-client": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.0.1.tgz",
"integrity": "sha512-PIXiMVtz6VvyaRsGY268qvj57hXQEpsYogYOu2nrQhlf+XCGmZstmuZBbAybUl1nQGnvS1k1eEsQ69ZoD7xlSw==",
"dependencies": {
"tunnel": "^0.0.6"
}
},
"node_modules/@actions/exec": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.1.1.tgz",
@ -67,11 +59,11 @@
}
},
"node_modules/@actions/http-client": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.8.tgz",
"integrity": "sha512-G4JjJ6f9Hb3Zvejj+ewLLKLf99ZC+9v+yCxoYf9vSyH+WkzPLB2LuUtRMGNkooMqdugGBFStIKXOuvH1W+EctA==",
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.0.1.tgz",
"integrity": "sha512-PIXiMVtz6VvyaRsGY268qvj57hXQEpsYogYOu2nrQhlf+XCGmZstmuZBbAybUl1nQGnvS1k1eEsQ69ZoD7xlSw==",
"dependencies": {
"tunnel": "0.0.6"
"tunnel": "^0.0.6"
}
},
"node_modules/@actions/io": {
@ -4739,16 +4731,6 @@
"requires": {
"@actions/http-client": "^2.0.1",
"uuid": "^8.3.2"
},
"dependencies": {
"@actions/http-client": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.0.1.tgz",
"integrity": "sha512-PIXiMVtz6VvyaRsGY268qvj57hXQEpsYogYOu2nrQhlf+XCGmZstmuZBbAybUl1nQGnvS1k1eEsQ69ZoD7xlSw==",
"requires": {
"tunnel": "^0.0.6"
}
}
}
},
"@actions/exec": {
@ -4769,11 +4751,11 @@
}
},
"@actions/http-client": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.8.tgz",
"integrity": "sha512-G4JjJ6f9Hb3Zvejj+ewLLKLf99ZC+9v+yCxoYf9vSyH+WkzPLB2LuUtRMGNkooMqdugGBFStIKXOuvH1W+EctA==",
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.0.1.tgz",
"integrity": "sha512-PIXiMVtz6VvyaRsGY268qvj57hXQEpsYogYOu2nrQhlf+XCGmZstmuZBbAybUl1nQGnvS1k1eEsQ69ZoD7xlSw==",
"requires": {
"tunnel": "0.0.6"
"tunnel": "^0.0.6"
}
},
"@actions/io": {

View File

@ -27,7 +27,7 @@
"@actions/core": "^1.9.1",
"@actions/exec": "^1.0.4",
"@actions/github": "^1.1.0",
"@actions/http-client": "^1.0.8",
"@actions/http-client": "^2.0.1",
"@actions/io": "^1.0.2",
"fast-xml-parser": "^3.15.1",
"semver": "^6.3.0",

View File

@ -6,35 +6,17 @@ import * as hc from '@actions/http-client';
import {chmodSync} from 'fs';
import path from 'path';
import semver from 'semver';
import {IS_LINUX, IS_WINDOWS, logWarning} from './utils';
import {IS_LINUX, IS_WINDOWS} from './utils';
export interface IDotNetVersion {
export interface DotnetVersion {
type: string;
value: string;
qualityFlag: boolean;
}
export class DotnetQualityValidator {
private quality: string;
private qualityOptions = ['daily', 'signed', 'validated', 'preview', 'ga'];
constructor(quality: string) {
this.quality = quality;
}
public validateQuality() {
if (this.quality && !this.qualityOptions.includes(this.quality)) {
throw new Error(
`${this.quality} is not a supported value for 'dotnet-quality' option. Supported values are: daily, signed, validated, preview, ga.`
);
}
return this.quality;
}
}
export class DotnetVersionResolver {
private inputVersion: string;
private resolvedArgument: IDotNetVersion;
private resolvedArgument: DotnetVersion;
constructor(version: string) {
this.inputVersion = version.trim();
@ -62,7 +44,7 @@ export class DotnetVersionResolver {
allowRetries: true,
maxRetries: 3
});
this.resolvedArgument.value = await this.getReleasesJsonUrl(
this.resolvedArgument.value = await this.getLatestVersion(
httpClient,
[major, minor]
);
@ -72,7 +54,7 @@ export class DotnetVersionResolver {
}
}
private isNumericTag(versionTag): Boolean {
private isNumericTag(versionTag): boolean {
return /^\d+$/.test(versionTag);
}
@ -95,7 +77,7 @@ export class DotnetVersionResolver {
return this.resolvedArgument;
}
private async getReleasesJsonUrl(
private async getLatestVersion(
httpClient: hc.HttpClient,
versionParts: string[]
): Promise<string> {
@ -170,14 +152,14 @@ export class DotnetCoreInstaller {
}
private setQuality(
dotnetVersion: IDotNetVersion,
dotnetVersion: DotnetVersion,
scriptArguments: string[]
): void {
const option = IS_WINDOWS ? '-Quality' : '--quality';
if (dotnetVersion.qualityFlag) {
scriptArguments.push(option, this.quality);
} else {
logWarning(
core.warning(
`'dotnet-quality' input can be used only with .NET SDK version in A.B, A.B.x, A and A.x formats where the major tag is higher than 5. You specified: ${this.version}. 'dotnet-quality' input is ignored.`
);
}
@ -203,13 +185,6 @@ export class DotnetCoreInstaller {
const versionResolver = new DotnetVersionResolver(this.version);
const dotnetVersion = await versionResolver.createDotNetVersion();
const envVariables: {[key: string]: string} = {};
for (let key in process.env) {
if (process.env[key]) {
let value: any = process.env[key];
envVariables[key] = value;
}
}
if (IS_WINDOWS) {
scriptArguments = ['&', `'${escapedScript}'`];
@ -259,7 +234,7 @@ export class DotnetCoreInstaller {
const {exitCode, stdout} = await exec.getExecOutput(
`"${scriptPath}"`,
scriptArguments,
{env: envVariables, ignoreReturnCode: true}
{ignoreReturnCode: true}
);
if (exitCode) {
throw new Error(`Failed to install dotnet ${exitCode}. ${stdout}`);

View File

@ -1,9 +1,19 @@
import * as core from '@actions/core';
import {DotnetQualityValidator, DotnetCoreInstaller} from './installer';
import {DotnetCoreInstaller} from './installer';
import * as fs from 'fs';
import path from 'path';
import * as auth from './authutil';
const qualityOptions = [
'daily',
'signed',
'validated',
'preview',
'ga'
] as const;
type QualityOptions = typeof qualityOptions[number];
export async function run() {
try {
//
@ -38,10 +48,13 @@ export async function run() {
}
if (versions.length) {
const qualityValidator = new DotnetQualityValidator(
core.getInput('dotnet-quality')
const quality = core.getInput('dotnet-quality') as QualityOptions;
if (quality && !qualityOptions.includes(quality)) {
throw new Error(
`${quality} is not a supported value for 'dotnet-quality' option. Supported values are: daily, signed, validated, preview, ga.`
);
const quality = qualityValidator.validateQuality();
}
let dotnetInstaller: DotnetCoreInstaller;
const uniqueVersions = new Set<string>(versions);

View File

@ -2,8 +2,3 @@ import * as core from '@actions/core';
export const IS_WINDOWS = process.platform === 'win32';
export const IS_LINUX = process.platform === 'linux';
export function logWarning(message: string): void {
const warningPrefix = '[warning]';
core.info(`${warningPrefix}${message}`);
}