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 6fd5143

Browse filesBrowse files
committed
feat: fallback to raw endpoint for manifest when rate limit is reached
1 parent 871daa9 commit 6fd5143
Copy full SHA for 6fd5143

File tree

Expand file treeCollapse file tree

3 files changed

+113
-3
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+113
-3
lines changed

‎__tests__/install-python.test.ts

Copy file name to clipboard
+58Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import {
2+
getManifest,
3+
getManifestFromRepo,
4+
getManifestFromURL
5+
} from '../src/install-python';
6+
import * as httpm from '@actions/http-client';
7+
import * as tc from '@actions/tool-cache';
8+
9+
jest.mock('@actions/http-client');
10+
jest.mock('@actions/tool-cache');
11+
12+
const mockManifest = [{version: '1.0.0'}];
13+
14+
describe('getManifest', () => {
15+
it('should return manifest from repo', async () => {
16+
(tc.getManifestFromRepo as jest.Mock).mockResolvedValue(mockManifest);
17+
const manifest = await getManifest();
18+
expect(manifest).toEqual(mockManifest);
19+
});
20+
21+
it('should return manifest from URL if repo fetch fails', async () => {
22+
(tc.getManifestFromRepo as jest.Mock).mockRejectedValue(
23+
new Error('Fetch failed')
24+
);
25+
(httpm.HttpClient.prototype.getJson as jest.Mock).mockResolvedValue({
26+
result: mockManifest
27+
});
28+
const manifest = await getManifest();
29+
expect(manifest).toEqual(mockManifest);
30+
});
31+
});
32+
33+
describe('getManifestFromRepo', () => {
34+
it('should return manifest from repo', async () => {
35+
(tc.getManifestFromRepo as jest.Mock).mockResolvedValue(mockManifest);
36+
const manifest = await getManifestFromRepo();
37+
expect(manifest).toEqual(mockManifest);
38+
});
39+
});
40+
41+
describe('getManifestFromURL', () => {
42+
it('should return manifest from URL', async () => {
43+
(httpm.HttpClient.prototype.getJson as jest.Mock).mockResolvedValue({
44+
result: mockManifest
45+
});
46+
const manifest = await getManifestFromURL();
47+
expect(manifest).toEqual(mockManifest);
48+
});
49+
50+
it('should throw error if unable to get manifest from URL', async () => {
51+
(httpm.HttpClient.prototype.getJson as jest.Mock).mockResolvedValue({
52+
result: null
53+
});
54+
await expect(getManifestFromURL()).rejects.toThrow(
55+
'Unable to get manifest from'
56+
);
57+
});
58+
});

‎dist/setup/index.js

Copy file name to clipboardExpand all lines: dist/setup/index.js
+30-2Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90923,11 +90923,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9092390923
});
9092490924
};
9092590925
Object.defineProperty(exports, "__esModule", ({ value: true }));
90926-
exports.installCpythonFromRelease = exports.getManifest = exports.findReleaseFromManifest = exports.MANIFEST_URL = void 0;
90926+
exports.installCpythonFromRelease = exports.getManifestFromURL = exports.getManifestFromRepo = exports.getManifest = exports.findReleaseFromManifest = exports.MANIFEST_URL = void 0;
9092790927
const path = __importStar(__nccwpck_require__(1017));
9092890928
const core = __importStar(__nccwpck_require__(2186));
9092990929
const tc = __importStar(__nccwpck_require__(7784));
9093090930
const exec = __importStar(__nccwpck_require__(1514));
90931+
const httpm = __importStar(__nccwpck_require__(6255));
9093190932
const utils_1 = __nccwpck_require__(1314);
9093290933
const TOKEN = core.getInput('token');
9093390934
const AUTH = !TOKEN ? undefined : `token ${TOKEN}`;
@@ -90946,10 +90947,37 @@ function findReleaseFromManifest(semanticVersionSpec, architecture, manifest) {
9094690947
}
9094790948
exports.findReleaseFromManifest = findReleaseFromManifest;
9094890949
function getManifest() {
90950+
return __awaiter(this, void 0, void 0, function* () {
90951+
try {
90952+
return yield getManifestFromRepo();
90953+
}
90954+
catch (err) {
90955+
core.debug('Fetching the manifest via the API failed.');
90956+
if (err instanceof Error) {
90957+
core.debug(err.message);
90958+
}
90959+
}
90960+
return yield getManifestFromURL();
90961+
});
90962+
}
90963+
exports.getManifest = getManifest;
90964+
function getManifestFromRepo() {
9094990965
core.debug(`Getting manifest from ${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}@${MANIFEST_REPO_BRANCH}`);
9095090966
return tc.getManifestFromRepo(MANIFEST_REPO_OWNER, MANIFEST_REPO_NAME, AUTH, MANIFEST_REPO_BRANCH);
9095190967
}
90952-
exports.getManifest = getManifest;
90968+
exports.getManifestFromRepo = getManifestFromRepo;
90969+
function getManifestFromURL() {
90970+
return __awaiter(this, void 0, void 0, function* () {
90971+
core.debug('Falling back to fetching the manifest using raw URL.');
90972+
const http = new httpm.HttpClient('tool-cache');
90973+
const response = yield http.getJson(exports.MANIFEST_URL);
90974+
if (!response.result) {
90975+
throw new Error(`Unable to get manifest from ${exports.MANIFEST_URL}`);
90976+
}
90977+
return response.result;
90978+
});
90979+
}
90980+
exports.getManifestFromURL = getManifestFromURL;
9095390981
function installPython(workingDirectory) {
9095490982
return __awaiter(this, void 0, void 0, function* () {
9095590983
const options = {

‎src/install-python.ts

Copy file name to clipboardExpand all lines: src/install-python.ts
+25-1Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as path from 'path';
22
import * as core from '@actions/core';
33
import * as tc from '@actions/tool-cache';
44
import * as exec from '@actions/exec';
5+
import * as httpm from '@actions/http-client';
56
import {ExecOptions} from '@actions/exec/lib/interfaces';
67
import {IS_WINDOWS, IS_LINUX} from './utils';
78

@@ -31,7 +32,19 @@ export async function findReleaseFromManifest(
3132
return foundRelease;
3233
}
3334

34-
export function getManifest(): Promise<tc.IToolRelease[]> {
35+
export async function getManifest(): Promise<tc.IToolRelease[]> {
36+
try {
37+
return await getManifestFromRepo();
38+
} catch (err) {
39+
core.debug('Fetching the manifest via the API failed.');
40+
if (err instanceof Error) {
41+
core.debug(err.message);
42+
}
43+
}
44+
return await getManifestFromURL();
45+
}
46+
47+
export function getManifestFromRepo(): Promise<tc.IToolRelease[]> {
3548
core.debug(
3649
`Getting manifest from ${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}@${MANIFEST_REPO_BRANCH}`
3750
);
@@ -43,6 +56,17 @@ export function getManifest(): Promise<tc.IToolRelease[]> {
4356
);
4457
}
4558

59+
export async function getManifestFromURL(): Promise<tc.IToolRelease[]> {
60+
core.debug('Falling back to fetching the manifest using raw URL.');
61+
62+
const http: httpm.HttpClient = new httpm.HttpClient('tool-cache');
63+
const response = await http.getJson<tc.IToolRelease[]>(MANIFEST_URL);
64+
if (!response.result) {
65+
throw new Error(`Unable to get manifest from ${MANIFEST_URL}`);
66+
}
67+
return response.result;
68+
}
69+
4670
async function installPython(workingDirectory: string) {
4771
const options: ExecOptions = {
4872
cwd: workingDirectory,

0 commit comments

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