mirror of
https://code.forgejo.org/actions/setup-python
synced 2025-03-15 06:36:56 +01:00
handled candidate not iterable error
This commit is contained in:
parent
6ca8e8598f
commit
7c16f92757
3 changed files with 87 additions and 5 deletions
|
@ -8,10 +8,30 @@ import * as tc from '@actions/tool-cache';
|
||||||
|
|
||||||
jest.mock('@actions/http-client');
|
jest.mock('@actions/http-client');
|
||||||
jest.mock('@actions/tool-cache');
|
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', () => {
|
describe('getManifest', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.resetAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
it('should return manifest from repo', async () => {
|
it('should return manifest from repo', async () => {
|
||||||
(tc.getManifestFromRepo as jest.Mock).mockResolvedValue(mockManifest);
|
(tc.getManifestFromRepo as jest.Mock).mockResolvedValue(mockManifest);
|
||||||
const manifest = await getManifest();
|
const manifest = await getManifest();
|
||||||
|
|
29
dist/setup/index.js
vendored
29
dist/setup/index.js
vendored
|
@ -100156,15 +100156,40 @@ function findReleaseFromManifest(semanticVersionSpec, architecture, manifest) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.findReleaseFromManifest = findReleaseFromManifest;
|
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() {
|
function getManifest() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
return yield getManifestFromRepo();
|
const repoManifest = yield getManifestFromRepo();
|
||||||
|
core.debug(`Received repo manifest: ${JSON.stringify(repoManifest)}`);
|
||||||
|
if (Array.isArray(repoManifest) &&
|
||||||
|
repoManifest.length &&
|
||||||
|
repoManifest.every(isIToolRelease)) {
|
||||||
|
core.debug('Repo manifest is valid and contains IToolRelease items.');
|
||||||
|
return repoManifest;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.debug('Repo manifest is invalid or does not contain IToolRelease items.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
core.debug('Fetching the manifest via the API failed.');
|
core.debug('Fetching the manifest via the API failed.');
|
||||||
if (err instanceof Error) {
|
if (err instanceof Error) {
|
||||||
core.debug(err.message);
|
core.debug(`Error message: ${err.message}`);
|
||||||
|
core.debug(`Error stack: ${err.stack}`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.debug('Error is not an instance of Error. It might be something else.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return yield getManifestFromURL();
|
return yield getManifestFromURL();
|
||||||
|
|
|
@ -5,6 +5,7 @@ import * as exec from '@actions/exec';
|
||||||
import * as httpm from '@actions/http-client';
|
import * as httpm from '@actions/http-client';
|
||||||
import {ExecOptions} from '@actions/exec/lib/interfaces';
|
import {ExecOptions} from '@actions/exec/lib/interfaces';
|
||||||
import {IS_WINDOWS, IS_LINUX, getDownloadFileName} from './utils';
|
import {IS_WINDOWS, IS_LINUX, getDownloadFileName} from './utils';
|
||||||
|
import {IToolRelease} from '@actions/tool-cache';
|
||||||
|
|
||||||
const TOKEN = core.getInput('token');
|
const TOKEN = core.getInput('token');
|
||||||
const AUTH = !TOKEN ? undefined : `token ${TOKEN}`;
|
const AUTH = !TOKEN ? undefined : `token ${TOKEN}`;
|
||||||
|
@ -32,13 +33,49 @@ export async function findReleaseFromManifest(
|
||||||
return foundRelease;
|
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[]> {
|
export async function getManifest(): Promise<tc.IToolRelease[]> {
|
||||||
try {
|
try {
|
||||||
return await getManifestFromRepo();
|
const repoManifest = await getManifestFromRepo();
|
||||||
|
core.debug(`Received repo manifest: ${JSON.stringify(repoManifest)}`);
|
||||||
|
|
||||||
|
if (
|
||||||
|
Array.isArray(repoManifest) &&
|
||||||
|
repoManifest.length &&
|
||||||
|
repoManifest.every(isIToolRelease)
|
||||||
|
) {
|
||||||
|
core.debug('Repo manifest is valid and contains IToolRelease items.');
|
||||||
|
return repoManifest;
|
||||||
|
} else {
|
||||||
|
core.debug(
|
||||||
|
'Repo manifest is invalid or does not contain IToolRelease items.'
|
||||||
|
);
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
core.debug('Fetching the manifest via the API failed.');
|
core.debug('Fetching the manifest via the API failed.');
|
||||||
if (err instanceof Error) {
|
if (err instanceof Error) {
|
||||||
core.debug(err.message);
|
core.debug(`Error message: ${err.message}`);
|
||||||
|
core.debug(`Error stack: ${err.stack}`);
|
||||||
|
} else {
|
||||||
|
core.debug(
|
||||||
|
'Error is not an instance of Error. It might be something else.'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return await getManifestFromURL();
|
return await getManifestFromURL();
|
||||||
|
|
Loading…
Add table
Reference in a new issue