mirror of
				https://kkgithub.com/actions/setup-node.git
				synced 2025-10-31 10:41:57 +08:00 
			
		
		
		
	Adding Node.js version file support (#338)
This commit is contained in:
		| @ -371,7 +371,7 @@ async function queryDistForMatch( | ||||
|   } | ||||
|  | ||||
|   let versions: string[] = []; | ||||
|   let nodeVersions = await module.exports.getVersionsFromDist(); | ||||
|   let nodeVersions = await getVersionsFromDist(); | ||||
|  | ||||
|   nodeVersions.forEach((nodeVersion: INodeVersion) => { | ||||
|     // ensure this version supports your os and platform | ||||
| @ -464,3 +464,12 @@ function translateArchToDistUrl(arch: string): string { | ||||
|       return arch; | ||||
|   } | ||||
| } | ||||
|  | ||||
| export function parseNodeVersionFile(contents: string): string { | ||||
|   let nodeVersion = contents.trim(); | ||||
|  | ||||
|   if (/^v\d/.test(nodeVersion)) { | ||||
|     nodeVersion = nodeVersion.substring(1); | ||||
|   } | ||||
|   return nodeVersion; | ||||
| } | ||||
|  | ||||
							
								
								
									
										43
									
								
								src/main.ts
									
									
									
									
									
								
							
							
						
						
									
										43
									
								
								src/main.ts
									
									
									
									
									
								
							| @ -1,5 +1,6 @@ | ||||
| import * as core from '@actions/core'; | ||||
| import * as installer from './installer'; | ||||
| import fs from 'fs'; | ||||
| import * as auth from './authutil'; | ||||
| import * as path from 'path'; | ||||
| import {restoreCache} from './cache-restore'; | ||||
| @ -12,10 +13,7 @@ export async function run() { | ||||
|     // Version is optional.  If supplied, install / use from the tool cache | ||||
|     // If not supplied then task is still used to setup proxy, auth, etc... | ||||
|     // | ||||
|     let version = core.getInput('node-version'); | ||||
|     if (!version) { | ||||
|       version = core.getInput('version'); | ||||
|     } | ||||
|     let version = resolveVersionInput(); | ||||
|  | ||||
|     let arch = core.getInput('architecture'); | ||||
|     const cache = core.getInput('cache'); | ||||
| @ -63,8 +61,8 @@ export async function run() { | ||||
|     core.info( | ||||
|       `##[add-matcher]${path.join(matchersPath, 'eslint-compact.json')}` | ||||
|     ); | ||||
|   } catch (error) { | ||||
|     core.setFailed(error.message); | ||||
|   } catch (err) { | ||||
|     core.setFailed(err.message); | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -74,3 +72,36 @@ function isGhes(): boolean { | ||||
|   ); | ||||
|   return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; | ||||
| } | ||||
|  | ||||
| function resolveVersionInput(): string { | ||||
|   let version = core.getInput('node-version') || core.getInput('version'); | ||||
|   const versionFileInput = core.getInput('node-version-file'); | ||||
|  | ||||
|   if (version && versionFileInput) { | ||||
|     core.warning( | ||||
|       'Both node-version and node-version-file inputs are specified, only node-version will be used' | ||||
|     ); | ||||
|   } | ||||
|  | ||||
|   if (version) { | ||||
|     return version; | ||||
|   } | ||||
|  | ||||
|   if (versionFileInput) { | ||||
|     const versionFilePath = path.join( | ||||
|       process.env.GITHUB_WORKSPACE!, | ||||
|       versionFileInput | ||||
|     ); | ||||
|     if (!fs.existsSync(versionFilePath)) { | ||||
|       throw new Error( | ||||
|         `The specified node version file at: ${versionFilePath} does not exist` | ||||
|       ); | ||||
|     } | ||||
|     version = installer.parseNodeVersionFile( | ||||
|       fs.readFileSync(versionFilePath, 'utf8') | ||||
|     ); | ||||
|     core.info(`Resolved ${versionFileInput} as ${version}`); | ||||
|   } | ||||
|  | ||||
|   return version; | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Hargun Kaur
					Hargun Kaur