mirror of
				https://github.com/actions/setup-go.git
				synced 2025-10-31 15:33:41 +00:00 
			
		
		
		
	Add manifest validation and improve error handling (#586)
This commit is contained in:
		
							parent
							
								
									78535dd5f2
								
							
						
					
					
						commit
						29694d72cd
					
				
							
								
								
									
										25
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										25
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							| @ -93475,10 +93475,33 @@ function extractGoArchive(archivePath) { | |||||||
|     }); |     }); | ||||||
| } | } | ||||||
| exports.extractGoArchive = extractGoArchive; | exports.extractGoArchive = extractGoArchive; | ||||||
|  | function isIToolRelease(obj) { | ||||||
|  |     return (typeof obj === 'object' && | ||||||
|  |         obj !== null && | ||||||
|  |         typeof obj.version === 'string' && | ||||||
|  |         typeof obj.stable === 'boolean' && | ||||||
|  |         Array.isArray(obj.files) && | ||||||
|  |         obj.files.every((file) => typeof file.filename === 'string' && | ||||||
|  |             typeof file.platform === 'string' && | ||||||
|  |             typeof file.arch === 'string' && | ||||||
|  |             typeof file.download_url === 'string')); | ||||||
|  | } | ||||||
| function getManifest(auth) { | function getManifest(auth) { | ||||||
|     return __awaiter(this, void 0, void 0, function* () { |     return __awaiter(this, void 0, void 0, function* () { | ||||||
|         try { |         try { | ||||||
|             return yield getManifestFromRepo(auth); |             const manifest = yield getManifestFromRepo(auth); | ||||||
|  |             if (Array.isArray(manifest) && | ||||||
|  |                 manifest.length && | ||||||
|  |                 manifest.every(isIToolRelease)) { | ||||||
|  |                 return manifest; | ||||||
|  |             } | ||||||
|  |             let errorMessage = 'An unexpected error occurred while fetching the manifest.'; | ||||||
|  |             if (typeof manifest === 'object' && | ||||||
|  |                 manifest !== null && | ||||||
|  |                 'message' in manifest) { | ||||||
|  |                 errorMessage = manifest.message; | ||||||
|  |             } | ||||||
|  |             throw new Error(errorMessage); | ||||||
|         } |         } | ||||||
|         catch (err) { |         catch (err) { | ||||||
|             core.debug('Fetching the manifest via the API failed.'); |             core.debug('Fetching the manifest via the API failed.'); | ||||||
|  | |||||||
| @ -275,11 +275,46 @@ export async function extractGoArchive(archivePath: string): Promise<string> { | |||||||
|   return extPath; |   return extPath; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | function isIToolRelease(obj: any): obj is tc.IToolRelease { | ||||||
|  |   return ( | ||||||
|  |     typeof obj === 'object' && | ||||||
|  |     obj !== null && | ||||||
|  |     typeof obj.version === 'string' && | ||||||
|  |     typeof obj.stable === 'boolean' && | ||||||
|  |     Array.isArray(obj.files) && | ||||||
|  |     obj.files.every( | ||||||
|  |       (file: any) => | ||||||
|  |         typeof file.filename === 'string' && | ||||||
|  |         typeof file.platform === 'string' && | ||||||
|  |         typeof file.arch === 'string' && | ||||||
|  |         typeof file.download_url === 'string' | ||||||
|  |     ) | ||||||
|  |   ); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| export async function getManifest( | export async function getManifest( | ||||||
|   auth: string | undefined |   auth: string | undefined | ||||||
| ): Promise<tc.IToolRelease[]> { | ): Promise<tc.IToolRelease[]> { | ||||||
|   try { |   try { | ||||||
|     return await getManifestFromRepo(auth); |     const manifest = await getManifestFromRepo(auth); | ||||||
|  |     if ( | ||||||
|  |       Array.isArray(manifest) && | ||||||
|  |       manifest.length && | ||||||
|  |       manifest.every(isIToolRelease) | ||||||
|  |     ) { | ||||||
|  |       return manifest; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     let errorMessage = | ||||||
|  |       'An unexpected error occurred while fetching the manifest.'; | ||||||
|  |     if ( | ||||||
|  |       typeof manifest === 'object' && | ||||||
|  |       manifest !== null && | ||||||
|  |       'message' in manifest | ||||||
|  |     ) { | ||||||
|  |       errorMessage = (manifest as {message: string}).message; | ||||||
|  |     } | ||||||
|  |     throw new Error(errorMessage); | ||||||
|   } catch (err) { |   } catch (err) { | ||||||
|     core.debug('Fetching the manifest via the API failed.'); |     core.debug('Fetching the manifest via the API failed.'); | ||||||
|     if (err instanceof Error) { |     if (err instanceof Error) { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user