Enable ability to change .NET SDK installation directory by DOTNET_INSTALL_DIR environment variable (#329)

This commit is contained in:
Ivan 2022-10-04 10:22:05 +02:00 committed by GitHub
parent c7e7147fd3
commit 45c9f236cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 38 additions and 36 deletions

View File

@ -195,6 +195,7 @@ Some environment variables may be necessary for your particular case or to impro
| **Env.variable** | **Description** | **Default value** | | **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_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_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*| | 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: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:
DOTNET_NOLOGO: true DOTNET_INSTALL_DIR: "path/to/directory"
steps: steps:
- uses: actions/checkout@main - uses: actions/checkout@main
- uses: actions/setup-dotnet@v3 - uses: actions/setup-dotnet@v3

27
dist/index.js vendored
View File

@ -333,8 +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']}`);
} }
scriptArguments.push('-InstallDir', `'${DotnetCoreInstaller.installationDirectoryWindows}'`); if (!process.env['DOTNET_INSTALL_DIR']) {
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used process.env['DOTNET_INSTALL_DIR'] =
DotnetCoreInstaller.installationDirectoryWindows;
}
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);
@ -349,18 +351,22 @@ class DotnetCoreInstaller {
if (this.quality) { if (this.quality) {
this.setQuality(dotnetVersion, scriptArguments); this.setQuality(dotnetVersion, scriptArguments);
} }
if (utils_1.IS_LINUX) { if (!process.env['DOTNET_INSTALL_DIR']) {
scriptArguments.push('--install-dir', DotnetCoreInstaller.installationDirectoryLinux); process.env['DOTNET_INSTALL_DIR'] = utils_1.IS_LINUX
} ? DotnetCoreInstaller.installationDirectoryLinux
if (utils_1.IS_MAC) { : DotnetCoreInstaller.installationDirectoryMac;
scriptArguments.push('--install-dir', DotnetCoreInstaller.installationDirectoryMac);
} }
} }
const { exitCode, stdout } = yield exec.getExecOutput(`"${scriptPath}"`, scriptArguments, { ignoreReturnCode: true }); // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
const getExecOutputOptions = {
ignoreReturnCode: true,
env: process.env
};
const { exitCode, stdout } = yield exec.getExecOutput(`"${scriptPath}"`, scriptArguments, getExecOutputOptions);
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, scriptArguments[scriptArguments.length - 1]); return this.outputDotnetVersion(dotnetVersion.value, process.env['DOTNET_INSTALL_DIR']);
}); });
} }
outputDotnetVersion(version, installationPath) { outputDotnetVersion(version, installationPath) {
@ -523,10 +529,9 @@ run();
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", ({ value: true })); 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_WINDOWS = process.platform === 'win32';
exports.IS_LINUX = process.platform === 'linux'; exports.IS_LINUX = process.platform === 'linux';
exports.IS_MAC = process.platform === 'darwin';
/***/ }), /***/ }),

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "setup-dotnet", "name": "setup-dotnet",
"version": "3.0.0", "version": "3.0.1",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "setup-dotnet", "name": "setup-dotnet",
"version": "3.0.0", "version": "3.0.1",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^1.9.1", "@actions/core": "^1.9.1",

View File

@ -1,6 +1,6 @@
{ {
"name": "setup-dotnet", "name": "setup-dotnet",
"version": "3.0.0", "version": "3.0.1",
"private": true, "private": true,
"description": "setup dotnet action", "description": "setup dotnet action",
"main": "lib/setup-dotnet.js", "main": "lib/setup-dotnet.js",

View File

@ -7,7 +7,7 @@ import {chmodSync} from 'fs';
import {readdir} from 'fs/promises'; import {readdir} from 'fs/promises';
import path from 'path'; import path from 'path';
import semver from 'semver'; 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'; import {QualityOptions} from './setup-dotnet';
export interface DotnetVersion { export interface DotnetVersion {
@ -208,11 +208,11 @@ export class DotnetCoreInstaller {
scriptArguments.push(`-ProxyBypassList ${process.env['no_proxy']}`); scriptArguments.push(`-ProxyBypassList ${process.env['no_proxy']}`);
} }
scriptArguments.push( if (!process.env['DOTNET_INSTALL_DIR']) {
'-InstallDir', process.env['DOTNET_INSTALL_DIR'] =
`'${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);
@ -229,24 +229,21 @@ export class DotnetCoreInstaller {
this.setQuality(dotnetVersion, scriptArguments); this.setQuality(dotnetVersion, scriptArguments);
} }
if (IS_LINUX) { if (!process.env['DOTNET_INSTALL_DIR']) {
scriptArguments.push( process.env['DOTNET_INSTALL_DIR'] = IS_LINUX
'--install-dir', ? DotnetCoreInstaller.installationDirectoryLinux
DotnetCoreInstaller.installationDirectoryLinux : DotnetCoreInstaller.installationDirectoryMac;
);
}
if (IS_MAC) {
scriptArguments.push(
'--install-dir',
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}
};
const {exitCode, stdout} = await exec.getExecOutput( const {exitCode, stdout} = await exec.getExecOutput(
`"${scriptPath}"`, `"${scriptPath}"`,
scriptArguments, scriptArguments,
{ignoreReturnCode: true} getExecOutputOptions
); );
if (exitCode) { if (exitCode) {
throw new Error(`Failed to install dotnet ${exitCode}. ${stdout}`); throw new Error(`Failed to install dotnet ${exitCode}. ${stdout}`);
@ -254,7 +251,7 @@ export class DotnetCoreInstaller {
return this.outputDotnetVersion( return this.outputDotnetVersion(
dotnetVersion.value, dotnetVersion.value,
scriptArguments[scriptArguments.length - 1] process.env['DOTNET_INSTALL_DIR']
); );
} }

View File

@ -1,3 +1,2 @@
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 const IS_MAC = process.platform === 'darwin';