@@ -6,6 +6,7 @@ import * as hc from '@actions/http-client';
6
6
import { chmodSync } from 'fs' ;
7
7
import { readdir } from 'fs/promises' ;
8
8
import path from 'path' ;
9
+ import os from 'os' ;
9
10
import semver from 'semver' ;
10
11
import { IS_LINUX , IS_WINDOWS } from './utils' ;
11
12
import { QualityOptions } from './setup-dotnet' ;
@@ -112,40 +113,29 @@ export class DotnetVersionResolver {
112
113
export class DotnetCoreInstaller {
113
114
private version : string ;
114
115
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
- ) ;
124
116
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 ) ;
129
132
} else {
130
133
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 ;
142
135
} 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 ;
149
139
}
150
140
}
151
141
}
@@ -155,6 +145,23 @@ export class DotnetCoreInstaller {
155
145
this . quality = quality ;
156
146
}
157
147
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
+
158
165
private setQuality (
159
166
dotnetVersion : DotnetVersion ,
160
167
scriptArguments : string [ ]
@@ -208,11 +215,6 @@ export class DotnetCoreInstaller {
208
215
scriptArguments . push ( `-ProxyBypassList ${ process . env [ 'no_proxy' ] } ` ) ;
209
216
}
210
217
211
- if ( ! process . env [ 'DOTNET_INSTALL_DIR' ] ) {
212
- process . env [ 'DOTNET_INSTALL_DIR' ] =
213
- DotnetCoreInstaller . installationDirectoryWindows ;
214
- }
215
-
216
218
scriptPath =
217
219
( await io . which ( 'pwsh' , false ) ) || ( await io . which ( 'powershell' , true ) ) ;
218
220
scriptArguments = windowsDefaultOptions . concat ( scriptArguments ) ;
@@ -228,12 +230,6 @@ export class DotnetCoreInstaller {
228
230
if ( this . quality ) {
229
231
this . setQuality ( dotnetVersion , scriptArguments ) ;
230
232
}
231
-
232
- if ( ! process . env [ 'DOTNET_INSTALL_DIR' ] ) {
233
- process . env [ 'DOTNET_INSTALL_DIR' ] = IS_LINUX
234
- ? DotnetCoreInstaller . installationDirectoryLinux
235
- : DotnetCoreInstaller . installationDirectoryMac ;
236
- }
237
233
}
238
234
// process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
239
235
const getExecOutputOptions = {
@@ -249,16 +245,11 @@ export class DotnetCoreInstaller {
249
245
throw new Error ( `Failed to install dotnet ${ exitCode } . ${ stdout } ` ) ;
250
246
}
251
247
252
- return this . outputDotnetVersion (
253
- dotnetVersion . value ,
254
- process . env [ 'DOTNET_INSTALL_DIR' ]
255
- ) ;
248
+ return this . outputDotnetVersion ( dotnetVersion . value ) ;
256
249
}
257
250
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' ] ! ;
262
253
let versionsOnRunner : string [ ] = await readdir (
263
254
path . join ( installationPath . replace ( / ' / g, '' ) , 'sdk' )
264
255
) ;
0 commit comments