You've already forked setup-python
							
							
				mirror of
				https://github.com/actions/setup-python.git
				synced 2025-10-31 15:16:23 +07:00 
			
		
		
		
	Handle download HTTP error (#511)
This commit is contained in:
		| @ -46,37 +46,58 @@ export async function installPyPy( | ||||
|   let downloadUrl = `${foundAsset.download_url}`; | ||||
|  | ||||
|   core.info(`Downloading PyPy from "${downloadUrl}" ...`); | ||||
|   const pypyPath = await tc.downloadTool(downloadUrl); | ||||
|  | ||||
|   core.info('Extracting downloaded archive...'); | ||||
|   if (IS_WINDOWS) { | ||||
|     downloadDir = await tc.extractZip(pypyPath); | ||||
|   } else { | ||||
|     downloadDir = await tc.extractTar(pypyPath, undefined, 'x'); | ||||
|   try { | ||||
|     const pypyPath = await tc.downloadTool(downloadUrl); | ||||
|  | ||||
|     core.info('Extracting downloaded archive...'); | ||||
|     if (IS_WINDOWS) { | ||||
|       downloadDir = await tc.extractZip(pypyPath); | ||||
|     } else { | ||||
|       downloadDir = await tc.extractTar(pypyPath, undefined, 'x'); | ||||
|     } | ||||
|  | ||||
|     // root folder in archive can have unpredictable name so just take the first folder | ||||
|     // downloadDir is unique folder under TEMP and can't contain any other folders | ||||
|     const archiveName = fs.readdirSync(downloadDir)[0]; | ||||
|  | ||||
|     const toolDir = path.join(downloadDir, archiveName); | ||||
|     let installDir = toolDir; | ||||
|     if (!isNightlyKeyword(resolvedPyPyVersion)) { | ||||
|       installDir = await tc.cacheDir( | ||||
|         toolDir, | ||||
|         'PyPy', | ||||
|         resolvedPythonVersion, | ||||
|         architecture | ||||
|       ); | ||||
|     } | ||||
|  | ||||
|     writeExactPyPyVersionFile(installDir, resolvedPyPyVersion); | ||||
|  | ||||
|     const binaryPath = getPyPyBinaryPath(installDir); | ||||
|     await createPyPySymlink(binaryPath, resolvedPythonVersion); | ||||
|     await installPip(binaryPath); | ||||
|  | ||||
|     return {installDir, resolvedPythonVersion, resolvedPyPyVersion}; | ||||
|   } catch (err) { | ||||
|     if (err instanceof Error) { | ||||
|       // Rate limit? | ||||
|       if ( | ||||
|         err instanceof tc.HTTPError && | ||||
|         (err.httpStatusCode === 403 || err.httpStatusCode === 429) | ||||
|       ) { | ||||
|         core.info( | ||||
|           `Received HTTP status code ${err.httpStatusCode}.  This usually indicates the rate limit has been exceeded` | ||||
|         ); | ||||
|       } else { | ||||
|         core.info(err.message); | ||||
|       } | ||||
|       if (err.stack !== undefined) { | ||||
|         core.debug(err.stack); | ||||
|       } | ||||
|     } | ||||
|     throw err; | ||||
|   } | ||||
|  | ||||
|   // root folder in archive can have unpredictable name so just take the first folder | ||||
|   // downloadDir is unique folder under TEMP and can't contain any other folders | ||||
|   const archiveName = fs.readdirSync(downloadDir)[0]; | ||||
|  | ||||
|   const toolDir = path.join(downloadDir, archiveName); | ||||
|   let installDir = toolDir; | ||||
|   if (!isNightlyKeyword(resolvedPyPyVersion)) { | ||||
|     installDir = await tc.cacheDir( | ||||
|       toolDir, | ||||
|       'PyPy', | ||||
|       resolvedPythonVersion, | ||||
|       architecture | ||||
|     ); | ||||
|   } | ||||
|  | ||||
|   writeExactPyPyVersionFile(installDir, resolvedPyPyVersion); | ||||
|  | ||||
|   const binaryPath = getPyPyBinaryPath(installDir); | ||||
|   await createPyPySymlink(binaryPath, resolvedPythonVersion); | ||||
|   await installPip(binaryPath); | ||||
|  | ||||
|   return {installDir, resolvedPythonVersion, resolvedPyPyVersion}; | ||||
| } | ||||
|  | ||||
| export async function getAvailablePyPyVersions() { | ||||
|  | ||||
| @ -72,15 +72,33 @@ export async function installCpythonFromRelease(release: tc.IToolRelease) { | ||||
|   const downloadUrl = release.files[0].download_url; | ||||
|  | ||||
|   core.info(`Download from "${downloadUrl}"`); | ||||
|   const pythonPath = await tc.downloadTool(downloadUrl, undefined, AUTH); | ||||
|   core.info('Extract downloaded archive'); | ||||
|   let pythonExtractedFolder; | ||||
|   if (IS_WINDOWS) { | ||||
|     pythonExtractedFolder = await tc.extractZip(pythonPath); | ||||
|   } else { | ||||
|     pythonExtractedFolder = await tc.extractTar(pythonPath); | ||||
|   } | ||||
|   let pythonPath = ''; | ||||
|   try { | ||||
|     pythonPath = await tc.downloadTool(downloadUrl, undefined, AUTH); | ||||
|     core.info('Extract downloaded archive'); | ||||
|     let pythonExtractedFolder; | ||||
|     if (IS_WINDOWS) { | ||||
|       pythonExtractedFolder = await tc.extractZip(pythonPath); | ||||
|     } else { | ||||
|       pythonExtractedFolder = await tc.extractTar(pythonPath); | ||||
|     } | ||||
|  | ||||
|   core.info('Execute installation script'); | ||||
|   await installPython(pythonExtractedFolder); | ||||
|     core.info('Execute installation script'); | ||||
|     await installPython(pythonExtractedFolder); | ||||
|   } catch (err) { | ||||
|     if (err instanceof tc.HTTPError) { | ||||
|       // Rate limit? | ||||
|       if (err.httpStatusCode === 403 || err.httpStatusCode === 429) { | ||||
|         core.info( | ||||
|           `Received HTTP status code ${err.httpStatusCode}.  This usually indicates the rate limit has been exceeded` | ||||
|         ); | ||||
|       } else { | ||||
|         core.info(err.message); | ||||
|       } | ||||
|       if (err.stack) { | ||||
|         core.debug(err.stack); | ||||
|       } | ||||
|     } | ||||
|     throw err; | ||||
|   } | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Sergey Dolin
					Sergey Dolin