Skip to content

Commit a1df4f3

Browse files
committed
Handle download HTTP error
1 parent 13a464f commit a1df4f3

File tree

3 files changed

+147
-68
lines changed

3 files changed

+147
-68
lines changed

dist/setup/index.js

+66-29
Original file line numberDiff line numberDiff line change
@@ -66496,27 +66496,45 @@ function installPyPy(pypyVersion, pythonVersion, architecture, releases) {
6649666496
const { foundAsset, resolvedPythonVersion, resolvedPyPyVersion } = releaseData;
6649766497
let downloadUrl = `${foundAsset.download_url}`;
6649866498
core.info(`Downloading PyPy from "${downloadUrl}" ...`);
66499-
const pypyPath = yield tc.downloadTool(downloadUrl);
66500-
core.info('Extracting downloaded archive...');
66501-
if (utils_1.IS_WINDOWS) {
66502-
downloadDir = yield tc.extractZip(pypyPath);
66499+
try {
66500+
const pypyPath = yield tc.downloadTool(downloadUrl);
66501+
core.info('Extracting downloaded archive...');
66502+
if (utils_1.IS_WINDOWS) {
66503+
downloadDir = yield tc.extractZip(pypyPath);
66504+
}
66505+
else {
66506+
downloadDir = yield tc.extractTar(pypyPath, undefined, 'x');
66507+
}
66508+
// root folder in archive can have unpredictable name so just take the first folder
66509+
// downloadDir is unique folder under TEMP and can't contain any other folders
66510+
const archiveName = fs_1.default.readdirSync(downloadDir)[0];
66511+
const toolDir = path.join(downloadDir, archiveName);
66512+
let installDir = toolDir;
66513+
if (!utils_1.isNightlyKeyword(resolvedPyPyVersion)) {
66514+
installDir = yield tc.cacheDir(toolDir, 'PyPy', resolvedPythonVersion, architecture);
66515+
}
66516+
utils_1.writeExactPyPyVersionFile(installDir, resolvedPyPyVersion);
66517+
const binaryPath = getPyPyBinaryPath(installDir);
66518+
yield createPyPySymlink(binaryPath, resolvedPythonVersion);
66519+
yield installPip(binaryPath);
66520+
return { installDir, resolvedPythonVersion, resolvedPyPyVersion };
66521+
}
66522+
catch (err) {
66523+
if (err instanceof Error) {
66524+
// Rate limit?
66525+
if (err instanceof tc.HTTPError &&
66526+
(err.httpStatusCode === 403 || err.httpStatusCode === 429)) {
66527+
core.info(`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`);
66528+
}
66529+
else {
66530+
core.info(err.message);
66531+
}
66532+
if (err.stack !== undefined) {
66533+
core.debug(err.stack);
66534+
}
66535+
}
66536+
throw err;
6650366537
}
66504-
else {
66505-
downloadDir = yield tc.extractTar(pypyPath, undefined, 'x');
66506-
}
66507-
// root folder in archive can have unpredictable name so just take the first folder
66508-
// downloadDir is unique folder under TEMP and can't contain any other folders
66509-
const archiveName = fs_1.default.readdirSync(downloadDir)[0];
66510-
const toolDir = path.join(downloadDir, archiveName);
66511-
let installDir = toolDir;
66512-
if (!utils_1.isNightlyKeyword(resolvedPyPyVersion)) {
66513-
installDir = yield tc.cacheDir(toolDir, 'PyPy', resolvedPythonVersion, architecture);
66514-
}
66515-
utils_1.writeExactPyPyVersionFile(installDir, resolvedPyPyVersion);
66516-
const binaryPath = getPyPyBinaryPath(installDir);
66517-
yield createPyPySymlink(binaryPath, resolvedPythonVersion);
66518-
yield installPip(binaryPath);
66519-
return { installDir, resolvedPythonVersion, resolvedPyPyVersion };
6652066538
});
6652166539
}
6652266540
exports.installPyPy = installPyPy;
@@ -66708,17 +66726,36 @@ function installCpythonFromRelease(release) {
6670866726
return __awaiter(this, void 0, void 0, function* () {
6670966727
const downloadUrl = release.files[0].download_url;
6671066728
core.info(`Download from "${downloadUrl}"`);
66711-
const pythonPath = yield tc.downloadTool(downloadUrl, undefined, AUTH);
66712-
core.info('Extract downloaded archive');
66713-
let pythonExtractedFolder;
66714-
if (utils_1.IS_WINDOWS) {
66715-
pythonExtractedFolder = yield tc.extractZip(pythonPath);
66729+
let pythonPath = '';
66730+
try {
66731+
pythonPath = yield tc.downloadTool(downloadUrl, undefined, AUTH);
66732+
core.info('Extract downloaded archive');
66733+
let pythonExtractedFolder;
66734+
if (utils_1.IS_WINDOWS) {
66735+
pythonExtractedFolder = yield tc.extractZip(pythonPath);
66736+
}
66737+
else {
66738+
pythonExtractedFolder = yield tc.extractTar(pythonPath);
66739+
}
66740+
core.info('Execute installation script');
66741+
yield installPython(pythonExtractedFolder);
6671666742
}
66717-
else {
66718-
pythonExtractedFolder = yield tc.extractTar(pythonPath);
66743+
catch (err) {
66744+
if (err instanceof Error) {
66745+
// Rate limit?
66746+
if (err instanceof tc.HTTPError &&
66747+
(err.httpStatusCode === 403 || err.httpStatusCode === 429)) {
66748+
core.info(`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`);
66749+
}
66750+
else {
66751+
core.info(err.message);
66752+
}
66753+
if (err.stack !== undefined) {
66754+
core.debug(err.stack);
66755+
}
66756+
}
66757+
throw err;
6671966758
}
66720-
core.info('Execute installation script');
66721-
yield installPython(pythonExtractedFolder);
6672266759
});
6672366760
}
6672466761
exports.installCpythonFromRelease = installCpythonFromRelease;

src/install-pypy.ts

+50-29
Original file line numberDiff line numberDiff line change
@@ -47,37 +47,58 @@ export async function installPyPy(
4747
let downloadUrl = `${foundAsset.download_url}`;
4848

4949
core.info(`Downloading PyPy from "${downloadUrl}" ...`);
50-
const pypyPath = await tc.downloadTool(downloadUrl);
5150

52-
core.info('Extracting downloaded archive...');
53-
if (IS_WINDOWS) {
54-
downloadDir = await tc.extractZip(pypyPath);
55-
} else {
56-
downloadDir = await tc.extractTar(pypyPath, undefined, 'x');
51+
try {
52+
const pypyPath = await tc.downloadTool(downloadUrl);
53+
54+
core.info('Extracting downloaded archive...');
55+
if (IS_WINDOWS) {
56+
downloadDir = await tc.extractZip(pypyPath);
57+
} else {
58+
downloadDir = await tc.extractTar(pypyPath, undefined, 'x');
59+
}
60+
61+
// root folder in archive can have unpredictable name so just take the first folder
62+
// downloadDir is unique folder under TEMP and can't contain any other folders
63+
const archiveName = fs.readdirSync(downloadDir)[0];
64+
65+
const toolDir = path.join(downloadDir, archiveName);
66+
let installDir = toolDir;
67+
if (!isNightlyKeyword(resolvedPyPyVersion)) {
68+
installDir = await tc.cacheDir(
69+
toolDir,
70+
'PyPy',
71+
resolvedPythonVersion,
72+
architecture
73+
);
74+
}
75+
76+
writeExactPyPyVersionFile(installDir, resolvedPyPyVersion);
77+
78+
const binaryPath = getPyPyBinaryPath(installDir);
79+
await createPyPySymlink(binaryPath, resolvedPythonVersion);
80+
await installPip(binaryPath);
81+
82+
return {installDir, resolvedPythonVersion, resolvedPyPyVersion};
83+
} catch (err) {
84+
if (err instanceof Error) {
85+
// Rate limit?
86+
if (
87+
err instanceof tc.HTTPError &&
88+
(err.httpStatusCode === 403 || err.httpStatusCode === 429)
89+
) {
90+
core.info(
91+
`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`
92+
);
93+
} else {
94+
core.info(err.message);
95+
}
96+
if (err.stack !== undefined) {
97+
core.debug(err.stack);
98+
}
99+
}
100+
throw err;
57101
}
58-
59-
// root folder in archive can have unpredictable name so just take the first folder
60-
// downloadDir is unique folder under TEMP and can't contain any other folders
61-
const archiveName = fs.readdirSync(downloadDir)[0];
62-
63-
const toolDir = path.join(downloadDir, archiveName);
64-
let installDir = toolDir;
65-
if (!isNightlyKeyword(resolvedPyPyVersion)) {
66-
installDir = await tc.cacheDir(
67-
toolDir,
68-
'PyPy',
69-
resolvedPythonVersion,
70-
architecture
71-
);
72-
}
73-
74-
writeExactPyPyVersionFile(installDir, resolvedPyPyVersion);
75-
76-
const binaryPath = getPyPyBinaryPath(installDir);
77-
await createPyPySymlink(binaryPath, resolvedPythonVersion);
78-
await installPip(binaryPath);
79-
80-
return {installDir, resolvedPythonVersion, resolvedPyPyVersion};
81102
}
82103

83104
export async function getAvailablePyPyVersions() {

src/install-python.ts

+31-10
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,36 @@ export async function installCpythonFromRelease(release: tc.IToolRelease) {
7272
const downloadUrl = release.files[0].download_url;
7373

7474
core.info(`Download from "${downloadUrl}"`);
75-
const pythonPath = await tc.downloadTool(downloadUrl, undefined, AUTH);
76-
core.info('Extract downloaded archive');
77-
let pythonExtractedFolder;
78-
if (IS_WINDOWS) {
79-
pythonExtractedFolder = await tc.extractZip(pythonPath);
80-
} else {
81-
pythonExtractedFolder = await tc.extractTar(pythonPath);
82-
}
75+
let pythonPath = '';
76+
try {
77+
pythonPath = await tc.downloadTool(downloadUrl, undefined, AUTH);
78+
core.info('Extract downloaded archive');
79+
let pythonExtractedFolder;
80+
if (IS_WINDOWS) {
81+
pythonExtractedFolder = await tc.extractZip(pythonPath);
82+
} else {
83+
pythonExtractedFolder = await tc.extractTar(pythonPath);
84+
}
8385

84-
core.info('Execute installation script');
85-
await installPython(pythonExtractedFolder);
86+
core.info('Execute installation script');
87+
await installPython(pythonExtractedFolder);
88+
} catch (err) {
89+
if (err instanceof Error) {
90+
// Rate limit?
91+
if (
92+
err instanceof tc.HTTPError &&
93+
(err.httpStatusCode === 403 || err.httpStatusCode === 429)
94+
) {
95+
core.info(
96+
`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`
97+
);
98+
} else {
99+
core.info(err.message);
100+
}
101+
if (err.stack !== undefined) {
102+
core.debug(err.stack);
103+
}
104+
}
105+
throw err;
106+
}
86107
}

0 commit comments

Comments
 (0)