mirror of
				https://github.com/actions/setup-node.git
				synced 2025-10-31 16:14:00 +08:00 
			
		
		
		
	Print node, npm and yarn versions after installation (#368)
This commit is contained in:
		 Uladzimir Havenchyk
					Uladzimir Havenchyk
				
			
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			 GitHub
						GitHub
					
				
			
						parent
						
							c96ab56c5b
						
					
				
				
					commit
					c81d8ad96d
				
			
							
								
								
									
										48
									
								
								src/main.ts
									
									
									
									
									
								
							
							
						
						
									
										48
									
								
								src/main.ts
									
									
									
									
									
								
							| @@ -40,17 +40,7 @@ export async function run() { | ||||
|       await installer.getNode(version, stable, checkLatest, auth, arch); | ||||
|     } | ||||
|  | ||||
|     // Output version of node is being used | ||||
|     try { | ||||
|       const {stdout: installedVersion} = await exec.getExecOutput( | ||||
|         'node', | ||||
|         ['--version'], | ||||
|         {ignoreReturnCode: true, silent: true} | ||||
|       ); | ||||
|       core.setOutput('node-version', installedVersion.trim()); | ||||
|     } catch (err) { | ||||
|       core.setOutput('node-version', ''); | ||||
|     } | ||||
|     await printEnvDetailsAndSetOutput(); | ||||
|  | ||||
|     const registryUrl: string = core.getInput('registry-url'); | ||||
|     const alwaysAuth: string = core.getInput('always-auth'); | ||||
| @@ -111,3 +101,39 @@ function resolveVersionInput(): string { | ||||
|  | ||||
|   return version; | ||||
| } | ||||
|  | ||||
| export async function printEnvDetailsAndSetOutput() { | ||||
|   core.startGroup('Environment details'); | ||||
|  | ||||
|   const promises = ['node', 'npm', 'yarn'].map(async tool => { | ||||
|     const output = await getToolVersion(tool, ['--version']); | ||||
|  | ||||
|     if (tool === 'node') { | ||||
|       core.setOutput(`${tool}-version`, output); | ||||
|     } | ||||
|  | ||||
|     core.info(`${tool}: ${output}`); | ||||
|   }); | ||||
|  | ||||
|   await Promise.all(promises); | ||||
|  | ||||
|   core.endGroup(); | ||||
| } | ||||
|  | ||||
| async function getToolVersion(tool: string, options: string[]) { | ||||
|   try { | ||||
|     const {stdout, stderr, exitCode} = await exec.getExecOutput(tool, options, { | ||||
|       ignoreReturnCode: true, | ||||
|       silent: true | ||||
|     }); | ||||
|  | ||||
|     if (exitCode > 0) { | ||||
|       core.warning(`[warning]${stderr}`); | ||||
|       return ''; | ||||
|     } | ||||
|  | ||||
|     return stdout; | ||||
|   } catch (err) { | ||||
|     return ''; | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user