mirror of
				https://github.com/actions/setup-node.git
				synced 2025-10-31 16:14:00 +08:00 
			
		
		
		
	Merge branch 'main' of github.com:actions/setup-node into main
This commit is contained in:
		| @@ -20,6 +20,7 @@ export interface INodeVersion { | ||||
| interface INodeVersionInfo { | ||||
|   downloadUrl: string; | ||||
|   resolvedVersion: string; | ||||
|   arch: string; | ||||
|   fileName: string; | ||||
| } | ||||
|  | ||||
| @@ -27,17 +28,19 @@ export async function getNode( | ||||
|   versionSpec: string, | ||||
|   stable: boolean, | ||||
|   checkLatest: boolean, | ||||
|   auth: string | undefined | ||||
|   auth: string | undefined, | ||||
|   arch: string = os.arch() | ||||
| ) { | ||||
|   let osPlat: string = os.platform(); | ||||
|   let osArch: string = translateArchToDistUrl(os.arch()); | ||||
|   let osArch: string = translateArchToDistUrl(arch); | ||||
|  | ||||
|   if (checkLatest) { | ||||
|     core.info('Attempt to resolve the latest version from manifest...'); | ||||
|     const resolvedVersion = await resolveVersionFromManifest( | ||||
|       versionSpec, | ||||
|       stable, | ||||
|       auth | ||||
|       auth, | ||||
|       osArch | ||||
|     ); | ||||
|     if (resolvedVersion) { | ||||
|       versionSpec = resolvedVersion; | ||||
| @@ -49,7 +52,7 @@ export async function getNode( | ||||
|  | ||||
|   // check cache | ||||
|   let toolPath: string; | ||||
|   toolPath = tc.find('node', versionSpec); | ||||
|   toolPath = tc.find('node', versionSpec, osArch); | ||||
|  | ||||
|   // If not found in cache, download | ||||
|   if (toolPath) { | ||||
| @@ -63,9 +66,11 @@ export async function getNode( | ||||
|     // Try download from internal distribution (popular versions only) | ||||
|     // | ||||
|     try { | ||||
|       info = await getInfoFromManifest(versionSpec, stable, auth); | ||||
|       info = await getInfoFromManifest(versionSpec, stable, auth, osArch); | ||||
|       if (info) { | ||||
|         core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`); | ||||
|         core.info( | ||||
|           `Acquiring ${info.resolvedVersion} - ${info.arch} from ${info.downloadUrl}` | ||||
|         ); | ||||
|         downloadPath = await tc.downloadTool(info.downloadUrl, undefined, auth); | ||||
|       } else { | ||||
|         core.info( | ||||
| @@ -92,19 +97,24 @@ export async function getNode( | ||||
|     // Download from nodejs.org | ||||
|     // | ||||
|     if (!downloadPath) { | ||||
|       info = await getInfoFromDist(versionSpec); | ||||
|       info = await getInfoFromDist(versionSpec, arch); | ||||
|       if (!info) { | ||||
|         throw new Error( | ||||
|           `Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.` | ||||
|         ); | ||||
|       } | ||||
|  | ||||
|       core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`); | ||||
|       core.info( | ||||
|         `Acquiring ${info.resolvedVersion} - ${info.arch} from ${info.downloadUrl}` | ||||
|       ); | ||||
|       try { | ||||
|         downloadPath = await tc.downloadTool(info.downloadUrl); | ||||
|       } catch (err) { | ||||
|         if (err instanceof tc.HTTPError && err.httpStatusCode == 404) { | ||||
|           return await acquireNodeFromFallbackLocation(info.resolvedVersion); | ||||
|           return await acquireNodeFromFallbackLocation( | ||||
|             info.resolvedVersion, | ||||
|             info.arch | ||||
|           ); | ||||
|         } | ||||
|  | ||||
|         throw err; | ||||
| @@ -137,7 +147,12 @@ export async function getNode( | ||||
|     // Install into the local tool cache - node extracts with a root folder that matches the fileName downloaded | ||||
|     // | ||||
|     core.info('Adding to the cache ...'); | ||||
|     toolPath = await tc.cacheDir(extPath, 'node', info.resolvedVersion); | ||||
|     toolPath = await tc.cacheDir( | ||||
|       extPath, | ||||
|       'node', | ||||
|       info.resolvedVersion, | ||||
|       info.arch | ||||
|     ); | ||||
|     core.info('Done'); | ||||
|   } | ||||
|  | ||||
| @@ -158,7 +173,8 @@ export async function getNode( | ||||
| async function getInfoFromManifest( | ||||
|   versionSpec: string, | ||||
|   stable: boolean, | ||||
|   auth: string | undefined | ||||
|   auth: string | undefined, | ||||
|   osArch: string = translateArchToDistUrl(os.arch()) | ||||
| ): Promise<INodeVersionInfo | null> { | ||||
|   let info: INodeVersionInfo | null = null; | ||||
|   const releases = await tc.getManifestFromRepo( | ||||
| @@ -167,11 +183,12 @@ async function getInfoFromManifest( | ||||
|     auth, | ||||
|     'main' | ||||
|   ); | ||||
|   const rel = await tc.findFromManifest(versionSpec, stable, releases); | ||||
|   const rel = await tc.findFromManifest(versionSpec, stable, releases, osArch); | ||||
|  | ||||
|   if (rel && rel.files.length > 0) { | ||||
|     info = <INodeVersionInfo>{}; | ||||
|     info.resolvedVersion = rel.version; | ||||
|     info.arch = rel.files[0].arch; | ||||
|     info.downloadUrl = rel.files[0].download_url; | ||||
|     info.fileName = rel.files[0].filename; | ||||
|   } | ||||
| @@ -180,14 +197,15 @@ async function getInfoFromManifest( | ||||
| } | ||||
|  | ||||
| async function getInfoFromDist( | ||||
|   versionSpec: string | ||||
|   versionSpec: string, | ||||
|   arch: string = os.arch() | ||||
| ): Promise<INodeVersionInfo | null> { | ||||
|   let osPlat: string = os.platform(); | ||||
|   let osArch: string = translateArchToDistUrl(os.arch()); | ||||
|   let osArch: string = translateArchToDistUrl(arch); | ||||
|  | ||||
|   let version: string; | ||||
|  | ||||
|   version = await queryDistForMatch(versionSpec); | ||||
|   version = await queryDistForMatch(versionSpec, arch); | ||||
|   if (!version) { | ||||
|     return null; | ||||
|   } | ||||
| @@ -207,6 +225,7 @@ async function getInfoFromDist( | ||||
|   return <INodeVersionInfo>{ | ||||
|     downloadUrl: url, | ||||
|     resolvedVersion: version, | ||||
|     arch: arch, | ||||
|     fileName: fileName | ||||
|   }; | ||||
| } | ||||
| @@ -214,10 +233,11 @@ async function getInfoFromDist( | ||||
| async function resolveVersionFromManifest( | ||||
|   versionSpec: string, | ||||
|   stable: boolean, | ||||
|   auth: string | undefined | ||||
|   auth: string | undefined, | ||||
|   osArch: string = translateArchToDistUrl(os.arch()) | ||||
| ): Promise<string | undefined> { | ||||
|   try { | ||||
|     const info = await getInfoFromManifest(versionSpec, stable, auth); | ||||
|     const info = await getInfoFromManifest(versionSpec, stable, auth, osArch); | ||||
|     return info?.resolvedVersion; | ||||
|   } catch (err) { | ||||
|     core.info('Unable to resolve version from manifest...'); | ||||
| @@ -253,9 +273,12 @@ function evaluateVersions(versions: string[], versionSpec: string): string { | ||||
|   return version; | ||||
| } | ||||
|  | ||||
| async function queryDistForMatch(versionSpec: string): Promise<string> { | ||||
| async function queryDistForMatch( | ||||
|   versionSpec: string, | ||||
|   arch: string = os.arch() | ||||
| ): Promise<string> { | ||||
|   let osPlat: string = os.platform(); | ||||
|   let osArch: string = translateArchToDistUrl(os.arch()); | ||||
|   let osArch: string = translateArchToDistUrl(arch); | ||||
|  | ||||
|   // node offers a json list of versions | ||||
|   let dataFileName: string; | ||||
| @@ -311,10 +334,11 @@ export async function getVersionsFromDist(): Promise<INodeVersion[]> { | ||||
| // Note also that the files are normally zipped but in this case they are just an exe | ||||
| // and lib file in a folder, not zipped. | ||||
| async function acquireNodeFromFallbackLocation( | ||||
|   version: string | ||||
|   version: string, | ||||
|   arch: string = os.arch() | ||||
| ): Promise<string> { | ||||
|   let osPlat: string = os.platform(); | ||||
|   let osArch: string = translateArchToDistUrl(os.arch()); | ||||
|   let osArch: string = translateArchToDistUrl(arch); | ||||
|  | ||||
|   // Create temporary folder to download in to | ||||
|   const tempDownloadFolder: string = | ||||
| @@ -348,7 +372,7 @@ async function acquireNodeFromFallbackLocation( | ||||
|       throw err; | ||||
|     } | ||||
|   } | ||||
|   let toolPath = await tc.cacheDir(tempDir, 'node', version); | ||||
|   let toolPath = await tc.cacheDir(tempDir, 'node', version, arch); | ||||
|   core.addPath(toolPath); | ||||
|   return toolPath; | ||||
| } | ||||
|   | ||||
							
								
								
									
										17
									
								
								src/main.ts
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								src/main.ts
									
									
									
									
									
								
							| @@ -3,6 +3,7 @@ import * as installer from './installer'; | ||||
| import * as auth from './authutil'; | ||||
| import * as path from 'path'; | ||||
| import {URL} from 'url'; | ||||
| import os = require('os'); | ||||
|  | ||||
| export async function run() { | ||||
|   try { | ||||
| @@ -15,13 +16,27 @@ export async function run() { | ||||
|       version = core.getInput('version'); | ||||
|     } | ||||
|  | ||||
|     let arch = core.getInput('architecture'); | ||||
|  | ||||
|     // if architecture supplied but node-version is not | ||||
|     // if we don't throw a warning, the already installed x64 node will be used which is not probably what user meant. | ||||
|     if (arch && !version) { | ||||
|       core.warning( | ||||
|         '`architecture` is provided but `node-version` is missing. In this configuration, the version/architecture of Node will not be changed. To fix this, provide `architecture` in combination with `node-version`' | ||||
|       ); | ||||
|     } | ||||
|  | ||||
|     if (!arch) { | ||||
|       arch = os.arch(); | ||||
|     } | ||||
|  | ||||
|     if (version) { | ||||
|       let token = core.getInput('token'); | ||||
|       let auth = !token || isGhes() ? undefined : `token ${token}`; | ||||
|       let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE'; | ||||
|       const checkLatest = | ||||
|         (core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE'; | ||||
|       await installer.getNode(version, stable, checkLatest, auth); | ||||
|       await installer.getNode(version, stable, checkLatest, auth, arch); | ||||
|     } | ||||
|  | ||||
|     const registryUrl: string = core.getInput('registry-url'); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Andres Vargas
					Andres Vargas