mirror of
https://gitea.com/actions/setup-python.git
synced 2024-11-29 21:49:32 +01:00
Handle download HTTP error (#511)
This commit is contained in:
parent
8bcd2560e2
commit
4818a5a153
3 changed files with 142 additions and 67 deletions
92
dist/setup/index.js
vendored
92
dist/setup/index.js
vendored
|
@ -66511,27 +66511,45 @@ 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}" ...`);
|
||||||
const pypyPath = yield tc.downloadTool(downloadUrl);
|
try {
|
||||||
core.info('Extracting downloaded archive...');
|
const pypyPath = yield tc.downloadTool(downloadUrl);
|
||||||
if (utils_1.IS_WINDOWS) {
|
core.info('Extracting downloaded archive...');
|
||||||
downloadDir = yield tc.extractZip(pypyPath);
|
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 };
|
||||||
}
|
}
|
||||||
else {
|
catch (err) {
|
||||||
downloadDir = yield tc.extractTar(pypyPath, undefined, 'x');
|
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_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;
|
exports.installPyPy = installPyPy;
|
||||||
|
@ -66730,17 +66748,35 @@ 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 = '';
|
||||||
core.info('Extract downloaded archive');
|
try {
|
||||||
let pythonExtractedFolder;
|
pythonPath = yield tc.downloadTool(downloadUrl, undefined, AUTH);
|
||||||
if (utils_1.IS_WINDOWS) {
|
core.info('Extract downloaded archive');
|
||||||
pythonExtractedFolder = yield tc.extractZip(pythonPath);
|
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 {
|
catch (err) {
|
||||||
pythonExtractedFolder = yield tc.extractTar(pythonPath);
|
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;
|
||||||
}
|
}
|
||||||
core.info('Execute installation script');
|
|
||||||
yield installPython(pythonExtractedFolder);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.installCpythonFromRelease = installCpythonFromRelease;
|
exports.installCpythonFromRelease = installCpythonFromRelease;
|
||||||
|
|
|
@ -46,37 +46,58 @@ 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}" ...`);
|
||||||
const pypyPath = await tc.downloadTool(downloadUrl);
|
|
||||||
|
|
||||||
core.info('Extracting downloaded archive...');
|
try {
|
||||||
if (IS_WINDOWS) {
|
const pypyPath = await tc.downloadTool(downloadUrl);
|
||||||
downloadDir = await tc.extractZip(pypyPath);
|
|
||||||
} else {
|
core.info('Extracting downloaded archive...');
|
||||||
downloadDir = await tc.extractTar(pypyPath, undefined, 'x');
|
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() {
|
export async function getAvailablePyPyVersions() {
|
||||||
|
|
|
@ -72,15 +72,33 @@ 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 = '';
|
||||||
core.info('Extract downloaded archive');
|
try {
|
||||||
let pythonExtractedFolder;
|
pythonPath = await tc.downloadTool(downloadUrl, undefined, AUTH);
|
||||||
if (IS_WINDOWS) {
|
core.info('Extract downloaded archive');
|
||||||
pythonExtractedFolder = await tc.extractZip(pythonPath);
|
let pythonExtractedFolder;
|
||||||
} else {
|
if (IS_WINDOWS) {
|
||||||
pythonExtractedFolder = await tc.extractTar(pythonPath);
|
pythonExtractedFolder = await tc.extractZip(pythonPath);
|
||||||
}
|
} else {
|
||||||
|
pythonExtractedFolder = await tc.extractTar(pythonPath);
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue