Skip to content

Commit d9a34fb

Browse files
author
IvanZosimov
committed
Add logic for processing DOTNET_INSTALL_DIR
1 parent 6c6c8dd commit d9a34fb

File tree

2 files changed

+98
-88
lines changed

2 files changed

+98
-88
lines changed

dist/index.js

+58-39
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1010
if (k2 === undefined) k2 = k;
11-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
11+
var desc = Object.getOwnPropertyDescriptor(m, k);
12+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13+
desc = { enumerable: true, get: function() { return m[k]; } };
14+
}
15+
Object.defineProperty(o, k2, desc);
1216
}) : (function(o, m, k, k2) {
1317
if (k2 === undefined) k2 = k;
1418
o[k2] = m[k];
@@ -21,7 +25,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
2125
var __importStar = (this && this.__importStar) || function (mod) {
2226
if (mod && mod.__esModule) return mod;
2327
var result = {};
24-
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
2529
__setModuleDefault(result, mod);
2630
return result;
2731
};
@@ -152,7 +156,11 @@ function writeFeedToFile(feedUrl, existingFileLocation, tempFileLocation) {
152156

153157
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
154158
if (k2 === undefined) k2 = k;
155-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
159+
var desc = Object.getOwnPropertyDescriptor(m, k);
160+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
161+
desc = { enumerable: true, get: function() { return m[k]; } };
162+
}
163+
Object.defineProperty(o, k2, desc);
156164
}) : (function(o, m, k, k2) {
157165
if (k2 === undefined) k2 = k;
158166
o[k2] = m[k];
@@ -165,7 +173,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
165173
var __importStar = (this && this.__importStar) || function (mod) {
166174
if (mod && mod.__esModule) return mod;
167175
var result = {};
168-
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
176+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
169177
__setModuleDefault(result, mod);
170178
return result;
171179
};
@@ -181,6 +189,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
181189
var __importDefault = (this && this.__importDefault) || function (mod) {
182190
return (mod && mod.__esModule) ? mod : { "default": mod };
183191
};
192+
var _a;
184193
Object.defineProperty(exports, "__esModule", ({ value: true }));
185194
exports.DotnetCoreInstaller = exports.DotnetVersionResolver = void 0;
186195
// Load tempDirectory before it gets wiped by tool-cache
@@ -191,6 +200,7 @@ const hc = __importStar(__nccwpck_require__(6255));
191200
const fs_1 = __nccwpck_require__(7147);
192201
const promises_1 = __nccwpck_require__(3292);
193202
const path_1 = __importDefault(__nccwpck_require__(1017));
203+
const os_1 = __importDefault(__nccwpck_require__(2037));
194204
const semver_1 = __importDefault(__nccwpck_require__(5911));
195205
const utils_1 = __nccwpck_require__(918);
196206
class DotnetVersionResolver {
@@ -269,26 +279,21 @@ class DotnetCoreInstaller {
269279
this.version = version;
270280
this.quality = quality;
271281
}
272-
static addToPath() {
273-
if (process.env['DOTNET_INSTALL_DIR']) {
274-
core.addPath(process.env['DOTNET_INSTALL_DIR']);
275-
core.exportVariable('DOTNET_ROOT', process.env['DOTNET_INSTALL_DIR']);
282+
static convertInstallPathToAbsolute(installDir) {
283+
let transformedPath;
284+
if (path_1.default.isAbsolute(installDir)) {
285+
transformedPath = installDir;
276286
}
277287
else {
278-
if (utils_1.IS_WINDOWS) {
279-
core.addPath(DotnetCoreInstaller.installationDirectoryWindows);
280-
core.exportVariable('DOTNET_ROOT', DotnetCoreInstaller.installationDirectoryWindows);
281-
}
282-
else if (utils_1.IS_LINUX) {
283-
core.addPath(DotnetCoreInstaller.installationDirectoryLinux);
284-
core.exportVariable('DOTNET_ROOT', DotnetCoreInstaller.installationDirectoryLinux);
285-
}
286-
else {
287-
// This is the default set in install-dotnet.sh
288-
core.addPath(DotnetCoreInstaller.installationDirectoryMac);
289-
core.exportVariable('DOTNET_ROOT', DotnetCoreInstaller.installationDirectoryMac);
290-
}
288+
transformedPath = installDir.startsWith('~')
289+
? path_1.default.join(os_1.default.homedir(), installDir.slice(1))
290+
: (transformedPath = path_1.default.join(process.cwd(), installDir));
291291
}
292+
return path_1.default.normalize(transformedPath);
293+
}
294+
static addToPath() {
295+
core.addPath(process.env['DOTNET_INSTALL_DIR']);
296+
core.exportVariable('DOTNET_ROOT', process.env['DOTNET_INSTALL_DIR']);
292297
}
293298
setQuality(dotnetVersion, scriptArguments) {
294299
const option = utils_1.IS_WINDOWS ? '-Quality' : '--quality';
@@ -333,16 +338,12 @@ class DotnetCoreInstaller {
333338
if (process.env['no_proxy'] != null) {
334339
scriptArguments.push(`-ProxyBypassList ${process.env['no_proxy']}`);
335340
}
336-
if (!process.env['DOTNET_INSTALL_DIR']) {
337-
process.env['DOTNET_INSTALL_DIR'] =
338-
DotnetCoreInstaller.installationDirectoryWindows;
339-
}
340341
scriptPath =
341342
(yield io.which('pwsh', false)) || (yield io.which('powershell', true));
342343
scriptArguments = windowsDefaultOptions.concat(scriptArguments);
343344
}
344345
else {
345-
fs_1.chmodSync(escapedScript, '777');
346+
(0, fs_1.chmodSync)(escapedScript, '777');
346347
scriptPath = yield io.which(escapedScript, true);
347348
scriptArguments = [];
348349
if (dotnetVersion.type) {
@@ -351,11 +352,6 @@ class DotnetCoreInstaller {
351352
if (this.quality) {
352353
this.setQuality(dotnetVersion, scriptArguments);
353354
}
354-
if (!process.env['DOTNET_INSTALL_DIR']) {
355-
process.env['DOTNET_INSTALL_DIR'] = utils_1.IS_LINUX
356-
? DotnetCoreInstaller.installationDirectoryLinux
357-
: DotnetCoreInstaller.installationDirectoryMac;
358-
}
359355
}
360356
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
361357
const getExecOutputOptions = {
@@ -366,12 +362,13 @@ class DotnetCoreInstaller {
366362
if (exitCode) {
367363
throw new Error(`Failed to install dotnet ${exitCode}. ${stdout}`);
368364
}
369-
return this.outputDotnetVersion(dotnetVersion.value, process.env['DOTNET_INSTALL_DIR']);
365+
return this.outputDotnetVersion(dotnetVersion.value);
370366
});
371367
}
372-
outputDotnetVersion(version, installationPath) {
368+
outputDotnetVersion(version) {
373369
return __awaiter(this, void 0, void 0, function* () {
374-
let versionsOnRunner = yield promises_1.readdir(path_1.default.join(installationPath.replace(/'/g, ''), 'sdk'));
370+
const installationPath = process.env['DOTNET_INSTALL_DIR'];
371+
let versionsOnRunner = yield (0, promises_1.readdir)(path_1.default.join(installationPath.replace(/'/g, ''), 'sdk'));
375372
let installedVersion = semver_1.default.maxSatisfying(versionsOnRunner, version, {
376373
includePrerelease: true
377374
});
@@ -380,9 +377,27 @@ class DotnetCoreInstaller {
380377
}
381378
}
382379
exports.DotnetCoreInstaller = DotnetCoreInstaller;
383-
DotnetCoreInstaller.installationDirectoryWindows = path_1.default.join(process.env['PROGRAMFILES'] + '', 'dotnet');
384-
DotnetCoreInstaller.installationDirectoryLinux = '/usr/share/dotnet';
385-
DotnetCoreInstaller.installationDirectoryMac = path_1.default.join(process.env['HOME'] + '', '.dotnet');
380+
_a = DotnetCoreInstaller;
381+
(() => {
382+
const installationDirectoryWindows = path_1.default.join(process.env['PROGRAMFILES'] + '', 'dotnet');
383+
const installationDirectoryLinux = '/usr/share/dotnet';
384+
const installationDirectoryMac = path_1.default.join(process.env['HOME'] + '', '.dotnet');
385+
const dotnetInstallDir = process.env['DOTNET_INSTALL_DIR'];
386+
if (dotnetInstallDir) {
387+
process.env['DOTNET_INSTALL_DIR'] =
388+
_a.convertInstallPathToAbsolute(dotnetInstallDir);
389+
}
390+
else {
391+
if (utils_1.IS_WINDOWS) {
392+
process.env['DOTNET_INSTALL_DIR'] = installationDirectoryWindows;
393+
}
394+
else {
395+
process.env['DOTNET_INSTALL_DIR'] = utils_1.IS_LINUX
396+
? installationDirectoryLinux
397+
: installationDirectoryMac;
398+
}
399+
}
400+
})();
386401

387402

388403
/***/ }),
@@ -394,7 +409,11 @@ DotnetCoreInstaller.installationDirectoryMac = path_1.default.join(process.env['
394409

395410
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
396411
if (k2 === undefined) k2 = k;
397-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
412+
var desc = Object.getOwnPropertyDescriptor(m, k);
413+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
414+
desc = { enumerable: true, get: function() { return m[k]; } };
415+
}
416+
Object.defineProperty(o, k2, desc);
398417
}) : (function(o, m, k, k2) {
399418
if (k2 === undefined) k2 = k;
400419
o[k2] = m[k];
@@ -407,7 +426,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
407426
var __importStar = (this && this.__importStar) || function (mod) {
408427
if (mod && mod.__esModule) return mod;
409428
var result = {};
410-
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
429+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
411430
__setModuleDefault(result, mod);
412431
return result;
413432
};

src/installer.ts

+40-49
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as hc from '@actions/http-client';
66
import {chmodSync} from 'fs';
77
import {readdir} from 'fs/promises';
88
import path from 'path';
9+
import os from 'os';
910
import semver from 'semver';
1011
import {IS_LINUX, IS_WINDOWS} from './utils';
1112
import {QualityOptions} from './setup-dotnet';
@@ -112,40 +113,29 @@ export class DotnetVersionResolver {
112113
export class DotnetCoreInstaller {
113114
private version: string;
114115
private quality: QualityOptions;
115-
private static readonly installationDirectoryWindows = path.join(
116-
process.env['PROGRAMFILES'] + '',
117-
'dotnet'
118-
);
119-
private static readonly installationDirectoryLinux = '/usr/share/dotnet';
120-
private static readonly installationDirectoryMac = path.join(
121-
process.env['HOME'] + '',
122-
'.dotnet'
123-
);
124116

125-
static addToPath() {
126-
if (process.env['DOTNET_INSTALL_DIR']) {
127-
core.addPath(process.env['DOTNET_INSTALL_DIR']);
128-
core.exportVariable('DOTNET_ROOT', process.env['DOTNET_INSTALL_DIR']);
117+
static {
118+
const installationDirectoryWindows = path.join(
119+
process.env['PROGRAMFILES'] + '',
120+
'dotnet'
121+
);
122+
const installationDirectoryLinux = '/usr/share/dotnet';
123+
const installationDirectoryMac = path.join(
124+
process.env['HOME'] + '',
125+
'.dotnet'
126+
);
127+
const dotnetInstallDir: string | undefined =
128+
process.env['DOTNET_INSTALL_DIR'];
129+
if (dotnetInstallDir) {
130+
process.env['DOTNET_INSTALL_DIR'] =
131+
this.convertInstallPathToAbsolute(dotnetInstallDir);
129132
} else {
130133
if (IS_WINDOWS) {
131-
core.addPath(DotnetCoreInstaller.installationDirectoryWindows);
132-
core.exportVariable(
133-
'DOTNET_ROOT',
134-
DotnetCoreInstaller.installationDirectoryWindows
135-
);
136-
} else if (IS_LINUX) {
137-
core.addPath(DotnetCoreInstaller.installationDirectoryLinux);
138-
core.exportVariable(
139-
'DOTNET_ROOT',
140-
DotnetCoreInstaller.installationDirectoryLinux
141-
);
134+
process.env['DOTNET_INSTALL_DIR'] = installationDirectoryWindows;
142135
} else {
143-
// This is the default set in install-dotnet.sh
144-
core.addPath(DotnetCoreInstaller.installationDirectoryMac);
145-
core.exportVariable(
146-
'DOTNET_ROOT',
147-
DotnetCoreInstaller.installationDirectoryMac
148-
);
136+
process.env['DOTNET_INSTALL_DIR'] = IS_LINUX
137+
? installationDirectoryLinux
138+
: installationDirectoryMac;
149139
}
150140
}
151141
}
@@ -155,6 +145,23 @@ export class DotnetCoreInstaller {
155145
this.quality = quality;
156146
}
157147

148+
private static convertInstallPathToAbsolute(installDir: string): string {
149+
let transformedPath;
150+
if (path.isAbsolute(installDir)) {
151+
transformedPath = installDir;
152+
} else {
153+
transformedPath = installDir.startsWith('~')
154+
? path.join(os.homedir(), installDir.slice(1))
155+
: (transformedPath = path.join(process.cwd(), installDir));
156+
}
157+
return path.normalize(transformedPath);
158+
}
159+
160+
static addToPath() {
161+
core.addPath(process.env['DOTNET_INSTALL_DIR']!);
162+
core.exportVariable('DOTNET_ROOT', process.env['DOTNET_INSTALL_DIR']);
163+
}
164+
158165
private setQuality(
159166
dotnetVersion: DotnetVersion,
160167
scriptArguments: string[]
@@ -208,11 +215,6 @@ export class DotnetCoreInstaller {
208215
scriptArguments.push(`-ProxyBypassList ${process.env['no_proxy']}`);
209216
}
210217

211-
if (!process.env['DOTNET_INSTALL_DIR']) {
212-
process.env['DOTNET_INSTALL_DIR'] =
213-
DotnetCoreInstaller.installationDirectoryWindows;
214-
}
215-
216218
scriptPath =
217219
(await io.which('pwsh', false)) || (await io.which('powershell', true));
218220
scriptArguments = windowsDefaultOptions.concat(scriptArguments);
@@ -228,12 +230,6 @@ export class DotnetCoreInstaller {
228230
if (this.quality) {
229231
this.setQuality(dotnetVersion, scriptArguments);
230232
}
231-
232-
if (!process.env['DOTNET_INSTALL_DIR']) {
233-
process.env['DOTNET_INSTALL_DIR'] = IS_LINUX
234-
? DotnetCoreInstaller.installationDirectoryLinux
235-
: DotnetCoreInstaller.installationDirectoryMac;
236-
}
237233
}
238234
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
239235
const getExecOutputOptions = {
@@ -249,16 +245,11 @@ export class DotnetCoreInstaller {
249245
throw new Error(`Failed to install dotnet ${exitCode}. ${stdout}`);
250246
}
251247

252-
return this.outputDotnetVersion(
253-
dotnetVersion.value,
254-
process.env['DOTNET_INSTALL_DIR']
255-
);
248+
return this.outputDotnetVersion(dotnetVersion.value);
256249
}
257250

258-
private async outputDotnetVersion(
259-
version,
260-
installationPath
261-
): Promise<string> {
251+
private async outputDotnetVersion(version): Promise<string> {
252+
const installationPath = process.env['DOTNET_INSTALL_DIR']!;
262253
let versionsOnRunner: string[] = await readdir(
263254
path.join(installationPath.replace(/'/g, ''), 'sdk')
264255
);

0 commit comments

Comments
 (0)