Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4818a5a

Browse filesBrowse files
authored
Handle download HTTP error (actions#511)
1 parent 8bcd256 commit 4818a5a
Copy full SHA for 4818a5a

File tree

Expand file treeCollapse file tree

3 files changed

+143
-68
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+143
-68
lines changed

‎dist/setup/index.js

Copy file name to clipboardExpand all lines: dist/setup/index.js
+65-29Lines changed: 65 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -66511,27 +66511,45 @@ function installPyPy(pypyVersion, pythonVersion, architecture, releases) {
6651166511
const { foundAsset, resolvedPythonVersion, resolvedPyPyVersion } = releaseData;
6651266512
let downloadUrl = `${foundAsset.download_url}`;
6651366513
core.info(`Downloading PyPy from "${downloadUrl}" ...`);
66514-
const pypyPath = yield tc.downloadTool(downloadUrl);
66515-
core.info('Extracting downloaded archive...');
66516-
if (utils_1.IS_WINDOWS) {
66517-
downloadDir = yield tc.extractZip(pypyPath);
66514+
try {
66515+
const pypyPath = yield tc.downloadTool(downloadUrl);
66516+
core.info('Extracting downloaded archive...');
66517+
if (utils_1.IS_WINDOWS) {
66518+
downloadDir = yield tc.extractZip(pypyPath);
66519+
}
66520+
else {
66521+
downloadDir = yield tc.extractTar(pypyPath, undefined, 'x');
66522+
}
66523+
// root folder in archive can have unpredictable name so just take the first folder
66524+
// downloadDir is unique folder under TEMP and can't contain any other folders
66525+
const archiveName = fs_1.default.readdirSync(downloadDir)[0];
66526+
const toolDir = path.join(downloadDir, archiveName);
66527+
let installDir = toolDir;
66528+
if (!utils_1.isNightlyKeyword(resolvedPyPyVersion)) {
66529+
installDir = yield tc.cacheDir(toolDir, 'PyPy', resolvedPythonVersion, architecture);
66530+
}
66531+
utils_1.writeExactPyPyVersionFile(installDir, resolvedPyPyVersion);
66532+
const binaryPath = getPyPyBinaryPath(installDir);
66533+
yield createPyPySymlink(binaryPath, resolvedPythonVersion);
66534+
yield installPip(binaryPath);
66535+
return { installDir, resolvedPythonVersion, resolvedPyPyVersion };
66536+
}
66537+
catch (err) {
66538+
if (err instanceof Error) {
66539+
// Rate limit?
66540+
if (err instanceof tc.HTTPError &&
66541+
(err.httpStatusCode === 403 || err.httpStatusCode === 429)) {
66542+
core.info(`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`);
66543+
}
66544+
else {
66545+
core.info(err.message);
66546+
}
66547+
if (err.stack !== undefined) {
66548+
core.debug(err.stack);
66549+
}
66550+
}
66551+
throw err;
6651866552
}
66519-
else {
66520-
downloadDir = yield tc.extractTar(pypyPath, undefined, 'x');
66521-
}
66522-
// root folder in archive can have unpredictable name so just take the first folder
66523-
// downloadDir is unique folder under TEMP and can't contain any other folders
66524-
const archiveName = fs_1.default.readdirSync(downloadDir)[0];
66525-
const toolDir = path.join(downloadDir, archiveName);
66526-
let installDir = toolDir;
66527-
if (!utils_1.isNightlyKeyword(resolvedPyPyVersion)) {
66528-
installDir = yield tc.cacheDir(toolDir, 'PyPy', resolvedPythonVersion, architecture);
66529-
}
66530-
utils_1.writeExactPyPyVersionFile(installDir, resolvedPyPyVersion);
66531-
const binaryPath = getPyPyBinaryPath(installDir);
66532-
yield createPyPySymlink(binaryPath, resolvedPythonVersion);
66533-
yield installPip(binaryPath);
66534-
return { installDir, resolvedPythonVersion, resolvedPyPyVersion };
6653566553
});
6653666554
}
6653766555
exports.installPyPy = installPyPy;
@@ -66730,17 +66748,35 @@ function installCpythonFromRelease(release) {
6673066748
return __awaiter(this, void 0, void 0, function* () {
6673166749
const downloadUrl = release.files[0].download_url;
6673266750
core.info(`Download from "${downloadUrl}"`);
66733-
const pythonPath = yield tc.downloadTool(downloadUrl, undefined, AUTH);
66734-
core.info('Extract downloaded archive');
66735-
let pythonExtractedFolder;
66736-
if (utils_1.IS_WINDOWS) {
66737-
pythonExtractedFolder = yield tc.extractZip(pythonPath);
66751+
let pythonPath = '';
66752+
try {
66753+
pythonPath = yield tc.downloadTool(downloadUrl, undefined, AUTH);
66754+
core.info('Extract downloaded archive');
66755+
let pythonExtractedFolder;
66756+
if (utils_1.IS_WINDOWS) {
66757+
pythonExtractedFolder = yield tc.extractZip(pythonPath);
66758+
}
66759+
else {
66760+
pythonExtractedFolder = yield tc.extractTar(pythonPath);
66761+
}
66762+
core.info('Execute installation script');
66763+
yield installPython(pythonExtractedFolder);
6673866764
}
66739-
else {
66740-
pythonExtractedFolder = yield tc.extractTar(pythonPath);
66765+
catch (err) {
66766+
if (err instanceof tc.HTTPError) {
66767+
// Rate limit?
66768+
if (err.httpStatusCode === 403 || err.httpStatusCode === 429) {
66769+
core.info(`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`);
66770+
}
66771+
else {
66772+
core.info(err.message);
66773+
}
66774+
if (err.stack) {
66775+
core.debug(err.stack);
66776+
}
66777+
}
66778+
throw err;
6674166779
}
66742-
core.info('Execute installation script');
66743-
yield installPython(pythonExtractedFolder);
6674466780
});
6674566781
}
6674666782
exports.installCpythonFromRelease = installCpythonFromRelease;

‎src/install-pypy.ts

Copy file name to clipboardExpand all lines: src/install-pypy.ts
+50-29Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,37 +46,58 @@ export async function installPyPy(
4646
let downloadUrl = `${foundAsset.download_url}`;
4747

4848
core.info(`Downloading PyPy from "${downloadUrl}" ...`);
49-
const pypyPath = await tc.downloadTool(downloadUrl);
5049

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

82103
export async function getAvailablePyPyVersions() {

‎src/install-python.ts

Copy file name to clipboardExpand all lines: src/install-python.ts
+28-10Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,33 @@ 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 tc.HTTPError) {
90+
// Rate limit?
91+
if (err.httpStatusCode === 403 || err.httpStatusCode === 429) {
92+
core.info(
93+
`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`
94+
);
95+
} else {
96+
core.info(err.message);
97+
}
98+
if (err.stack) {
99+
core.debug(err.stack);
100+
}
101+
}
102+
throw err;
103+
}
86104
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.