Skip to content

Commit 45c9f23

Browse files
authored
Enable ability to change .NET SDK installation directory by DOTNET_INSTALL_DIR environment variable (#329)
1 parent c7e7147 commit 45c9f23

File tree

6 files changed

+38
-36
lines changed

6 files changed

+38
-36
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ Some environment variables may be necessary for your particular case or to impro
195195

196196
| **Env.variable** | **Description** | **Default value** |
197197
| ----------- | ----------- | ----------- |
198+
| DOTNET_INSTALL_DIR |Specifies a directory where .NET SDKs should be installed by the action|*isn't set*|
198199
| DOTNET_NOLOGO |Removes logo and telemetry message from first run of dotnet cli|*false*|
199200
| DOTNET_CLI_TELEMETRY_OPTOUT |Opt-out of telemetry being sent to Microsoft|*false*|
200201
| 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
204205
build:
205206
runs-on: ubuntu-latest
206207
env:
207-
DOTNET_NOLOGO: true
208+
DOTNET_INSTALL_DIR: "path/to/directory"
208209
steps:
209210
- uses: actions/checkout@main
210211
- uses: actions/setup-dotnet@v3

dist/index.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,10 @@ class DotnetCoreInstaller {
333333
if (process.env['no_proxy'] != null) {
334334
scriptArguments.push(`-ProxyBypassList ${process.env['no_proxy']}`);
335335
}
336-
scriptArguments.push('-InstallDir', `'${DotnetCoreInstaller.installationDirectoryWindows}'`);
337-
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
336+
if (!process.env['DOTNET_INSTALL_DIR']) {
337+
process.env['DOTNET_INSTALL_DIR'] =
338+
DotnetCoreInstaller.installationDirectoryWindows;
339+
}
338340
scriptPath =
339341
(yield io.which('pwsh', false)) || (yield io.which('powershell', true));
340342
scriptArguments = windowsDefaultOptions.concat(scriptArguments);
@@ -349,18 +351,22 @@ class DotnetCoreInstaller {
349351
if (this.quality) {
350352
this.setQuality(dotnetVersion, scriptArguments);
351353
}
352-
if (utils_1.IS_LINUX) {
353-
scriptArguments.push('--install-dir', DotnetCoreInstaller.installationDirectoryLinux);
354-
}
355-
if (utils_1.IS_MAC) {
356-
scriptArguments.push('--install-dir', DotnetCoreInstaller.installationDirectoryMac);
354+
if (!process.env['DOTNET_INSTALL_DIR']) {
355+
process.env['DOTNET_INSTALL_DIR'] = utils_1.IS_LINUX
356+
? DotnetCoreInstaller.installationDirectoryLinux
357+
: DotnetCoreInstaller.installationDirectoryMac;
357358
}
358359
}
359-
const { exitCode, stdout } = yield exec.getExecOutput(`"${scriptPath}"`, scriptArguments, { ignoreReturnCode: true });
360+
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
361+
const getExecOutputOptions = {
362+
ignoreReturnCode: true,
363+
env: process.env
364+
};
365+
const { exitCode, stdout } = yield exec.getExecOutput(`"${scriptPath}"`, scriptArguments, getExecOutputOptions);
360366
if (exitCode) {
361367
throw new Error(`Failed to install dotnet ${exitCode}. ${stdout}`);
362368
}
363-
return this.outputDotnetVersion(dotnetVersion.value, scriptArguments[scriptArguments.length - 1]);
369+
return this.outputDotnetVersion(dotnetVersion.value, process.env['DOTNET_INSTALL_DIR']);
364370
});
365371
}
366372
outputDotnetVersion(version, installationPath) {
@@ -523,10 +529,9 @@ run();
523529
"use strict";
524530

525531
Object.defineProperty(exports, "__esModule", ({ value: true }));
526-
exports.IS_MAC = exports.IS_LINUX = exports.IS_WINDOWS = void 0;
532+
exports.IS_LINUX = exports.IS_WINDOWS = void 0;
527533
exports.IS_WINDOWS = process.platform === 'win32';
528534
exports.IS_LINUX = process.platform === 'linux';
529-
exports.IS_MAC = process.platform === 'darwin';
530535

531536

532537
/***/ }),

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "setup-dotnet",
3-
"version": "3.0.0",
3+
"version": "3.0.1",
44
"private": true,
55
"description": "setup dotnet action",
66
"main": "lib/setup-dotnet.js",

src/installer.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {chmodSync} from 'fs';
77
import {readdir} from 'fs/promises';
88
import path from 'path';
99
import semver from 'semver';
10-
import {IS_LINUX, IS_WINDOWS, IS_MAC} from './utils';
10+
import {IS_LINUX, IS_WINDOWS} from './utils';
1111
import {QualityOptions} from './setup-dotnet';
1212

1313
export interface DotnetVersion {
@@ -208,11 +208,11 @@ export class DotnetCoreInstaller {
208208
scriptArguments.push(`-ProxyBypassList ${process.env['no_proxy']}`);
209209
}
210210

211-
scriptArguments.push(
212-
'-InstallDir',
213-
`'${DotnetCoreInstaller.installationDirectoryWindows}'`
214-
);
215-
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
211+
if (!process.env['DOTNET_INSTALL_DIR']) {
212+
process.env['DOTNET_INSTALL_DIR'] =
213+
DotnetCoreInstaller.installationDirectoryWindows;
214+
}
215+
216216
scriptPath =
217217
(await io.which('pwsh', false)) || (await io.which('powershell', true));
218218
scriptArguments = windowsDefaultOptions.concat(scriptArguments);
@@ -229,32 +229,29 @@ export class DotnetCoreInstaller {
229229
this.setQuality(dotnetVersion, scriptArguments);
230230
}
231231

232-
if (IS_LINUX) {
233-
scriptArguments.push(
234-
'--install-dir',
235-
DotnetCoreInstaller.installationDirectoryLinux
236-
);
237-
}
238-
239-
if (IS_MAC) {
240-
scriptArguments.push(
241-
'--install-dir',
242-
DotnetCoreInstaller.installationDirectoryMac
243-
);
232+
if (!process.env['DOTNET_INSTALL_DIR']) {
233+
process.env['DOTNET_INSTALL_DIR'] = IS_LINUX
234+
? DotnetCoreInstaller.installationDirectoryLinux
235+
: DotnetCoreInstaller.installationDirectoryMac;
244236
}
245237
}
238+
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
239+
const getExecOutputOptions = {
240+
ignoreReturnCode: true,
241+
env: process.env as {string: string}
242+
};
246243
const {exitCode, stdout} = await exec.getExecOutput(
247244
`"${scriptPath}"`,
248245
scriptArguments,
249-
{ignoreReturnCode: true}
246+
getExecOutputOptions
250247
);
251248
if (exitCode) {
252249
throw new Error(`Failed to install dotnet ${exitCode}. ${stdout}`);
253250
}
254251

255252
return this.outputDotnetVersion(
256253
dotnetVersion.value,
257-
scriptArguments[scriptArguments.length - 1]
254+
process.env['DOTNET_INSTALL_DIR']
258255
);
259256
}
260257

src/utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export const IS_WINDOWS = process.platform === 'win32';
22
export const IS_LINUX = process.platform === 'linux';
3-
export const IS_MAC = process.platform === 'darwin';

0 commit comments

Comments
 (0)