You've already forked setup-python
							
							
				mirror of
				https://github.com/actions/setup-python.git
				synced 2025-10-26 13:05:13 +07:00 
			
		
		
		
	Handle download HTTP error (#511)
This commit is contained in:
		
							
								
								
									
										38
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										38
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							| @ -66511,6 +66511,7 @@ function installPyPy(pypyVersion, pythonVersion, architecture, releases) { | |||||||
|         const { foundAsset, resolvedPythonVersion, resolvedPyPyVersion } = releaseData; |         const { foundAsset, resolvedPythonVersion, resolvedPyPyVersion } = releaseData; | ||||||
|         let downloadUrl = `${foundAsset.download_url}`; |         let downloadUrl = `${foundAsset.download_url}`; | ||||||
|         core.info(`Downloading PyPy from "${downloadUrl}" ...`); |         core.info(`Downloading PyPy from "${downloadUrl}" ...`); | ||||||
|  |         try { | ||||||
|             const pypyPath = yield tc.downloadTool(downloadUrl); |             const pypyPath = yield tc.downloadTool(downloadUrl); | ||||||
|             core.info('Extracting downloaded archive...'); |             core.info('Extracting downloaded archive...'); | ||||||
|             if (utils_1.IS_WINDOWS) { |             if (utils_1.IS_WINDOWS) { | ||||||
| @ -66532,6 +66533,23 @@ function installPyPy(pypyVersion, pythonVersion, architecture, releases) { | |||||||
|             yield createPyPySymlink(binaryPath, resolvedPythonVersion); |             yield createPyPySymlink(binaryPath, resolvedPythonVersion); | ||||||
|             yield installPip(binaryPath); |             yield installPip(binaryPath); | ||||||
|             return { installDir, resolvedPythonVersion, resolvedPyPyVersion }; |             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; | ||||||
|  |         } | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
| exports.installPyPy = installPyPy; | exports.installPyPy = installPyPy; | ||||||
| @ -66730,7 +66748,9 @@ function installCpythonFromRelease(release) { | |||||||
|     return __awaiter(this, void 0, void 0, function* () { |     return __awaiter(this, void 0, void 0, function* () { | ||||||
|         const downloadUrl = release.files[0].download_url; |         const downloadUrl = release.files[0].download_url; | ||||||
|         core.info(`Download from "${downloadUrl}"`); |         core.info(`Download from "${downloadUrl}"`); | ||||||
|         const pythonPath = yield tc.downloadTool(downloadUrl, undefined, AUTH); |         let pythonPath = ''; | ||||||
|  |         try { | ||||||
|  |             pythonPath = yield tc.downloadTool(downloadUrl, undefined, AUTH); | ||||||
|             core.info('Extract downloaded archive'); |             core.info('Extract downloaded archive'); | ||||||
|             let pythonExtractedFolder; |             let pythonExtractedFolder; | ||||||
|             if (utils_1.IS_WINDOWS) { |             if (utils_1.IS_WINDOWS) { | ||||||
| @ -66741,6 +66761,22 @@ function installCpythonFromRelease(release) { | |||||||
|             } |             } | ||||||
|             core.info('Execute installation script'); |             core.info('Execute installation script'); | ||||||
|             yield installPython(pythonExtractedFolder); |             yield 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; | ||||||
|  |         } | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
| exports.installCpythonFromRelease = installCpythonFromRelease; | exports.installCpythonFromRelease = installCpythonFromRelease; | ||||||
|  | |||||||
| @ -46,6 +46,8 @@ export async function installPyPy( | |||||||
|   let downloadUrl = `${foundAsset.download_url}`; |   let downloadUrl = `${foundAsset.download_url}`; | ||||||
|  |  | ||||||
|   core.info(`Downloading PyPy from "${downloadUrl}" ...`); |   core.info(`Downloading PyPy from "${downloadUrl}" ...`); | ||||||
|  |  | ||||||
|  |   try { | ||||||
|     const pypyPath = await tc.downloadTool(downloadUrl); |     const pypyPath = await tc.downloadTool(downloadUrl); | ||||||
|  |  | ||||||
|     core.info('Extracting downloaded archive...'); |     core.info('Extracting downloaded archive...'); | ||||||
| @ -77,6 +79,25 @@ export async function installPyPy( | |||||||
|     await installPip(binaryPath); |     await installPip(binaryPath); | ||||||
|  |  | ||||||
|     return {installDir, resolvedPythonVersion, resolvedPyPyVersion}; |     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; | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| export async function getAvailablePyPyVersions() { | export async function getAvailablePyPyVersions() { | ||||||
|  | |||||||
| @ -72,7 +72,9 @@ export async function installCpythonFromRelease(release: tc.IToolRelease) { | |||||||
|   const downloadUrl = release.files[0].download_url; |   const downloadUrl = release.files[0].download_url; | ||||||
|  |  | ||||||
|   core.info(`Download from "${downloadUrl}"`); |   core.info(`Download from "${downloadUrl}"`); | ||||||
|   const pythonPath = await tc.downloadTool(downloadUrl, undefined, AUTH); |   let pythonPath = ''; | ||||||
|  |   try { | ||||||
|  |     pythonPath = await tc.downloadTool(downloadUrl, undefined, AUTH); | ||||||
|     core.info('Extract downloaded archive'); |     core.info('Extract downloaded archive'); | ||||||
|     let pythonExtractedFolder; |     let pythonExtractedFolder; | ||||||
|     if (IS_WINDOWS) { |     if (IS_WINDOWS) { | ||||||
| @ -83,4 +85,20 @@ export async function installCpythonFromRelease(release: tc.IToolRelease) { | |||||||
|  |  | ||||||
|     core.info('Execute installation script'); |     core.info('Execute installation script'); | ||||||
|     await installPython(pythonExtractedFolder); |     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