Skip to content

Commit 7c16f92

Browse files
handled candidate not iterable error
1 parent 6ca8e85 commit 7c16f92

File tree

3 files changed

+87
-5
lines changed

3 files changed

+87
-5
lines changed

__tests__/install-python.test.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,30 @@ import * as tc from '@actions/tool-cache';
88

99
jest.mock('@actions/http-client');
1010
jest.mock('@actions/tool-cache');
11+
jest.mock('@actions/tool-cache', () => ({
12+
getManifestFromRepo: jest.fn()
13+
}));
1114

12-
const mockManifest = [{version: '1.0.0'}];
15+
const mockManifest = [
16+
{
17+
version: '1.0.0',
18+
stable: true,
19+
files: [
20+
{
21+
filename: 'tool-v1.0.0-linux-x64.tar.gz',
22+
platform: 'linux',
23+
arch: 'x64',
24+
download_url: 'https://example.com/tool-v1.0.0-linux-x64.tar.gz'
25+
}
26+
]
27+
}
28+
];
1329

1430
describe('getManifest', () => {
31+
beforeEach(() => {
32+
jest.resetAllMocks();
33+
});
34+
1535
it('should return manifest from repo', async () => {
1636
(tc.getManifestFromRepo as jest.Mock).mockResolvedValue(mockManifest);
1737
const manifest = await getManifest();

dist/setup/index.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100156,15 +100156,40 @@ function findReleaseFromManifest(semanticVersionSpec, architecture, manifest) {
100156100156
});
100157100157
}
100158100158
exports.findReleaseFromManifest = findReleaseFromManifest;
100159+
function isIToolRelease(obj) {
100160+
return (typeof obj === 'object' &&
100161+
obj !== null &&
100162+
typeof obj.version === 'string' &&
100163+
typeof obj.stable === 'boolean' &&
100164+
Array.isArray(obj.files) &&
100165+
obj.files.every((file) => typeof file.filename === 'string' &&
100166+
typeof file.platform === 'string' &&
100167+
typeof file.arch === 'string' &&
100168+
typeof file.download_url === 'string'));
100169+
}
100159100170
function getManifest() {
100160100171
return __awaiter(this, void 0, void 0, function* () {
100161100172
try {
100162-
return yield getManifestFromRepo();
100173+
const repoManifest = yield getManifestFromRepo();
100174+
core.debug(`Received repo manifest: ${JSON.stringify(repoManifest)}`);
100175+
if (Array.isArray(repoManifest) &&
100176+
repoManifest.length &&
100177+
repoManifest.every(isIToolRelease)) {
100178+
core.debug('Repo manifest is valid and contains IToolRelease items.');
100179+
return repoManifest;
100180+
}
100181+
else {
100182+
core.debug('Repo manifest is invalid or does not contain IToolRelease items.');
100183+
}
100163100184
}
100164100185
catch (err) {
100165100186
core.debug('Fetching the manifest via the API failed.');
100166100187
if (err instanceof Error) {
100167-
core.debug(err.message);
100188+
core.debug(`Error message: ${err.message}`);
100189+
core.debug(`Error stack: ${err.stack}`);
100190+
}
100191+
else {
100192+
core.debug('Error is not an instance of Error. It might be something else.');
100168100193
}
100169100194
}
100170100195
return yield getManifestFromURL();

src/install-python.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as exec from '@actions/exec';
55
import * as httpm from '@actions/http-client';
66
import {ExecOptions} from '@actions/exec/lib/interfaces';
77
import {IS_WINDOWS, IS_LINUX, getDownloadFileName} from './utils';
8+
import {IToolRelease} from '@actions/tool-cache';
89

910
const TOKEN = core.getInput('token');
1011
const AUTH = !TOKEN ? undefined : `token ${TOKEN}`;
@@ -32,13 +33,49 @@ export async function findReleaseFromManifest(
3233
return foundRelease;
3334
}
3435

36+
function isIToolRelease(obj: any): obj is IToolRelease {
37+
return (
38+
typeof obj === 'object' &&
39+
obj !== null &&
40+
typeof obj.version === 'string' &&
41+
typeof obj.stable === 'boolean' &&
42+
Array.isArray(obj.files) &&
43+
obj.files.every(
44+
(file: any) =>
45+
typeof file.filename === 'string' &&
46+
typeof file.platform === 'string' &&
47+
typeof file.arch === 'string' &&
48+
typeof file.download_url === 'string'
49+
)
50+
);
51+
}
52+
3553
export async function getManifest(): Promise<tc.IToolRelease[]> {
3654
try {
37-
return await getManifestFromRepo();
55+
const repoManifest = await getManifestFromRepo();
56+
core.debug(`Received repo manifest: ${JSON.stringify(repoManifest)}`);
57+
58+
if (
59+
Array.isArray(repoManifest) &&
60+
repoManifest.length &&
61+
repoManifest.every(isIToolRelease)
62+
) {
63+
core.debug('Repo manifest is valid and contains IToolRelease items.');
64+
return repoManifest;
65+
} else {
66+
core.debug(
67+
'Repo manifest is invalid or does not contain IToolRelease items.'
68+
);
69+
}
3870
} catch (err) {
3971
core.debug('Fetching the manifest via the API failed.');
4072
if (err instanceof Error) {
41-
core.debug(err.message);
73+
core.debug(`Error message: ${err.message}`);
74+
core.debug(`Error stack: ${err.stack}`);
75+
} else {
76+
core.debug(
77+
'Error is not an instance of Error. It might be something else.'
78+
);
4279
}
4380
}
4481
return await getManifestFromURL();

0 commit comments

Comments
 (0)