@@ -6,6 +6,7 @@ import * as hc from '@actions/http-client';
66import { chmodSync } from 'fs' ;
77import { readdir } from 'fs/promises' ;
88import path from 'path' ;
9+ import os from 'os' ;
910import semver from 'semver' ;
1011import { IS_LINUX , IS_WINDOWS } from './utils' ;
1112import { QualityOptions } from './setup-dotnet' ;
@@ -112,40 +113,29 @@ export class DotnetVersionResolver {
112113export 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