Add logic for processing DOTNET_INSTALL_DIR environment variable (#332)
This commit is contained in:
		
							parent
							
								
									70c3f4d098
								
							
						
					
					
						commit
						4d4a70f4a5
					
				
							
								
								
									
										2
									
								
								.gitattributes
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitattributes
									
									
									
									
										vendored
									
									
								
							| @ -1 +1 @@ | |||||||
| .licenses/** -diff linguist-generated=true | .licenses/** -diff linguist-generated=true | ||||||
|  | |||||||
| @ -7,5 +7,6 @@ | |||||||
|     "trailingComma": "none", |     "trailingComma": "none", | ||||||
|     "bracketSpacing": false, |     "bracketSpacing": false, | ||||||
|     "arrowParens": "avoid", |     "arrowParens": "avoid", | ||||||
|     "parser": "typescript" |     "parser": "typescript", | ||||||
|  |     "endOfLine": "auto" | ||||||
|   } |   } | ||||||
| @ -195,11 +195,18 @@ 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_INSTALL_DIR      |Specifies a directory where .NET SDKs should be installed by the action.|*default value for each OS* | | ||||||
| | 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*| | ||||||
| 
 | 
 | ||||||
|  | The default value of the `DOTNET_INSTALL_DIR` environment variable depends on the operation system which is used on a runner: | ||||||
|  | | **Operation system**      | **Default value** | | ||||||
|  | | ----------- | ----------- | | ||||||
|  | | **Windows** | `C:\Program Files\dotnet` | | ||||||
|  | | **Ubuntu** | `/usr/share/dotnet` | | ||||||
|  | | **macOS** | `/Users/runner/.dotnet` | | ||||||
|  | 
 | ||||||
| **Example usage**: | **Example usage**: | ||||||
| ```yml | ```yml | ||||||
| build: | build: | ||||||
|  | |||||||
| @ -5,11 +5,7 @@ import path from 'path'; | |||||||
| const fakeSourcesDirForTesting = path.join( | const fakeSourcesDirForTesting = path.join( | ||||||
|   __dirname, |   __dirname, | ||||||
|   'runner', |   'runner', | ||||||
|   path.join( |   path.join(Math.random().toString(36).substring(7)), | ||||||
|     Math.random() |  | ||||||
|       .toString(36) |  | ||||||
|       .substring(7) |  | ||||||
|   ), |  | ||||||
|   's' |   's' | ||||||
| ); | ); | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										1025
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1025
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										37
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										37
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							| @ -1,12 +1,12 @@ | |||||||
| { | { | ||||||
|   "name": "setup-dotnet", |   "name": "setup-dotnet", | ||||||
|   "version": "3.0.1", |   "version": "3.0.2", | ||||||
|   "lockfileVersion": 2, |   "lockfileVersion": 2, | ||||||
|   "requires": true, |   "requires": true, | ||||||
|   "packages": { |   "packages": { | ||||||
|     "": { |     "": { | ||||||
|       "name": "setup-dotnet", |       "name": "setup-dotnet", | ||||||
|       "version": "3.0.1", |       "version": "3.0.2", | ||||||
|       "license": "MIT", |       "license": "MIT", | ||||||
|       "dependencies": { |       "dependencies": { | ||||||
|         "@actions/core": "^1.10.0", |         "@actions/core": "^1.10.0", | ||||||
| @ -26,9 +26,9 @@ | |||||||
|         "husky": "^8.0.1", |         "husky": "^8.0.1", | ||||||
|         "jest": "^27.2.5", |         "jest": "^27.2.5", | ||||||
|         "jest-circus": "^27.2.5", |         "jest-circus": "^27.2.5", | ||||||
|         "prettier": "^1.19.1", |         "prettier": "^2.7.1", | ||||||
|         "ts-jest": "^27.0.5", |         "ts-jest": "^27.0.5", | ||||||
|         "typescript": "^3.9.7", |         "typescript": "^4.8.4", | ||||||
|         "wget-improved": "^3.2.1" |         "wget-improved": "^3.2.1" | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
| @ -3883,15 +3883,18 @@ | |||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     "node_modules/prettier": { |     "node_modules/prettier": { | ||||||
|       "version": "1.19.1", |       "version": "2.7.1", | ||||||
|       "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz", |       "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz", | ||||||
|       "integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==", |       "integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==", | ||||||
|       "dev": true, |       "dev": true, | ||||||
|       "bin": { |       "bin": { | ||||||
|         "prettier": "bin-prettier.js" |         "prettier": "bin-prettier.js" | ||||||
|       }, |       }, | ||||||
|       "engines": { |       "engines": { | ||||||
|         "node": ">=4" |         "node": ">=10.13.0" | ||||||
|  |       }, | ||||||
|  |       "funding": { | ||||||
|  |         "url": "https://github.com/prettier/prettier?sponsor=1" | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     "node_modules/pretty-format": { |     "node_modules/pretty-format": { | ||||||
| @ -4430,9 +4433,9 @@ | |||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     "node_modules/typescript": { |     "node_modules/typescript": { | ||||||
|       "version": "3.9.7", |       "version": "4.8.4", | ||||||
|       "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.7.tgz", |       "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.4.tgz", | ||||||
|       "integrity": "sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==", |       "integrity": "sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==", | ||||||
|       "dev": true, |       "dev": true, | ||||||
|       "bin": { |       "bin": { | ||||||
|         "tsc": "bin/tsc", |         "tsc": "bin/tsc", | ||||||
| @ -7723,9 +7726,9 @@ | |||||||
|       "dev": true |       "dev": true | ||||||
|     }, |     }, | ||||||
|     "prettier": { |     "prettier": { | ||||||
|       "version": "1.19.1", |       "version": "2.7.1", | ||||||
|       "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz", |       "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz", | ||||||
|       "integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==", |       "integrity": "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==", | ||||||
|       "dev": true |       "dev": true | ||||||
|     }, |     }, | ||||||
|     "pretty-format": { |     "pretty-format": { | ||||||
| @ -8123,9 +8126,9 @@ | |||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     "typescript": { |     "typescript": { | ||||||
|       "version": "3.9.7", |       "version": "4.8.4", | ||||||
|       "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.7.tgz", |       "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.4.tgz", | ||||||
|       "integrity": "sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==", |       "integrity": "sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==", | ||||||
|       "dev": true |       "dev": true | ||||||
|     }, |     }, | ||||||
|     "universal-user-agent": { |     "universal-user-agent": { | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
| { | { | ||||||
|   "name": "setup-dotnet", |   "name": "setup-dotnet", | ||||||
|   "version": "3.0.1", |   "version": "3.0.2", | ||||||
|   "private": true, |   "private": true, | ||||||
|   "description": "setup dotnet action", |   "description": "setup dotnet action", | ||||||
|   "main": "lib/setup-dotnet.js", |   "main": "lib/setup-dotnet.js", | ||||||
| @ -41,9 +41,9 @@ | |||||||
|     "husky": "^8.0.1", |     "husky": "^8.0.1", | ||||||
|     "jest": "^27.2.5", |     "jest": "^27.2.5", | ||||||
|     "jest-circus": "^27.2.5", |     "jest-circus": "^27.2.5", | ||||||
|     "prettier": "^1.19.1", |     "prettier": "^2.7.1", | ||||||
|     "ts-jest": "^27.0.5", |     "ts-jest": "^27.0.5", | ||||||
|     "typescript": "^3.9.7", |     "typescript": "^4.8.4", | ||||||
|     "wget-improved": "^3.2.1" |     "wget-improved": "^3.2.1" | ||||||
|   }, |   }, | ||||||
|   "jest": { |   "jest": { | ||||||
|  | |||||||
| @ -6,6 +6,7 @@ import * as hc from '@actions/http-client'; | |||||||
| import {chmodSync} from 'fs'; | import {chmodSync} from 'fs'; | ||||||
| import {readdir} from 'fs/promises'; | import {readdir} from 'fs/promises'; | ||||||
| import path from 'path'; | import path from 'path'; | ||||||
|  | import os from 'os'; | ||||||
| import semver from 'semver'; | import semver from 'semver'; | ||||||
| import {IS_LINUX, IS_WINDOWS} from './utils'; | import {IS_LINUX, IS_WINDOWS} from './utils'; | ||||||
| import {QualityOptions} from './setup-dotnet'; | import {QualityOptions} from './setup-dotnet'; | ||||||
| @ -112,40 +113,29 @@ export class DotnetVersionResolver { | |||||||
| export class DotnetCoreInstaller { | export class DotnetCoreInstaller { | ||||||
|   private version: string; |   private version: string; | ||||||
|   private quality: QualityOptions; |   private quality: QualityOptions; | ||||||
|   private static readonly installationDirectoryWindows = path.join( |  | ||||||
|     process.env['PROGRAMFILES'] + '', |  | ||||||
|     'dotnet' |  | ||||||
|   ); |  | ||||||
|   private static readonly installationDirectoryLinux = '/usr/share/dotnet'; |  | ||||||
|   private static readonly installationDirectoryMac = path.join( |  | ||||||
|     process.env['HOME'] + '', |  | ||||||
|     '.dotnet' |  | ||||||
|   ); |  | ||||||
| 
 | 
 | ||||||
|   static addToPath() { |   static { | ||||||
|     if (process.env['DOTNET_INSTALL_DIR']) { |     const installationDirectoryWindows = path.join( | ||||||
|       core.addPath(process.env['DOTNET_INSTALL_DIR']); |       process.env['PROGRAMFILES'] + '', | ||||||
|       core.exportVariable('DOTNET_ROOT', process.env['DOTNET_INSTALL_DIR']); |       'dotnet' | ||||||
|  |     ); | ||||||
|  |     const installationDirectoryLinux = '/usr/share/dotnet'; | ||||||
|  |     const installationDirectoryMac = path.join( | ||||||
|  |       process.env['HOME'] + '', | ||||||
|  |       '.dotnet' | ||||||
|  |     ); | ||||||
|  |     const dotnetInstallDir: string | undefined = | ||||||
|  |       process.env['DOTNET_INSTALL_DIR']; | ||||||
|  |     if (dotnetInstallDir) { | ||||||
|  |       process.env['DOTNET_INSTALL_DIR'] = | ||||||
|  |         this.convertInstallPathToAbsolute(dotnetInstallDir); | ||||||
|     } else { |     } else { | ||||||
|       if (IS_WINDOWS) { |       if (IS_WINDOWS) { | ||||||
|         core.addPath(DotnetCoreInstaller.installationDirectoryWindows); |         process.env['DOTNET_INSTALL_DIR'] = installationDirectoryWindows; | ||||||
|         core.exportVariable( |  | ||||||
|           'DOTNET_ROOT', |  | ||||||
|           DotnetCoreInstaller.installationDirectoryWindows |  | ||||||
|         ); |  | ||||||
|       } else if (IS_LINUX) { |  | ||||||
|         core.addPath(DotnetCoreInstaller.installationDirectoryLinux); |  | ||||||
|         core.exportVariable( |  | ||||||
|           'DOTNET_ROOT', |  | ||||||
|           DotnetCoreInstaller.installationDirectoryLinux |  | ||||||
|         ); |  | ||||||
|       } else { |       } else { | ||||||
|         // This is the default set in install-dotnet.sh
 |         process.env['DOTNET_INSTALL_DIR'] = IS_LINUX | ||||||
|         core.addPath(DotnetCoreInstaller.installationDirectoryMac); |           ? installationDirectoryLinux | ||||||
|         core.exportVariable( |           : installationDirectoryMac; | ||||||
|           'DOTNET_ROOT', |  | ||||||
|           DotnetCoreInstaller.installationDirectoryMac |  | ||||||
|         ); |  | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| @ -155,6 +145,23 @@ export class DotnetCoreInstaller { | |||||||
|     this.quality = quality; |     this.quality = quality; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   private static convertInstallPathToAbsolute(installDir: string): string { | ||||||
|  |     let transformedPath; | ||||||
|  |     if (path.isAbsolute(installDir)) { | ||||||
|  |       transformedPath = installDir; | ||||||
|  |     } else { | ||||||
|  |       transformedPath = installDir.startsWith('~') | ||||||
|  |         ? path.join(os.homedir(), installDir.slice(1)) | ||||||
|  |         : (transformedPath = path.join(process.cwd(), installDir)); | ||||||
|  |     } | ||||||
|  |     return path.normalize(transformedPath); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   static addToPath() { | ||||||
|  |     core.addPath(process.env['DOTNET_INSTALL_DIR']!); | ||||||
|  |     core.exportVariable('DOTNET_ROOT', process.env['DOTNET_INSTALL_DIR']); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   private setQuality( |   private setQuality( | ||||||
|     dotnetVersion: DotnetVersion, |     dotnetVersion: DotnetVersion, | ||||||
|     scriptArguments: string[] |     scriptArguments: string[] | ||||||
| @ -208,11 +215,6 @@ export class DotnetCoreInstaller { | |||||||
|         scriptArguments.push(`-ProxyBypassList ${process.env['no_proxy']}`); |         scriptArguments.push(`-ProxyBypassList ${process.env['no_proxy']}`); | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       if (!process.env['DOTNET_INSTALL_DIR']) { |  | ||||||
|         process.env['DOTNET_INSTALL_DIR'] = |  | ||||||
|           DotnetCoreInstaller.installationDirectoryWindows; |  | ||||||
|       } |  | ||||||
| 
 |  | ||||||
|       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); | ||||||
| @ -228,12 +230,6 @@ export class DotnetCoreInstaller { | |||||||
|       if (this.quality) { |       if (this.quality) { | ||||||
|         this.setQuality(dotnetVersion, scriptArguments); |         this.setQuality(dotnetVersion, scriptArguments); | ||||||
|       } |       } | ||||||
| 
 |  | ||||||
|       if (!process.env['DOTNET_INSTALL_DIR']) { |  | ||||||
|         process.env['DOTNET_INSTALL_DIR'] = IS_LINUX |  | ||||||
|           ? DotnetCoreInstaller.installationDirectoryLinux |  | ||||||
|           : DotnetCoreInstaller.installationDirectoryMac; |  | ||||||
|       } |  | ||||||
|     } |     } | ||||||
|     // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
 |     // process.env must be explicitly passed in for DOTNET_INSTALL_DIR to be used
 | ||||||
|     const getExecOutputOptions = { |     const getExecOutputOptions = { | ||||||
| @ -249,16 +245,11 @@ export class DotnetCoreInstaller { | |||||||
|       throw new Error(`Failed to install dotnet ${exitCode}. ${stdout}`); |       throw new Error(`Failed to install dotnet ${exitCode}. ${stdout}`); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return this.outputDotnetVersion( |     return this.outputDotnetVersion(dotnetVersion.value); | ||||||
|       dotnetVersion.value, |  | ||||||
|       process.env['DOTNET_INSTALL_DIR'] |  | ||||||
|     ); |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   private async outputDotnetVersion( |   private async outputDotnetVersion(version): Promise<string> { | ||||||
|     version, |     const installationPath = process.env['DOTNET_INSTALL_DIR']!; | ||||||
|     installationPath |  | ||||||
|   ): Promise<string> { |  | ||||||
|     let versionsOnRunner: string[] = await readdir( |     let versionsOnRunner: string[] = await readdir( | ||||||
|       path.join(installationPath.replace(/'/g, ''), 'sdk') |       path.join(installationPath.replace(/'/g, ''), 'sdk') | ||||||
|     ); |     ); | ||||||
|  | |||||||
| @ -35,6 +35,7 @@ | |||||||
|     // "alwaysStrict": true,                  /* Parse in strict mode and emit "use strict" for each source file. */ |     // "alwaysStrict": true,                  /* Parse in strict mode and emit "use strict" for each source file. */ | ||||||
| 
 | 
 | ||||||
|     /* Additional Checks */ |     /* Additional Checks */ | ||||||
|  |     "useUnknownInCatchVariables": false,               /* Type catch clause variables as 'unknown' instead of 'any'. */ | ||||||
|     // "noUnusedLocals": true,                /* Report errors on unused locals. */ |     // "noUnusedLocals": true,                /* Report errors on unused locals. */ | ||||||
|     // "noUnusedParameters": true,            /* Report errors on unused parameters. */ |     // "noUnusedParameters": true,            /* Report errors on unused parameters. */ | ||||||
|     // "noImplicitReturns": true,             /* Report error when not all code paths in function return a value. */ |     // "noImplicitReturns": true,             /* Report error when not all code paths in function return a value. */ | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Ivan
						Ivan