mirror of
https://github.com/actions/setup-python.git
synced 2024-12-01 11:20:59 -05:00
testing with conditions
This commit is contained in:
parent
996d9604f2
commit
6aeae83a71
3 changed files with 76 additions and 9 deletions
|
@ -9,7 +9,7 @@ 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');
|
||||||
|
|
||||||
const mockManifest = [{version: '1.0.0'}];
|
const mockManifest = [{version: '3.12.0'}];
|
||||||
|
|
||||||
describe('getManifest', () => {
|
describe('getManifest', () => {
|
||||||
it('should return manifest from repo', async () => {
|
it('should return manifest from repo', async () => {
|
||||||
|
|
37
dist/setup/index.js
vendored
37
dist/setup/index.js
vendored
|
@ -91651,6 +91651,10 @@ function getManifest() {
|
||||||
const manifestFromRepo = yield getManifestFromRepo();
|
const manifestFromRepo = yield getManifestFromRepo();
|
||||||
core.info('Successfully fetched the manifest from the repo.');
|
core.info('Successfully fetched the manifest from the repo.');
|
||||||
core.info(`Manifest from repo: ${JSON.stringify(manifestFromRepo)}`);
|
core.info(`Manifest from repo: ${JSON.stringify(manifestFromRepo)}`);
|
||||||
|
if (!Array.isArray(manifestFromRepo) ||
|
||||||
|
!manifestFromRepo.every(isValidManifestEntry)) {
|
||||||
|
throw new Error('Invalid response');
|
||||||
|
}
|
||||||
return manifestFromRepo;
|
return manifestFromRepo;
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
|
@ -91659,13 +91663,38 @@ function getManifest() {
|
||||||
core.info(err.message);
|
core.info(err.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const manifestFromURL = yield getManifestFromURL();
|
try {
|
||||||
core.info('Successfully fetched the manifest from the URL.');
|
const manifestFromURL = yield getManifestFromURL();
|
||||||
core.info(`Manifest from URL: ${JSON.stringify(manifestFromURL)}`);
|
core.info('Successfully fetched the manifest from the URL.');
|
||||||
return manifestFromURL;
|
core.info(`Manifest from URL: ${JSON.stringify(manifestFromURL)}`);
|
||||||
|
return manifestFromURL;
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
core.info('Fetching the manifest from the URL failed.');
|
||||||
|
if (err instanceof Error) {
|
||||||
|
core.info(err.message);
|
||||||
|
}
|
||||||
|
// Rethrow the error or return a default value
|
||||||
|
throw new Error('Failed to fetch the manifest from both the repo and the URL.');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.getManifest = getManifest;
|
exports.getManifest = getManifest;
|
||||||
|
function isValidManifestEntry(entry) {
|
||||||
|
return (typeof entry.version === 'string' &&
|
||||||
|
typeof entry.stable === 'boolean' &&
|
||||||
|
typeof entry.release_url === 'string' &&
|
||||||
|
Array.isArray(entry.files) &&
|
||||||
|
entry.files.every(isValidFileEntry));
|
||||||
|
}
|
||||||
|
function isValidFileEntry(file) {
|
||||||
|
return (typeof file.filename === 'string' &&
|
||||||
|
typeof file.arch === 'string' &&
|
||||||
|
typeof file.platform === 'string' &&
|
||||||
|
(typeof file.platform_version === 'string' ||
|
||||||
|
file.platform_version === undefined) &&
|
||||||
|
typeof file.download_url === 'string');
|
||||||
|
}
|
||||||
function getManifestFromRepo() {
|
function getManifestFromRepo() {
|
||||||
core.info(`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);
|
return tc.getManifestFromRepo(MANIFEST_REPO_OWNER, MANIFEST_REPO_NAME, AUTH, MANIFEST_REPO_BRANCH);
|
||||||
|
|
|
@ -38,6 +38,12 @@ export async function getManifest(): Promise<tc.IToolRelease[]> {
|
||||||
const manifestFromRepo = await getManifestFromRepo();
|
const manifestFromRepo = await getManifestFromRepo();
|
||||||
core.info('Successfully fetched the manifest from the repo.');
|
core.info('Successfully fetched the manifest from the repo.');
|
||||||
core.info(`Manifest from repo: ${JSON.stringify(manifestFromRepo)}`);
|
core.info(`Manifest from repo: ${JSON.stringify(manifestFromRepo)}`);
|
||||||
|
if (
|
||||||
|
!Array.isArray(manifestFromRepo) ||
|
||||||
|
!manifestFromRepo.every(isValidManifestEntry)
|
||||||
|
) {
|
||||||
|
throw new Error('Invalid response');
|
||||||
|
}
|
||||||
return manifestFromRepo;
|
return manifestFromRepo;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
core.info('Fetching the manifest via the API failed.');
|
core.info('Fetching the manifest via the API failed.');
|
||||||
|
@ -45,10 +51,42 @@ export async function getManifest(): Promise<tc.IToolRelease[]> {
|
||||||
core.info(err.message);
|
core.info(err.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const manifestFromURL = await getManifestFromURL();
|
try {
|
||||||
core.info('Successfully fetched the manifest from the URL.');
|
const manifestFromURL = await getManifestFromURL();
|
||||||
core.info(`Manifest from URL: ${JSON.stringify(manifestFromURL)}`);
|
core.info('Successfully fetched the manifest from the URL.');
|
||||||
return manifestFromURL;
|
core.info(`Manifest from URL: ${JSON.stringify(manifestFromURL)}`);
|
||||||
|
return manifestFromURL;
|
||||||
|
} catch (err) {
|
||||||
|
core.info('Fetching the manifest from the URL failed.');
|
||||||
|
if (err instanceof Error) {
|
||||||
|
core.info(err.message);
|
||||||
|
}
|
||||||
|
// Rethrow the error or return a default value
|
||||||
|
throw new Error(
|
||||||
|
'Failed to fetch the manifest from both the repo and the URL.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function isValidManifestEntry(entry: any): boolean {
|
||||||
|
return (
|
||||||
|
typeof entry.version === 'string' &&
|
||||||
|
typeof entry.stable === 'boolean' &&
|
||||||
|
typeof entry.release_url === 'string' &&
|
||||||
|
Array.isArray(entry.files) &&
|
||||||
|
entry.files.every(isValidFileEntry)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isValidFileEntry(file: any): boolean {
|
||||||
|
return (
|
||||||
|
typeof file.filename === 'string' &&
|
||||||
|
typeof file.arch === 'string' &&
|
||||||
|
typeof file.platform === 'string' &&
|
||||||
|
(typeof file.platform_version === 'string' ||
|
||||||
|
file.platform_version === undefined) &&
|
||||||
|
typeof file.download_url === 'string'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getManifestFromRepo(): Promise<tc.IToolRelease[]> {
|
export function getManifestFromRepo(): Promise<tc.IToolRelease[]> {
|
||||||
|
|
Loading…
Reference in a new issue