From b4e0d356f9525a2df50878839949114cf3f1a65d Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Fri, 30 Sep 2022 14:11:07 +0200 Subject: [PATCH 1/9] Fix issue with DOTNET_INSTALL_DIR env.var --- dist/index.js | 20 +++++++++++--------- src/installer.ts | 29 ++++++++++++++--------------- src/utils.ts | 1 - 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/dist/index.js b/dist/index.js index 217682101..ab821252b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -333,7 +333,9 @@ class DotnetCoreInstaller { if (process.env['no_proxy'] != null) { scriptArguments.push(`-ProxyBypassList ${process.env['no_proxy']}`); } - scriptArguments.push('-InstallDir', `'${DotnetCoreInstaller.installationDirectoryWindows}'`); + if (!process.env['DOTNET_INSTALL_DIR']) { + scriptArguments.push('-InstallDir', `'${DotnetCoreInstaller.installationDirectoryWindows}'`); + } // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used scriptPath = (yield io.which('pwsh', false)) || (yield io.which('powershell', true)); @@ -349,18 +351,19 @@ class DotnetCoreInstaller { if (this.quality) { this.setQuality(dotnetVersion, scriptArguments); } - if (utils_1.IS_LINUX) { - scriptArguments.push('--install-dir', DotnetCoreInstaller.installationDirectoryLinux); - } - if (utils_1.IS_MAC) { - scriptArguments.push('--install-dir', DotnetCoreInstaller.installationDirectoryMac); + if (!process.env['DOTNET_INSTALL_DIR']) { + scriptArguments.push('--install-dir', utils_1.IS_LINUX + ? DotnetCoreInstaller.installationDirectoryLinux + : DotnetCoreInstaller.installationDirectoryMac); } } const { exitCode, stdout } = yield exec.getExecOutput(`"${scriptPath}"`, scriptArguments, { ignoreReturnCode: true }); if (exitCode) { throw new Error(`Failed to install dotnet ${exitCode}. ${stdout}`); } - return this.outputDotnetVersion(dotnetVersion.value, scriptArguments[scriptArguments.length - 1]); + return this.outputDotnetVersion(dotnetVersion.value, process.env['DOTNET_INSTALL_DIR'] + ? process.env['DOTNET_INSTALL_DIR'] + : scriptArguments[scriptArguments.length - 1]); }); } outputDotnetVersion(version, installationPath) { @@ -523,10 +526,9 @@ run(); "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.IS_MAC = exports.IS_LINUX = exports.IS_WINDOWS = void 0; +exports.IS_LINUX = exports.IS_WINDOWS = void 0; exports.IS_WINDOWS = process.platform === 'win32'; exports.IS_LINUX = process.platform === 'linux'; -exports.IS_MAC = process.platform === 'darwin'; /***/ }), diff --git a/src/installer.ts b/src/installer.ts index 041b65579..dc3c2758f 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -7,7 +7,7 @@ import {chmodSync} from 'fs'; import {readdir} from 'fs/promises'; import path from 'path'; import semver from 'semver'; -import {IS_LINUX, IS_WINDOWS, IS_MAC} from './utils'; +import {IS_LINUX, IS_WINDOWS} from './utils'; import {QualityOptions} from './setup-dotnet'; export interface DotnetVersion { @@ -208,10 +208,12 @@ export class DotnetCoreInstaller { scriptArguments.push(`-ProxyBypassList ${process.env['no_proxy']}`); } - scriptArguments.push( - '-InstallDir', - `'${DotnetCoreInstaller.installationDirectoryWindows}'` - ); + if (!process.env['DOTNET_INSTALL_DIR']) { + scriptArguments.push( + '-InstallDir', + `'${DotnetCoreInstaller.installationDirectoryWindows}'` + ); + } // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used scriptPath = (await io.which('pwsh', false)) || (await io.which('powershell', true)); @@ -229,17 +231,12 @@ export class DotnetCoreInstaller { this.setQuality(dotnetVersion, scriptArguments); } - if (IS_LINUX) { + if (!process.env['DOTNET_INSTALL_DIR']) { scriptArguments.push( '--install-dir', - DotnetCoreInstaller.installationDirectoryLinux - ); - } - - if (IS_MAC) { - scriptArguments.push( - '--install-dir', - DotnetCoreInstaller.installationDirectoryMac + IS_LINUX + ? DotnetCoreInstaller.installationDirectoryLinux + : DotnetCoreInstaller.installationDirectoryMac ); } } @@ -254,7 +251,9 @@ export class DotnetCoreInstaller { return this.outputDotnetVersion( dotnetVersion.value, - scriptArguments[scriptArguments.length - 1] + process.env['DOTNET_INSTALL_DIR'] + ? process.env['DOTNET_INSTALL_DIR'] + : scriptArguments[scriptArguments.length - 1] ); } diff --git a/src/utils.ts b/src/utils.ts index ff20ee303..77886ce0e 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,3 +1,2 @@ export const IS_WINDOWS = process.platform === 'win32'; export const IS_LINUX = process.platform === 'linux'; -export const IS_MAC = process.platform === 'darwin'; From 0949c87857988cd55971760d4461738ec27d31f2 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Fri, 30 Sep 2022 14:43:34 +0200 Subject: [PATCH 2/9] Output DOTNET_INSTALL_DIR if present --- dist/index.js | 4 ++++ src/installer.ts | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/dist/index.js b/dist/index.js index ab821252b..7ba0702e1 100644 --- a/dist/index.js +++ b/dist/index.js @@ -301,6 +301,10 @@ class DotnetCoreInstaller { } installDotnet() { 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 = [ '-NoLogo', '-Sta', diff --git a/src/installer.ts b/src/installer.ts index dc3c2758f..ecae01da7 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -170,6 +170,10 @@ export class DotnetCoreInstaller { } public async installDotnet(): Promise { + const dotnetInstallDir = process.env['DOTNET_INSTALL_DIR']; + if (dotnetInstallDir) { + core.debug(`DOTNET_INSTALL_DIR is set up to ${dotnetInstallDir}`); + } const windowsDefaultOptions = [ '-NoLogo', '-Sta', From 1225bf2b8a37ff800daa2deaa47f03d79d8e0c34 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Fri, 30 Sep 2022 14:53:08 +0200 Subject: [PATCH 3/9] Fix logic --- dist/index.js | 8 ++++---- src/installer.ts | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dist/index.js b/dist/index.js index 7ba0702e1..371b043d3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -337,7 +337,7 @@ class DotnetCoreInstaller { if (process.env['no_proxy'] != null) { scriptArguments.push(`-ProxyBypassList ${process.env['no_proxy']}`); } - if (!process.env['DOTNET_INSTALL_DIR']) { + if (!dotnetInstallDir) { scriptArguments.push('-InstallDir', `'${DotnetCoreInstaller.installationDirectoryWindows}'`); } // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used @@ -355,7 +355,7 @@ class DotnetCoreInstaller { if (this.quality) { this.setQuality(dotnetVersion, scriptArguments); } - if (!process.env['DOTNET_INSTALL_DIR']) { + if (!dotnetInstallDir) { scriptArguments.push('--install-dir', utils_1.IS_LINUX ? DotnetCoreInstaller.installationDirectoryLinux : DotnetCoreInstaller.installationDirectoryMac); @@ -365,8 +365,8 @@ class DotnetCoreInstaller { if (exitCode) { throw new Error(`Failed to install dotnet ${exitCode}. ${stdout}`); } - return this.outputDotnetVersion(dotnetVersion.value, process.env['DOTNET_INSTALL_DIR'] - ? process.env['DOTNET_INSTALL_DIR'] + return this.outputDotnetVersion(dotnetVersion.value, dotnetInstallDir + ? dotnetInstallDir : scriptArguments[scriptArguments.length - 1]); }); } diff --git a/src/installer.ts b/src/installer.ts index ecae01da7..56869fa42 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -212,7 +212,7 @@ export class DotnetCoreInstaller { scriptArguments.push(`-ProxyBypassList ${process.env['no_proxy']}`); } - if (!process.env['DOTNET_INSTALL_DIR']) { + if (!dotnetInstallDir) { scriptArguments.push( '-InstallDir', `'${DotnetCoreInstaller.installationDirectoryWindows}'` @@ -235,7 +235,7 @@ export class DotnetCoreInstaller { this.setQuality(dotnetVersion, scriptArguments); } - if (!process.env['DOTNET_INSTALL_DIR']) { + if (!dotnetInstallDir) { scriptArguments.push( '--install-dir', IS_LINUX @@ -255,8 +255,8 @@ export class DotnetCoreInstaller { return this.outputDotnetVersion( dotnetVersion.value, - process.env['DOTNET_INSTALL_DIR'] - ? process.env['DOTNET_INSTALL_DIR'] + dotnetInstallDir + ? dotnetInstallDir : scriptArguments[scriptArguments.length - 1] ); } From 99eb4e7d581d35b03d0c3371bcb5cb14cc2c11f2 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Mon, 3 Oct 2022 13:27:16 +0200 Subject: [PATCH 4/9] Inject environment variables into getExecOutput() --- dist/index.js | 6 +++++- src/installer.ts | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 371b043d3..016158c12 100644 --- a/dist/index.js +++ b/dist/index.js @@ -361,7 +361,11 @@ class DotnetCoreInstaller { : DotnetCoreInstaller.installationDirectoryMac); } } - const { exitCode, stdout } = yield exec.getExecOutput(`"${scriptPath}"`, scriptArguments, { ignoreReturnCode: true }); + const getExecOutputOptions = { + ignoreReturnCode: true, + env: process.env + }; + const { exitCode, stdout } = yield exec.getExecOutput(`"${scriptPath}"`, scriptArguments, getExecOutputOptions); if (exitCode) { throw new Error(`Failed to install dotnet ${exitCode}. ${stdout}`); } diff --git a/src/installer.ts b/src/installer.ts index 56869fa42..6a7702ee6 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -244,10 +244,15 @@ export class DotnetCoreInstaller { ); } } + + const getExecOutputOptions = { + ignoreReturnCode: true, + env: process.env as {string: string} + }; const {exitCode, stdout} = await exec.getExecOutput( `"${scriptPath}"`, scriptArguments, - {ignoreReturnCode: true} + getExecOutputOptions ); if (exitCode) { throw new Error(`Failed to install dotnet ${exitCode}. ${stdout}`); From 4aad884a7a666831ae80d20e828de1d047825894 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Mon, 3 Oct 2022 13:55:03 +0200 Subject: [PATCH 5/9] Refactor code --- dist/index.js | 21 ++++++++------------- src/installer.ts | 31 ++++++++++--------------------- 2 files changed, 18 insertions(+), 34 deletions(-) diff --git a/dist/index.js b/dist/index.js index 016158c12..59deee9a7 100644 --- a/dist/index.js +++ b/dist/index.js @@ -301,10 +301,6 @@ class DotnetCoreInstaller { } installDotnet() { 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 = [ '-NoLogo', '-Sta', @@ -337,10 +333,10 @@ class DotnetCoreInstaller { if (process.env['no_proxy'] != null) { scriptArguments.push(`-ProxyBypassList ${process.env['no_proxy']}`); } - if (!dotnetInstallDir) { - scriptArguments.push('-InstallDir', `'${DotnetCoreInstaller.installationDirectoryWindows}'`); + if (!process.env['DOTNET_INSTALL_DIR']) { + process.env['DOTNET_INSTALL_DIR'] = + DotnetCoreInstaller.installationDirectoryWindows; } - // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used scriptPath = (yield io.which('pwsh', false)) || (yield io.which('powershell', true)); scriptArguments = windowsDefaultOptions.concat(scriptArguments); @@ -355,12 +351,13 @@ class DotnetCoreInstaller { if (this.quality) { this.setQuality(dotnetVersion, scriptArguments); } - if (!dotnetInstallDir) { - scriptArguments.push('--install-dir', utils_1.IS_LINUX + if (!process.env['DOTNET_INSTALL_DIR']) { + process.env['DOTNET_INSTALL_DIR'] = utils_1.IS_LINUX ? DotnetCoreInstaller.installationDirectoryLinux - : DotnetCoreInstaller.installationDirectoryMac); + : DotnetCoreInstaller.installationDirectoryMac; } } + // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used const getExecOutputOptions = { ignoreReturnCode: true, env: process.env @@ -369,9 +366,7 @@ class DotnetCoreInstaller { if (exitCode) { throw new Error(`Failed to install dotnet ${exitCode}. ${stdout}`); } - return this.outputDotnetVersion(dotnetVersion.value, dotnetInstallDir - ? dotnetInstallDir - : scriptArguments[scriptArguments.length - 1]); + return this.outputDotnetVersion(dotnetVersion.value, process.env['DOTNET_INSTALL_DIR']); }); } outputDotnetVersion(version, installationPath) { diff --git a/src/installer.ts b/src/installer.ts index 6a7702ee6..f7730a6aa 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -170,10 +170,6 @@ export class DotnetCoreInstaller { } public async installDotnet(): Promise { - const dotnetInstallDir = process.env['DOTNET_INSTALL_DIR']; - if (dotnetInstallDir) { - core.debug(`DOTNET_INSTALL_DIR is set up to ${dotnetInstallDir}`); - } const windowsDefaultOptions = [ '-NoLogo', '-Sta', @@ -212,13 +208,11 @@ export class DotnetCoreInstaller { scriptArguments.push(`-ProxyBypassList ${process.env['no_proxy']}`); } - if (!dotnetInstallDir) { - scriptArguments.push( - '-InstallDir', - `'${DotnetCoreInstaller.installationDirectoryWindows}'` - ); + if (!process.env['DOTNET_INSTALL_DIR']) { + process.env['DOTNET_INSTALL_DIR'] = + DotnetCoreInstaller.installationDirectoryWindows; } - // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used + scriptPath = (await io.which('pwsh', false)) || (await io.which('powershell', true)); scriptArguments = windowsDefaultOptions.concat(scriptArguments); @@ -235,16 +229,13 @@ export class DotnetCoreInstaller { this.setQuality(dotnetVersion, scriptArguments); } - if (!dotnetInstallDir) { - scriptArguments.push( - '--install-dir', - IS_LINUX - ? DotnetCoreInstaller.installationDirectoryLinux - : DotnetCoreInstaller.installationDirectoryMac - ); + if (!process.env['DOTNET_INSTALL_DIR']) { + process.env['DOTNET_INSTALL_DIR'] = IS_LINUX + ? DotnetCoreInstaller.installationDirectoryLinux + : DotnetCoreInstaller.installationDirectoryMac; } } - + // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used const getExecOutputOptions = { ignoreReturnCode: true, env: process.env as {string: string} @@ -260,9 +251,7 @@ export class DotnetCoreInstaller { return this.outputDotnetVersion( dotnetVersion.value, - dotnetInstallDir - ? dotnetInstallDir - : scriptArguments[scriptArguments.length - 1] + process.env['DOTNET_INSTALL_DIR'] ); } From 206199fb0409bf40610e80812dff5cc003a8fe69 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Mon, 3 Oct 2022 14:03:30 +0200 Subject: [PATCH 6/9] Update documentation --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c802711b7..b02b4baba 100644 --- a/README.md +++ b/README.md @@ -195,6 +195,7 @@ Some environment variables may be necessary for your particular case or to impro | **Env.variable** | **Description** | **Default value** | | ----------- | ----------- | ----------- | +| DOTNET_INSTALL_DIR |Specifies a directory where .NET SDKs should be installed by the action|*isn't set*| | DOTNET_NOLOGO |Removes logo and telemetry message from first run of dotnet cli|*false*| | DOTNET_CLI_TELEMETRY_OPTOUT |Opt-out of telemetry being sent to Microsoft|*false*| | DOTNET_MULTILEVEL_LOOKUP |Configures whether the global install location is used as a fall-back|*true*| @@ -204,7 +205,7 @@ Some environment variables may be necessary for your particular case or to impro build: runs-on: ubuntu-latest env: - DOTNET_NOLOGO: true + DOTNET_INSTALL_DIR: "some/directory" steps: - uses: actions/checkout@main - uses: actions/setup-dotnet@v3 From 5b3f163c2cba4bc80c94ad9f22fd7dec07743826 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Mon, 3 Oct 2022 14:04:56 +0200 Subject: [PATCH 7/9] Update documentation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b02b4baba..c4472ea30 100644 --- a/README.md +++ b/README.md @@ -205,7 +205,7 @@ Some environment variables may be necessary for your particular case or to impro build: runs-on: ubuntu-latest env: - DOTNET_INSTALL_DIR: "some/directory" + DOTNET_INSTALL_DIR: "some/specific/directory" steps: - uses: actions/checkout@main - uses: actions/setup-dotnet@v3 From 51e9ed003857e9ad6e598195cb66d47010f11dd7 Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Mon, 3 Oct 2022 14:06:08 +0200 Subject: [PATCH 8/9] Update documentation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c4472ea30..382465bbd 100644 --- a/README.md +++ b/README.md @@ -205,7 +205,7 @@ Some environment variables may be necessary for your particular case or to impro build: runs-on: ubuntu-latest env: - DOTNET_INSTALL_DIR: "some/specific/directory" + DOTNET_INSTALL_DIR: "path/to/directory" steps: - uses: actions/checkout@main - uses: actions/setup-dotnet@v3 From ba2bb181d236177c6fd559689a3f088faa00cf7c Mon Sep 17 00:00:00 2001 From: IvanZosimov Date: Tue, 4 Oct 2022 09:26:38 +0200 Subject: [PATCH 9/9] Bump the action's version to v3.0.1 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 98bc5c556..5459e0f8a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "setup-dotnet", - "version": "3.0.0", + "version": "3.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "setup-dotnet", - "version": "3.0.0", + "version": "3.0.1", "license": "MIT", "dependencies": { "@actions/core": "^1.9.1", diff --git a/package.json b/package.json index 5838e4d3a..b58554ceb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "setup-dotnet", - "version": "3.0.0", + "version": "3.0.1", "private": true, "description": "setup dotnet action", "main": "lib/setup-dotnet.js",