Refactor code

This commit is contained in:
IvanZosimov 2022-10-03 13:55:03 +02:00
parent 99eb4e7d58
commit 4aad884a7a
2 changed files with 18 additions and 34 deletions

21
dist/index.js vendored
View File

@ -301,10 +301,6 @@ class DotnetCoreInstaller {
} }
installDotnet() { installDotnet() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const dotnetInstallDir = process.env['DOTNET_INSTALL_DIR'];
if (dotnetInstallDir) {
core.debug(`DOTNET_INSTALL_DIR is set up to ${dotnetInstallDir}`);
}
const windowsDefaultOptions = [ const windowsDefaultOptions = [
'-NoLogo', '-NoLogo',
'-Sta', '-Sta',
@ -337,10 +333,10 @@ class DotnetCoreInstaller {
if (process.env['no_proxy'] != null) { if (process.env['no_proxy'] != null) {
scriptArguments.push(`-ProxyBypassList ${process.env['no_proxy']}`); scriptArguments.push(`-ProxyBypassList ${process.env['no_proxy']}`);
} }
if (!dotnetInstallDir) { if (!process.env['DOTNET_INSTALL_DIR']) {
scriptArguments.push('-InstallDir', `'${DotnetCoreInstaller.installationDirectoryWindows}'`); process.env['DOTNET_INSTALL_DIR'] =
DotnetCoreInstaller.installationDirectoryWindows;
} }
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
scriptPath = scriptPath =
(yield io.which('pwsh', false)) || (yield io.which('powershell', true)); (yield io.which('pwsh', false)) || (yield io.which('powershell', true));
scriptArguments = windowsDefaultOptions.concat(scriptArguments); scriptArguments = windowsDefaultOptions.concat(scriptArguments);
@ -355,12 +351,13 @@ class DotnetCoreInstaller {
if (this.quality) { if (this.quality) {
this.setQuality(dotnetVersion, scriptArguments); this.setQuality(dotnetVersion, scriptArguments);
} }
if (!dotnetInstallDir) { if (!process.env['DOTNET_INSTALL_DIR']) {
scriptArguments.push('--install-dir', utils_1.IS_LINUX process.env['DOTNET_INSTALL_DIR'] = utils_1.IS_LINUX
? DotnetCoreInstaller.installationDirectoryLinux ? DotnetCoreInstaller.installationDirectoryLinux
: DotnetCoreInstaller.installationDirectoryMac); : DotnetCoreInstaller.installationDirectoryMac;
} }
} }
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
const getExecOutputOptions = { const getExecOutputOptions = {
ignoreReturnCode: true, ignoreReturnCode: true,
env: process.env env: process.env
@ -369,9 +366,7 @@ class DotnetCoreInstaller {
if (exitCode) { if (exitCode) {
throw new Error(`Failed to install dotnet ${exitCode}. ${stdout}`); throw new Error(`Failed to install dotnet ${exitCode}. ${stdout}`);
} }
return this.outputDotnetVersion(dotnetVersion.value, dotnetInstallDir return this.outputDotnetVersion(dotnetVersion.value, process.env['DOTNET_INSTALL_DIR']);
? dotnetInstallDir
: scriptArguments[scriptArguments.length - 1]);
}); });
} }
outputDotnetVersion(version, installationPath) { outputDotnetVersion(version, installationPath) {

View File

@ -170,10 +170,6 @@ export class DotnetCoreInstaller {
} }
public async installDotnet(): Promise<string> { public async installDotnet(): Promise<string> {
const dotnetInstallDir = process.env['DOTNET_INSTALL_DIR'];
if (dotnetInstallDir) {
core.debug(`DOTNET_INSTALL_DIR is set up to ${dotnetInstallDir}`);
}
const windowsDefaultOptions = [ const windowsDefaultOptions = [
'-NoLogo', '-NoLogo',
'-Sta', '-Sta',
@ -212,13 +208,11 @@ export class DotnetCoreInstaller {
scriptArguments.push(`-ProxyBypassList ${process.env['no_proxy']}`); scriptArguments.push(`-ProxyBypassList ${process.env['no_proxy']}`);
} }
if (!dotnetInstallDir) { if (!process.env['DOTNET_INSTALL_DIR']) {
scriptArguments.push( process.env['DOTNET_INSTALL_DIR'] =
'-InstallDir', DotnetCoreInstaller.installationDirectoryWindows;
`'${DotnetCoreInstaller.installationDirectoryWindows}'`
);
} }
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
scriptPath = scriptPath =
(await io.which('pwsh', false)) || (await io.which('powershell', true)); (await io.which('pwsh', false)) || (await io.which('powershell', true));
scriptArguments = windowsDefaultOptions.concat(scriptArguments); scriptArguments = windowsDefaultOptions.concat(scriptArguments);
@ -235,16 +229,13 @@ export class DotnetCoreInstaller {
this.setQuality(dotnetVersion, scriptArguments); this.setQuality(dotnetVersion, scriptArguments);
} }
if (!dotnetInstallDir) { if (!process.env['DOTNET_INSTALL_DIR']) {
scriptArguments.push( process.env['DOTNET_INSTALL_DIR'] = IS_LINUX
'--install-dir', ? DotnetCoreInstaller.installationDirectoryLinux
IS_LINUX : DotnetCoreInstaller.installationDirectoryMac;
? DotnetCoreInstaller.installationDirectoryLinux
: DotnetCoreInstaller.installationDirectoryMac
);
} }
} }
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
const getExecOutputOptions = { const getExecOutputOptions = {
ignoreReturnCode: true, ignoreReturnCode: true,
env: process.env as {string: string} env: process.env as {string: string}
@ -260,9 +251,7 @@ export class DotnetCoreInstaller {
return this.outputDotnetVersion( return this.outputDotnetVersion(
dotnetVersion.value, dotnetVersion.value,
dotnetInstallDir process.env['DOTNET_INSTALL_DIR']
? dotnetInstallDir
: scriptArguments[scriptArguments.length - 1]
); );
} }