From de50e7576c450816cb539d83c3e063b25956c4d4 Mon Sep 17 00:00:00 2001 From: Sergey Dolin Date: Thu, 29 Sep 2022 11:25:30 +0200 Subject: [PATCH 1/2] Handle download HTTP error --- dist/setup/index.js | 95 ++++++++++++++++++++++++++++++------------- src/install-pypy.ts | 79 ++++++++++++++++++++++------------- src/install-python.ts | 41 ++++++++++++++----- 3 files changed, 147 insertions(+), 68 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index f153c3c24..b0fec7c3b 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -66511,27 +66511,45 @@ function installPyPy(pypyVersion, pythonVersion, architecture, releases) { const { foundAsset, resolvedPythonVersion, resolvedPyPyVersion } = releaseData; let downloadUrl = `${foundAsset.download_url}`; core.info(`Downloading PyPy from "${downloadUrl}" ...`); - const pypyPath = yield tc.downloadTool(downloadUrl); - core.info('Extracting downloaded archive...'); - if (utils_1.IS_WINDOWS) { - downloadDir = yield tc.extractZip(pypyPath); + try { + const pypyPath = yield tc.downloadTool(downloadUrl); + core.info('Extracting downloaded archive...'); + if (utils_1.IS_WINDOWS) { + downloadDir = yield tc.extractZip(pypyPath); + } + else { + downloadDir = yield 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_1.default.readdirSync(downloadDir)[0]; + const toolDir = path.join(downloadDir, archiveName); + let installDir = toolDir; + if (!utils_1.isNightlyKeyword(resolvedPyPyVersion)) { + installDir = yield tc.cacheDir(toolDir, 'PyPy', resolvedPythonVersion, architecture); + } + utils_1.writeExactPyPyVersionFile(installDir, resolvedPyPyVersion); + const binaryPath = getPyPyBinaryPath(installDir); + yield createPyPySymlink(binaryPath, resolvedPythonVersion); + yield 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; } - else { - downloadDir = yield 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_1.default.readdirSync(downloadDir)[0]; - const toolDir = path.join(downloadDir, archiveName); - let installDir = toolDir; - if (!utils_1.isNightlyKeyword(resolvedPyPyVersion)) { - installDir = yield tc.cacheDir(toolDir, 'PyPy', resolvedPythonVersion, architecture); - } - utils_1.writeExactPyPyVersionFile(installDir, resolvedPyPyVersion); - const binaryPath = getPyPyBinaryPath(installDir); - yield createPyPySymlink(binaryPath, resolvedPythonVersion); - yield installPip(binaryPath); - return { installDir, resolvedPythonVersion, resolvedPyPyVersion }; }); } exports.installPyPy = installPyPy; @@ -66730,17 +66748,36 @@ function installCpythonFromRelease(release) { return __awaiter(this, void 0, void 0, function* () { const downloadUrl = release.files[0].download_url; core.info(`Download from "${downloadUrl}"`); - const pythonPath = yield tc.downloadTool(downloadUrl, undefined, AUTH); - core.info('Extract downloaded archive'); - let pythonExtractedFolder; - if (utils_1.IS_WINDOWS) { - pythonExtractedFolder = yield tc.extractZip(pythonPath); + let pythonPath = ''; + try { + pythonPath = yield tc.downloadTool(downloadUrl, undefined, AUTH); + core.info('Extract downloaded archive'); + let pythonExtractedFolder; + if (utils_1.IS_WINDOWS) { + pythonExtractedFolder = yield tc.extractZip(pythonPath); + } + else { + pythonExtractedFolder = yield tc.extractTar(pythonPath); + } + core.info('Execute installation script'); + yield installPython(pythonExtractedFolder); } - else { - pythonExtractedFolder = yield tc.extractTar(pythonPath); + 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; } - core.info('Execute installation script'); - yield installPython(pythonExtractedFolder); }); } exports.installCpythonFromRelease = installCpythonFromRelease; diff --git a/src/install-pypy.ts b/src/install-pypy.ts index d8594ba6b..f7df9c521 100644 --- a/src/install-pypy.ts +++ b/src/install-pypy.ts @@ -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() { diff --git a/src/install-python.ts b/src/install-python.ts index aa6ab2d4d..ec796c902 100644 --- a/src/install-python.ts +++ b/src/install-python.ts @@ -72,15 +72,36 @@ 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 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; + } } From 63afba950bd2283eed6cea514747cc0ee7ae45a6 Mon Sep 17 00:00:00 2001 From: Sergey Dolin Date: Thu, 20 Oct 2022 19:34:00 +0200 Subject: [PATCH 2/2] Fix styling --- dist/setup/index.js | 7 +++---- src/install-python.ts | 9 +++------ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index b0fec7c3b..2ca2fe1b6 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -66763,16 +66763,15 @@ function installCpythonFromRelease(release) { yield installPython(pythonExtractedFolder); } catch (err) { - if (err instanceof Error) { + if (err instanceof tc.HTTPError) { // Rate limit? - if (err instanceof tc.HTTPError && - (err.httpStatusCode === 403 || err.httpStatusCode === 429)) { + 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 !== undefined) { + if (err.stack) { core.debug(err.stack); } } diff --git a/src/install-python.ts b/src/install-python.ts index ec796c902..2af61291d 100644 --- a/src/install-python.ts +++ b/src/install-python.ts @@ -86,19 +86,16 @@ export async function installCpythonFromRelease(release: tc.IToolRelease) { core.info('Execute installation script'); await installPython(pythonExtractedFolder); } catch (err) { - if (err instanceof Error) { + if (err instanceof tc.HTTPError) { // Rate limit? - if ( - err instanceof tc.HTTPError && - (err.httpStatusCode === 403 || err.httpStatusCode === 429) - ) { + 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 !== undefined) { + if (err.stack) { core.debug(err.stack); } } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy