mirror of
https://github.com/actions/setup-dotnet.git
synced 2025-08-18 06:35:09 +00:00
Fix review points
This commit is contained in:
parent
1d59406933
commit
2d9890d842
@ -3,7 +3,7 @@ import * as os from 'os';
|
|||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import each from 'jest-each';
|
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 * as installer from '../src/installer';
|
||||||
|
|
||||||
import {IS_WINDOWS} from '../src/utils';
|
import {IS_WINDOWS} from '../src/utils';
|
||||||
@ -153,38 +153,6 @@ describe('DotnetCoreInstaller tests', () => {
|
|||||||
}, 30000);
|
}, 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', () => {
|
describe('DotnetVersionResolver tests', () => {
|
||||||
each([
|
each([
|
||||||
'3.1',
|
'3.1',
|
||||||
|
1485
dist/index.js
vendored
1485
dist/index.js
vendored
File diff suppressed because it is too large
Load Diff
36
package-lock.json
generated
36
package-lock.json
generated
@ -12,7 +12,7 @@
|
|||||||
"@actions/core": "^1.9.1",
|
"@actions/core": "^1.9.1",
|
||||||
"@actions/exec": "^1.0.4",
|
"@actions/exec": "^1.0.4",
|
||||||
"@actions/github": "^1.1.0",
|
"@actions/github": "^1.1.0",
|
||||||
"@actions/http-client": "^1.0.8",
|
"@actions/http-client": "^2.0.1",
|
||||||
"@actions/io": "^1.0.2",
|
"@actions/io": "^1.0.2",
|
||||||
"fast-xml-parser": "^3.15.1",
|
"fast-xml-parser": "^3.15.1",
|
||||||
"semver": "^6.3.0",
|
"semver": "^6.3.0",
|
||||||
@ -41,14 +41,6 @@
|
|||||||
"uuid": "^8.3.2"
|
"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": {
|
"node_modules/@actions/exec": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.1.1.tgz",
|
||||||
@ -67,11 +59,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@actions/http-client": {
|
"node_modules/@actions/http-client": {
|
||||||
"version": "1.0.8",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.8.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.0.1.tgz",
|
||||||
"integrity": "sha512-G4JjJ6f9Hb3Zvejj+ewLLKLf99ZC+9v+yCxoYf9vSyH+WkzPLB2LuUtRMGNkooMqdugGBFStIKXOuvH1W+EctA==",
|
"integrity": "sha512-PIXiMVtz6VvyaRsGY268qvj57hXQEpsYogYOu2nrQhlf+XCGmZstmuZBbAybUl1nQGnvS1k1eEsQ69ZoD7xlSw==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tunnel": "0.0.6"
|
"tunnel": "^0.0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@actions/io": {
|
"node_modules/@actions/io": {
|
||||||
@ -4739,16 +4731,6 @@
|
|||||||
"requires": {
|
"requires": {
|
||||||
"@actions/http-client": "^2.0.1",
|
"@actions/http-client": "^2.0.1",
|
||||||
"uuid": "^8.3.2"
|
"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": {
|
"@actions/exec": {
|
||||||
@ -4769,11 +4751,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@actions/http-client": {
|
"@actions/http-client": {
|
||||||
"version": "1.0.8",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.8.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.0.1.tgz",
|
||||||
"integrity": "sha512-G4JjJ6f9Hb3Zvejj+ewLLKLf99ZC+9v+yCxoYf9vSyH+WkzPLB2LuUtRMGNkooMqdugGBFStIKXOuvH1W+EctA==",
|
"integrity": "sha512-PIXiMVtz6VvyaRsGY268qvj57hXQEpsYogYOu2nrQhlf+XCGmZstmuZBbAybUl1nQGnvS1k1eEsQ69ZoD7xlSw==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"tunnel": "0.0.6"
|
"tunnel": "^0.0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@actions/io": {
|
"@actions/io": {
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
"@actions/core": "^1.9.1",
|
"@actions/core": "^1.9.1",
|
||||||
"@actions/exec": "^1.0.4",
|
"@actions/exec": "^1.0.4",
|
||||||
"@actions/github": "^1.1.0",
|
"@actions/github": "^1.1.0",
|
||||||
"@actions/http-client": "^1.0.8",
|
"@actions/http-client": "^2.0.1",
|
||||||
"@actions/io": "^1.0.2",
|
"@actions/io": "^1.0.2",
|
||||||
"fast-xml-parser": "^3.15.1",
|
"fast-xml-parser": "^3.15.1",
|
||||||
"semver": "^6.3.0",
|
"semver": "^6.3.0",
|
||||||
|
@ -6,35 +6,17 @@ import * as hc from '@actions/http-client';
|
|||||||
import {chmodSync} from 'fs';
|
import {chmodSync} from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import semver from 'semver';
|
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;
|
type: string;
|
||||||
value: string;
|
value: string;
|
||||||
qualityFlag: boolean;
|
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 {
|
export class DotnetVersionResolver {
|
||||||
private inputVersion: string;
|
private inputVersion: string;
|
||||||
private resolvedArgument: IDotNetVersion;
|
private resolvedArgument: DotnetVersion;
|
||||||
|
|
||||||
constructor(version: string) {
|
constructor(version: string) {
|
||||||
this.inputVersion = version.trim();
|
this.inputVersion = version.trim();
|
||||||
@ -62,7 +44,7 @@ export class DotnetVersionResolver {
|
|||||||
allowRetries: true,
|
allowRetries: true,
|
||||||
maxRetries: 3
|
maxRetries: 3
|
||||||
});
|
});
|
||||||
this.resolvedArgument.value = await this.getReleasesJsonUrl(
|
this.resolvedArgument.value = await this.getLatestVersion(
|
||||||
httpClient,
|
httpClient,
|
||||||
[major, minor]
|
[major, minor]
|
||||||
);
|
);
|
||||||
@ -72,7 +54,7 @@ export class DotnetVersionResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private isNumericTag(versionTag): Boolean {
|
private isNumericTag(versionTag): boolean {
|
||||||
return /^\d+$/.test(versionTag);
|
return /^\d+$/.test(versionTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +77,7 @@ export class DotnetVersionResolver {
|
|||||||
return this.resolvedArgument;
|
return this.resolvedArgument;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getReleasesJsonUrl(
|
private async getLatestVersion(
|
||||||
httpClient: hc.HttpClient,
|
httpClient: hc.HttpClient,
|
||||||
versionParts: string[]
|
versionParts: string[]
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
@ -170,14 +152,14 @@ export class DotnetCoreInstaller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private setQuality(
|
private setQuality(
|
||||||
dotnetVersion: IDotNetVersion,
|
dotnetVersion: DotnetVersion,
|
||||||
scriptArguments: string[]
|
scriptArguments: string[]
|
||||||
): void {
|
): void {
|
||||||
const option = IS_WINDOWS ? '-Quality' : '--quality';
|
const option = IS_WINDOWS ? '-Quality' : '--quality';
|
||||||
if (dotnetVersion.qualityFlag) {
|
if (dotnetVersion.qualityFlag) {
|
||||||
scriptArguments.push(option, this.quality);
|
scriptArguments.push(option, this.quality);
|
||||||
} else {
|
} 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.`
|
`'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 versionResolver = new DotnetVersionResolver(this.version);
|
||||||
const dotnetVersion = await versionResolver.createDotNetVersion();
|
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) {
|
if (IS_WINDOWS) {
|
||||||
scriptArguments = ['&', `'${escapedScript}'`];
|
scriptArguments = ['&', `'${escapedScript}'`];
|
||||||
|
|
||||||
@ -259,7 +234,7 @@ export class DotnetCoreInstaller {
|
|||||||
const {exitCode, stdout} = await exec.getExecOutput(
|
const {exitCode, stdout} = await exec.getExecOutput(
|
||||||
`"${scriptPath}"`,
|
`"${scriptPath}"`,
|
||||||
scriptArguments,
|
scriptArguments,
|
||||||
{env: envVariables, ignoreReturnCode: true}
|
{ignoreReturnCode: true}
|
||||||
);
|
);
|
||||||
if (exitCode) {
|
if (exitCode) {
|
||||||
throw new Error(`Failed to install dotnet ${exitCode}. ${stdout}`);
|
throw new Error(`Failed to install dotnet ${exitCode}. ${stdout}`);
|
||||||
|
@ -1,9 +1,19 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import {DotnetQualityValidator, DotnetCoreInstaller} from './installer';
|
import {DotnetCoreInstaller} from './installer';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import * as auth from './authutil';
|
import * as auth from './authutil';
|
||||||
|
|
||||||
|
const qualityOptions = [
|
||||||
|
'daily',
|
||||||
|
'signed',
|
||||||
|
'validated',
|
||||||
|
'preview',
|
||||||
|
'ga'
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
type QualityOptions = typeof qualityOptions[number];
|
||||||
|
|
||||||
export async function run() {
|
export async function run() {
|
||||||
try {
|
try {
|
||||||
//
|
//
|
||||||
@ -38,10 +48,13 @@ export async function run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (versions.length) {
|
if (versions.length) {
|
||||||
const qualityValidator = new DotnetQualityValidator(
|
const quality = core.getInput('dotnet-quality') as QualityOptions;
|
||||||
core.getInput('dotnet-quality')
|
|
||||||
);
|
if (quality && !qualityOptions.includes(quality)) {
|
||||||
const quality = qualityValidator.validateQuality();
|
throw new Error(
|
||||||
|
`${quality} is not a supported value for 'dotnet-quality' option. Supported values are: daily, signed, validated, preview, ga.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
let dotnetInstaller: DotnetCoreInstaller;
|
let dotnetInstaller: DotnetCoreInstaller;
|
||||||
const uniqueVersions = new Set<string>(versions);
|
const uniqueVersions = new Set<string>(versions);
|
||||||
|
@ -2,8 +2,3 @@ import * as core from '@actions/core';
|
|||||||
|
|
||||||
export const IS_WINDOWS = process.platform === 'win32';
|
export const IS_WINDOWS = process.platform === 'win32';
|
||||||
export const IS_LINUX = process.platform === 'linux';
|
export const IS_LINUX = process.platform === 'linux';
|
||||||
|
|
||||||
export function logWarning(message: string): void {
|
|
||||||
const warningPrefix = '[warning]';
|
|
||||||
core.info(`${warningPrefix}${message}`);
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user