8000 Handled Candidate Not Iterable Error by mahabaleshwars · Pull Request #1074 · actions/setup-python · GitHub
[go: up one dir, main page]

Skip to content

Handled Candidate Not Iterable Error #1074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/e2e-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ jobs:
python-version: pypy-3.11-v7.x
- os: ubuntu-22.04-arm
python-version: pypy-3.11-v7.x
- os: ubuntu-22.04-arm
python-version: pypy-3.10-v7.x

steps:
- uses: actions/checkout@v4
- name: Setup Python
Expand Down
22 changes: 21 additions & 1 deletion __tests__/install-python.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,30 @@ import * as tc from '@actions/tool-cache';

jest.mock('@actions/http-client');
jest.mock('@actions/tool-cache');
jest.mock('@actions/tool-cache', () => ({
getManifestFromRepo: jest.fn()
}));

const mockManifest = [{version: '1.0.0'}];
const mockManifest = [
{
version: '1.0.0',
stable: true,
files: [
{
filename: 'tool-v1.0.0-linux-x64.tar.gz',
platform: 'linux',
arch: 'x64',
download_url: 'https://example.com/tool-v1.0.0-linux-x64.tar.gz'
}
]
}
];

describe('getManifest', () => {
beforeEach(() => {
jest.resetAllMocks();
});

it('should return manifest from repo', async () => {
(tc.getManifestFromRepo as jest.Mock).mockResolvedValue(mockManifest);
const manifest = await getManifest();
Expand Down
45 changes: 36 additions & 9 deletions dist/setup/index.js
10000
Original file line number Diff line number Diff line change
Expand Up @@ -97461,33 +97461,54 @@ function findReleaseFromManifest(semanticVersionSpec, architecture, manifest) {
});
}
exports.findReleaseFromManifest = findReleaseFromManifest;
function isIToolRelease(obj) {
return (typeof obj === 'object' &&
obj !== null &&
typeof obj.version === 'string' &&
typeof obj.stable === 'boolean' &&
Array.isArray(obj.files) &&
obj.files.every((file) => typeof file.filename === 'string' &&
typeof file.platform === 'string' &&
typeof file.arch === 'string' &&
typeof file.download_url === 'string'));
}
function getManifest() {
return __awaiter(this, void 0, void 0, function* () {
try {
return yield getManifestFromRepo();
const repoManifest = yield getManifestFromRepo();
if (Array.isArray(repoManifest) &&
repoManifest.length &&
repoManifest.every(isIToolRelease)) {
return repoManifest;
}
throw new Error('The repository manifest is invalid or does not include any valid tool release (IToolRelease) entries.');
}
catch (err) {
core.debug('Fetching the manifest via the API failed.');
core.error('Failed to fetch the manifest from the repository API.');
if (err instanceof Error) {
core.debug(err.message);
core.error(`Error message: ${err.message}`);
core.debug(`Error stack: ${err.stack}`);
}
else {
core.error('An unexpected error occurred while fetching the manifest.');
}
}
return yield getManifestFromURL();
});
}
exports.getManifest = getManifest;
function getManifestFromRepo() {
core.debug(`Getting manifest from ${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}@${MANIFEST_REPO_BRANCH}`);
core.info(`Getting manifest from ${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}@${MANIFEST_REPO_BRANCH}`);
return tc.getManifestFromRepo(MANIFEST_REPO_OWNER, MANIFEST_REPO_NAME, AUTH, MANIFEST_REPO_BRANCH);
}
exports.getManifestFromRepo = getManifestFromRepo;
function getManifestFromURL() {
return __awaiter(this, void 0, void 0, function* () {
core.debug('Falling back to fetching the manifest using raw URL.');
core.info('Falling back to fetching the manifest using raw URL.');
const http = new httpm.HttpClient('tool-cache');
const response = yield http.getJson(exports.MANIFEST_URL);
if (!response.result) {
throw new Error(`Unable to get manifest from ${exports.MANIFEST_URL}`);
throw new Error(`Unable to get manifest from ${exports.MANIFEST_URL}. HTTP status: ${response.statusCode}`);
}
return response.result;
});
Expand Down Expand Up @@ -97518,6 +97539,9 @@ function installPython(workingDirectory) {
}
function installCpythonFromRelease(release) {
return __awaiter(this, void 0, void 0, function* () {
if (!release.files || release.files.length === 0) {
throw new Error('No files found in the release to download.');
}
const downloadUrl = release.files[0].download_url;
core.info(`Download from "${downloadUrl}"`);
let pythonPath = '';
Expand All @@ -97538,11 +97562,14 @@ function installCpythonFromRelease(release) {
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`);
if (err.httpStatusCode === 403) {
core.error(`Received HTTP status code 403 (Forbidden). This usually indicates that the request is not authorized. Please check your credentials or permissions.`);
}
else if (err.httpStatusCode === 429) {
core.info(`Received HTTP status code 429 (Too Many Requests). This usually indicates that the rate limit has been exceeded. Please wait and try again later.`);
}
else {
core.info(err.message);
core.error(err.message);
}
if (err.stack) {
core.debug(err.stack);
Expand Down
58 changes: 49 additions & 9 deletions src/install-python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as exec from '@actions/exec';
import * as httpm from '@actions/http-client';
import {ExecOptions} from '@actions/exec/lib/interfaces';
import {IS_WINDOWS, IS_LINUX, getDownloadFileName} from './utils';
import {IToolRelease} from '@actions/tool-cache';

const TOKEN = core.getInput('token');
const AUTH = !TOKEN ? undefined : `token ${TOKEN}`;
Expand Down Expand Up @@ -32,20 +33,50 @@ export async function findReleaseFromManifest(
return foundRelease;
}

function isIToolRelease(obj: any): obj is IToolRelease {
return (
typeof obj === 'object' &&
obj !== null &&
typeof obj.version === 'string' &&
typeof obj.stable === 'boolean' &&
Array.isArray(obj.files) &&
obj.files.every(
(file: any) =>
typeof file.filename === 'string' &&
typeof file.platform === 'string' &&
typeof file.arch === 'string' &&
typeof file.download_url === 'string'
)
);
}

export async function getManifest(): Promise<tc.IToolRelease[]> {
try {
return await getManifestFromRepo();
const repoManifest = await getManifestFromRepo();
if (
Array.isArray(repoManifest) &&
repoManifest.length &&
repoManifest.every(isIToolRelease)
) {
return repoManifest;
}
throw new Error(
'The repository manifest is invalid or does not include any valid tool release (IToolRelease) entries.'
);
} catch (err) {
core.debug('Fetching the manifest via the API failed.');
core.error('Failed to fetch the manifest from the repository API.');
if (err instanceof Error) {
core.debug(err.message);
core.error(`Error message: ${err.message}`);
core.debug(`Error stack: ${err.stack}`);
} else {
core.error('An unexpected error occurred while fetching the manifest.');
}
}
return await getManifestFromURL();
}

export function getManifestFromRepo(): Promise<tc.IToolRelease[]> {
core.debug(
core.info(
`Getting manifest from ${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}@${MANIFEST_REPO_BRANCH}`
);
return tc.getManifestFromRepo(
Expand All @@ -57,12 +88,14 @@ export function getManifestFromRepo(): Promise<tc.IToolRelease[]> {
}

export async function getManifestFromURL(): Promise<tc.IToolRelease[]> {
core.debug('Falling back to fetching the manifest using raw URL.');
core.info('Falling back to fetching the manifest using raw URL.');

const http: httpm.HttpClient = new httpm.HttpClient('tool-cache');
const response = await http.getJson<tc.IToolRelease[]>(MANIFEST_URL);
if (!response.result) {
throw new Error(`Unable to get manifest from ${MANIFEST_URL}`);
throw new Error(
`Unable to get manifest from ${MANIFEST_URL}. HTTP status: ${response.statusCode}`
);
}
return response.result;
}
Expand Down Expand Up @@ -93,6 +126,9 @@ async function 9750 installPython(workingDirectory: string) {
}

export async function installCpythonFromRelease(release: tc.IToolRelease) {
if (!release.files || release.files.length === 0) {
throw new Error('No files found in the release to download.');
}
const downloadUrl = release.files[0].download_url;

core.info(`Download from "${downloadUrl}"`);
Expand All @@ -113,12 +149,16 @@ export async function installCpythonFromRelease(release: tc.IToolRelease) {
} catch (err) {
if (err instanceof tc.HTTPError) {
// Rate limit?
if (err.httpStatusCode === 403 || err.httpStatusCode === 429) {
if (err.httpStatusCode === 403) {
core.error(
`Received HTTP status code 403 (Forbidden). This usually indicates that the request is not authorized. Please check your credentials or permissions.`
);
} else if (err.httpStatusCode === 429) {
core.info(
`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`
`Received HTTP status code 429 (Too Many Requests). This usually indicates that the rate limit has been exceeded. Please wait and try again later.`
);
} else {
core.info(err.message);
core.error(err.message);
}
if (err.stack) {
core.debug(err.stack);
Expand Down
Loading
0