From c4b81dc3e7daf6768ce106d2cd1c05ea1546bb65 Mon Sep 17 00:00:00 2001 From: mahabaleshwars <147705296+mahabaleshwars@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:09:10 +0530 Subject: [PATCH 1/7] intial commit --- dist/setup/index.js | 12 ++++++++++-- src/install-python.ts | 13 ++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 126f4a32..3b821247 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -91637,8 +91637,10 @@ function findReleaseFromManifest(semanticVersionSpec, architecture, manifest) { return __awaiter(this, void 0, void 0, function* () { if (!manifest) { manifest = yield getManifest(); + core.debug('manifest :>> ' + JSON.stringify(manifest)); } const foundRelease = yield tc.findFromManifest(semanticVersionSpec, false, manifest, architecture); + core.debug(`Found release: ${JSON.stringify(foundRelease)}`); return foundRelease; }); } @@ -91646,7 +91648,10 @@ exports.findReleaseFromManifest = findReleaseFromManifest; function getManifest() { return __awaiter(this, void 0, void 0, function* () { try { - return yield getManifestFromRepo(); + const manifestFromRepo = yield getManifestFromRepo(); + core.debug('Successfully fetched the manifest from the repo.'); + core.debug(`Manifest from repo: ${JSON.stringify(manifestFromRepo)}`); + return manifestFromRepo; } catch (err) { core.debug('Fetching the manifest via the API failed.'); @@ -91654,7 +91659,10 @@ function getManifest() { core.debug(err.message); } } - return yield getManifestFromURL(); + const manifestFromURL = yield getManifestFromURL(); + core.debug('Successfully fetched the manifest from the URL.'); + core.debug(`Manifest from URL: ${JSON.stringify(manifestFromURL)}`); + return manifestFromURL; }); } exports.getManifest = getManifest; diff --git a/src/install-python.ts b/src/install-python.ts index d3421bf8..550ae28c 100644 --- a/src/install-python.ts +++ b/src/install-python.ts @@ -20,6 +20,7 @@ export async function findReleaseFromManifest( ): Promise { if (!manifest) { manifest = await getManifest(); + core.debug('manifest :>> ' + JSON.stringify(manifest)); } const foundRelease = await tc.findFromManifest( @@ -28,20 +29,26 @@ export async function findReleaseFromManifest( manifest, architecture ); - + core.debug(`Found release: ${JSON.stringify(foundRelease)}`); return foundRelease; } export async function getManifest(): Promise { try { - return await getManifestFromRepo(); + const manifestFromRepo = await getManifestFromRepo(); + core.debug('Successfully fetched the manifest from the repo.'); + core.debug(`Manifest from repo: ${JSON.stringify(manifestFromRepo)}`); + return manifestFromRepo; } catch (err) { core.debug('Fetching the manifest via the API failed.'); if (err instanceof Error) { core.debug(err.message); } } - return await getManifestFromURL(); + const manifestFromURL = await getManifestFromURL(); + core.debug('Successfully fetched the manifest from the URL.'); + core.debug(`Manifest from URL: ${JSON.stringify(manifestFromURL)}`); + return manifestFromURL; } export function getManifestFromRepo(): Promise { From 996d9604f26c11e8dc594b6747ee8b4828413637 Mon Sep 17 00:00:00 2001 From: mahabaleshwars <147705296+mahabaleshwars@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:20:29 +0530 Subject: [PATCH 2/7] updated error debugging --- dist/setup/index.js | 18 +++++++++--------- src/install-python.ts | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 3b821247..52db022a 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -91637,10 +91637,10 @@ function findReleaseFromManifest(semanticVersionSpec, architecture, manifest) { return __awaiter(this, void 0, void 0, function* () { if (!manifest) { manifest = yield getManifest(); - core.debug('manifest :>> ' + JSON.stringify(manifest)); + core.info('manifest :>> ' + JSON.stringify(manifest)); } const foundRelease = yield tc.findFromManifest(semanticVersionSpec, false, manifest, architecture); - core.debug(`Found release: ${JSON.stringify(foundRelease)}`); + core.info(`Found release: ${JSON.stringify(foundRelease)}`); return foundRelease; }); } @@ -91649,25 +91649,25 @@ function getManifest() { return __awaiter(this, void 0, void 0, function* () { try { const manifestFromRepo = yield getManifestFromRepo(); - core.debug('Successfully fetched the manifest from the repo.'); - core.debug(`Manifest from repo: ${JSON.stringify(manifestFromRepo)}`); + core.info('Successfully fetched the manifest from the repo.'); + core.info(`Manifest from repo: ${JSON.stringify(manifestFromRepo)}`); return manifestFromRepo; } catch (err) { - core.debug('Fetching the manifest via the API failed.'); + core.info('Fetching the manifest via the API failed.'); if (err instanceof Error) { - core.debug(err.message); + core.info(err.message); } } const manifestFromURL = yield getManifestFromURL(); - core.debug('Successfully fetched the manifest from the URL.'); - core.debug(`Manifest from URL: ${JSON.stringify(manifestFromURL)}`); + core.info('Successfully fetched the manifest from the URL.'); + core.info(`Manifest from URL: ${JSON.stringify(manifestFromURL)}`); return manifestFromURL; }); } 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; diff --git a/src/install-python.ts b/src/install-python.ts index 550ae28c..9b1ef24a 100644 --- a/src/install-python.ts +++ b/src/install-python.ts @@ -20,7 +20,7 @@ export async function findReleaseFromManifest( ): Promise { if (!manifest) { manifest = await getManifest(); - core.debug('manifest :>> ' + JSON.stringify(manifest)); + core.info('manifest :>> ' + JSON.stringify(manifest)); } const foundRelease = await tc.findFromManifest( @@ -29,30 +29,30 @@ export async function findReleaseFromManifest( manifest, architecture ); - core.debug(`Found release: ${JSON.stringify(foundRelease)}`); + core.info(`Found release: ${JSON.stringify(foundRelease)}`); return foundRelease; } export async function getManifest(): Promise { try { const manifestFromRepo = await getManifestFromRepo(); - core.debug('Successfully fetched the manifest from the repo.'); - core.debug(`Manifest from repo: ${JSON.stringify(manifestFromRepo)}`); + core.info('Successfully fetched the manifest from the repo.'); + core.info(`Manifest from repo: ${JSON.stringify(manifestFromRepo)}`); return manifestFromRepo; } catch (err) { - core.debug('Fetching the manifest via the API failed.'); + core.info('Fetching the manifest via the API failed.'); if (err instanceof Error) { - core.debug(err.message); + core.info(err.message); } } const manifestFromURL = await getManifestFromURL(); - core.debug('Successfully fetched the manifest from the URL.'); - core.debug(`Manifest from URL: ${JSON.stringify(manifestFromURL)}`); + core.info('Successfully fetched the manifest from the URL.'); + core.info(`Manifest from URL: ${JSON.stringify(manifestFromURL)}`); return manifestFromURL; } export function getManifestFromRepo(): Promise { - core.debug( + core.info( `Getting manifest from ${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}@${MANIFEST_REPO_BRANCH}` ); return tc.getManifestFromRepo( From 6aeae83a713db206e155395aa1283263da15c210 Mon Sep 17 00:00:00 2001 From: mahabaleshwars <147705296+mahabaleshwars@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:05:25 +0530 Subject: [PATCH 3/7] testing with conditions --- __tests__/install-python.test.ts | 2 +- dist/setup/index.js | 37 ++++++++++++++++++++++--- src/install-python.ts | 46 +++++++++++++++++++++++++++++--- 3 files changed, 76 insertions(+), 9 deletions(-) diff --git a/__tests__/install-python.test.ts b/__tests__/install-python.test.ts index c3a6e7b4..8763aed5 100644 --- a/__tests__/install-python.test.ts +++ b/__tests__/install-python.test.ts @@ -9,7 +9,7 @@ import * as tc from '@actions/tool-cache'; jest.mock('@actions/http-client'); jest.mock('@actions/tool-cache'); -const mockManifest = [{version: '1.0.0'}]; +const mockManifest = [{version: '3.12.0'}]; describe('getManifest', () => { it('should return manifest from repo', async () => { diff --git a/dist/setup/index.js b/dist/setup/index.js index 52db022a..8afafd18 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -91651,6 +91651,10 @@ function getManifest() { const manifestFromRepo = yield getManifestFromRepo(); core.info('Successfully fetched the manifest from the repo.'); core.info(`Manifest from repo: ${JSON.stringify(manifestFromRepo)}`); + if (!Array.isArray(manifestFromRepo) || + !manifestFromRepo.every(isValidManifestEntry)) { + throw new Error('Invalid response'); + } return manifestFromRepo; } catch (err) { @@ -91659,13 +91663,38 @@ function getManifest() { core.info(err.message); } } - const manifestFromURL = yield getManifestFromURL(); - core.info('Successfully fetched the manifest from the URL.'); - core.info(`Manifest from URL: ${JSON.stringify(manifestFromURL)}`); - return manifestFromURL; + try { + const manifestFromURL = yield getManifestFromURL(); + core.info('Successfully fetched the manifest from the URL.'); + 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; +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() { 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); diff --git a/src/install-python.ts b/src/install-python.ts index 9b1ef24a..20767567 100644 --- a/src/install-python.ts +++ b/src/install-python.ts @@ -38,6 +38,12 @@ export async function getManifest(): Promise { const manifestFromRepo = await getManifestFromRepo(); core.info('Successfully fetched the manifest from the repo.'); core.info(`Manifest from repo: ${JSON.stringify(manifestFromRepo)}`); + if ( + !Array.isArray(manifestFromRepo) || + !manifestFromRepo.every(isValidManifestEntry) + ) { + throw new Error('Invalid response'); + } return manifestFromRepo; } catch (err) { core.info('Fetching the manifest via the API failed.'); @@ -45,10 +51,42 @@ export async function getManifest(): Promise { core.info(err.message); } } - const manifestFromURL = await getManifestFromURL(); - core.info('Successfully fetched the manifest from the URL.'); - core.info(`Manifest from URL: ${JSON.stringify(manifestFromURL)}`); - return manifestFromURL; + try { + const manifestFromURL = await getManifestFromURL(); + core.info('Successfully fetched the manifest from the URL.'); + 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 { From 658d90b402bcd1155816ad8364ba2595f9b62e57 Mon Sep 17 00:00:00 2001 From: mahabaleshwars <147705296+mahabaleshwars@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:19:18 +0530 Subject: [PATCH 4/7] testing for getting from url --- dist/setup/index.js | 6 +++--- src/install-python.ts | 8 +++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 8afafd18..d3ff39f9 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -91648,11 +91648,11 @@ exports.findReleaseFromManifest = findReleaseFromManifest; function getManifest() { return __awaiter(this, void 0, void 0, function* () { try { - const manifestFromRepo = yield getManifestFromRepo(); + // const manifestFromRepo = await getManifestFromRepo(); + const manifestFromRepo = null; core.info('Successfully fetched the manifest from the repo.'); core.info(`Manifest from repo: ${JSON.stringify(manifestFromRepo)}`); - if (!Array.isArray(manifestFromRepo) || - !manifestFromRepo.every(isValidManifestEntry)) { + if (!Array.isArray(manifestFromRepo)) { throw new Error('Invalid response'); } return manifestFromRepo; diff --git a/src/install-python.ts b/src/install-python.ts index 20767567..95d66cd7 100644 --- a/src/install-python.ts +++ b/src/install-python.ts @@ -35,13 +35,11 @@ export async function findReleaseFromManifest( export async function getManifest(): Promise { try { - const manifestFromRepo = await getManifestFromRepo(); + // const manifestFromRepo = await getManifestFromRepo(); + const manifestFromRepo = null; core.info('Successfully fetched the manifest from the repo.'); core.info(`Manifest from repo: ${JSON.stringify(manifestFromRepo)}`); - if ( - !Array.isArray(manifestFromRepo) || - !manifestFromRepo.every(isValidManifestEntry) - ) { + if (!Array.isArray(manifestFromRepo)) { throw new Error('Invalid response'); } return manifestFromRepo; From da830ea0e9dae2e0018f46782e46ab333775f0cf Mon Sep 17 00:00:00 2001 From: mahabaleshwars <147705296+mahabaleshwars@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:56:55 +0530 Subject: [PATCH 5/7] testing with different input --- dist/setup/index.js | 14 +++++++++++--- src/install-python.ts | 17 ++++++++++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index d3ff39f9..bf91b555 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -91648,11 +91648,19 @@ exports.findReleaseFromManifest = findReleaseFromManifest; function getManifest() { return __awaiter(this, void 0, void 0, function* () { try { - // const manifestFromRepo = await getManifestFromRepo(); - const manifestFromRepo = null; + //const manifestFromRepo = await getManifestFromRepo(); + const manifestFromRepo = { + sha: '5418fd77743bd877e972056787b3ee67a5725566', + node_id: 'MDQ6QmxvYjI1MDA3NzkzMzo1NDE4ZmQ3Nzc0M2JkODc3ZTk3MjA1Njc4N2IzZWU2N2E1NzI1NTY2', + size: 296984, + url: 'https://api.github.com/repos/actions/python-versions/git/blobs/5418fd77743bd877e972056787b3ee67a5725566', + content: 'fasfWfasdkjnflaknc@fakjsdhfjlakjlkfj', + encoding: 'base64' + }; core.info('Successfully fetched the manifest from the repo.'); core.info(`Manifest from repo: ${JSON.stringify(manifestFromRepo)}`); - if (!Array.isArray(manifestFromRepo)) { + if (!Array.isArray(manifestFromRepo) || + !manifestFromRepo.every(isValidManifestEntry)) { throw new Error('Invalid response'); } return manifestFromRepo; diff --git a/src/install-python.ts b/src/install-python.ts index 95d66cd7..43d7c664 100644 --- a/src/install-python.ts +++ b/src/install-python.ts @@ -35,11 +35,22 @@ export async function findReleaseFromManifest( export async function getManifest(): Promise { try { - // const manifestFromRepo = await getManifestFromRepo(); - const manifestFromRepo = null; + //const manifestFromRepo = await getManifestFromRepo(); + const manifestFromRepo = { + sha: '5418fd77743bd877e972056787b3ee67a5725566', + node_id: + 'MDQ6QmxvYjI1MDA3NzkzMzo1NDE4ZmQ3Nzc0M2JkODc3ZTk3MjA1Njc4N2IzZWU2N2E1NzI1NTY2', + size: 296984, + url: 'https://api.github.com/repos/actions/python-versions/git/blobs/5418fd77743bd877e972056787b3ee67a5725566', + content: 'fasfWfasdkjnflaknc@fakjsdhfjlakjlkfj', + encoding: 'base64' + }; core.info('Successfully fetched the manifest from the repo.'); core.info(`Manifest from repo: ${JSON.stringify(manifestFromRepo)}`); - if (!Array.isArray(manifestFromRepo)) { + if ( + !Array.isArray(manifestFromRepo) || + !manifestFromRepo.every(isValidManifestEntry) + ) { throw new Error('Invalid response'); } return manifestFromRepo; From d14839675354c38a6da5d6a50aac18cbf8755827 Mon Sep 17 00:00:00 2001 From: mahabaleshwars <147705296+mahabaleshwars@users.noreply.github.com> Date: Wed, 25 Sep 2024 14:32:22 +0530 Subject: [PATCH 6/7] final test commit --- __tests__/install-python.test.ts | 20 +++++++++- dist/setup/index.js | 63 ++++++++++++------------------ src/install-python.ts | 67 +++++++++++++------------------- 3 files changed, 72 insertions(+), 78 deletions(-) diff --git a/__tests__/install-python.test.ts b/__tests__/install-python.test.ts index 8763aed5..70a109ac 100644 --- a/__tests__/install-python.test.ts +++ b/__tests__/install-python.test.ts @@ -9,7 +9,25 @@ import * as tc from '@actions/tool-cache'; jest.mock('@actions/http-client'); jest.mock('@actions/tool-cache'); -const mockManifest = [{version: '3.12.0'}]; +const mockManifest = [ + { + version: '3.9.0', + stable: true, + release_url: 'https://example.com/release-url', + files: [ + { + filename: 'python-3.9.0-macosx10.9.pkg', + arch: 'x64', + platform: 'darwin', + download_url: 'https://example.com/download-url' + } + ] + } +]; + +beforeEach(() => { + jest.resetAllMocks(); +}); describe('getManifest', () => { it('should return manifest from repo', async () => { diff --git a/dist/setup/index.js b/dist/setup/index.js index bf91b555..4ec6e453 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -91637,7 +91637,6 @@ function findReleaseFromManifest(semanticVersionSpec, architecture, manifest) { return __awaiter(this, void 0, void 0, function* () { if (!manifest) { manifest = yield getManifest(); - core.info('manifest :>> ' + JSON.stringify(manifest)); } const foundRelease = yield tc.findFromManifest(semanticVersionSpec, false, manifest, architecture); core.info(`Found release: ${JSON.stringify(foundRelease)}`); @@ -91648,28 +91647,14 @@ exports.findReleaseFromManifest = findReleaseFromManifest; function getManifest() { return __awaiter(this, void 0, void 0, function* () { try { - //const manifestFromRepo = await getManifestFromRepo(); - const manifestFromRepo = { - sha: '5418fd77743bd877e972056787b3ee67a5725566', - node_id: 'MDQ6QmxvYjI1MDA3NzkzMzo1NDE4ZmQ3Nzc0M2JkODc3ZTk3MjA1Njc4N2IzZWU2N2E1NzI1NTY2', - size: 296984, - url: 'https://api.github.com/repos/actions/python-versions/git/blobs/5418fd77743bd877e972056787b3ee67a5725566', - content: 'fasfWfasdkjnflaknc@fakjsdhfjlakjlkfj', - encoding: 'base64' - }; + const manifestFromRepo = yield getManifestFromRepo(); core.info('Successfully fetched the manifest from the repo.'); core.info(`Manifest from repo: ${JSON.stringify(manifestFromRepo)}`); - if (!Array.isArray(manifestFromRepo) || - !manifestFromRepo.every(isValidManifestEntry)) { - throw new Error('Invalid response'); - } + validateManifest(manifestFromRepo); return manifestFromRepo; } catch (err) { - core.info('Fetching the manifest via the API failed.'); - if (err instanceof Error) { - core.info(err.message); - } + logError('Fetching the manifest via the API failed.', err); } try { const manifestFromURL = yield getManifestFromURL(); @@ -91678,16 +91663,18 @@ function getManifest() { return manifestFromURL; } catch (err) { - core.info('Fetching the manifest from the URL failed.'); - if (err instanceof Error) { - core.info(err.message); - } + logError('Fetching the manifest via the URL failed.', err); // 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; +function validateManifest(manifest) { + if (!Array.isArray(manifest) || !manifest.every(isValidManifestEntry)) { + throw new Error('Invalid manifest response'); + } +} function isValidManifestEntry(entry) { return (typeof entry.version === 'string' && typeof entry.stable === 'boolean' && @@ -91735,34 +91722,29 @@ function installPython(workingDirectory) { } } }; - if (utils_1.IS_WINDOWS) { - yield exec.exec('powershell', ['./setup.ps1'], options); - } - else { - yield exec.exec('bash', ['./setup.sh'], options); - } + const script = utils_1.IS_WINDOWS ? 'powershell ./setup.ps1' : 'bash ./setup.sh'; + yield exec.exec(script, [], options); }); } function installCpythonFromRelease(release) { return __awaiter(this, void 0, void 0, function* () { const downloadUrl = release.files[0].download_url; core.info(`Download from "${downloadUrl}"`); - let pythonPath = ''; try { const fileName = (0, utils_1.getDownloadFileName)(downloadUrl); - pythonPath = yield tc.downloadTool(downloadUrl, fileName, AUTH); + const pythonPath = yield tc.downloadTool(downloadUrl, fileName, AUTH); core.info('Extract downloaded archive'); - let pythonExtractedFolder; - if (utils_1.IS_WINDOWS) { - pythonExtractedFolder = yield tc.extractZip(pythonPath); - } - else { - pythonExtractedFolder = yield tc.extractTar(pythonPath); - } + const pythonExtractedFolder = utils_1.IS_WINDOWS + ? yield tc.extractZip(pythonPath) + : yield tc.extractTar(pythonPath); core.info('Execute installation script'); yield installPython(pythonExtractedFolder); } catch (err) { + handleDownloadError(err); + throw err; + } + function handleDownloadError(err) { if (err instanceof tc.HTTPError) { // Rate limit? if (err.httpStatusCode === 403 || err.httpStatusCode === 429) { @@ -91775,11 +91757,16 @@ function installCpythonFromRelease(release) { core.debug(err.stack); } } - throw err; } }); } exports.installCpythonFromRelease = installCpythonFromRelease; +function logError(message, err) { + core.info(message); + if (err instanceof Error) { + core.info(err.message); + } +} /***/ }), diff --git a/src/install-python.ts b/src/install-python.ts index 43d7c664..ff8493dd 100644 --- a/src/install-python.ts +++ b/src/install-python.ts @@ -20,7 +20,6 @@ export async function findReleaseFromManifest( ): Promise { if (!manifest) { manifest = await getManifest(); - core.info('manifest :>> ' + JSON.stringify(manifest)); } const foundRelease = await tc.findFromManifest( @@ -35,30 +34,13 @@ export async function findReleaseFromManifest( export async function getManifest(): Promise { try { - //const manifestFromRepo = await getManifestFromRepo(); - const manifestFromRepo = { - sha: '5418fd77743bd877e972056787b3ee67a5725566', - node_id: - 'MDQ6QmxvYjI1MDA3NzkzMzo1NDE4ZmQ3Nzc0M2JkODc3ZTk3MjA1Njc4N2IzZWU2N2E1NzI1NTY2', - size: 296984, - url: 'https://api.github.com/repos/actions/python-versions/git/blobs/5418fd77743bd877e972056787b3ee67a5725566', - content: 'fasfWfasdkjnflaknc@fakjsdhfjlakjlkfj', - encoding: 'base64' - }; + const manifestFromRepo = await getManifestFromRepo(); core.info('Successfully fetched the manifest from the repo.'); core.info(`Manifest from repo: ${JSON.stringify(manifestFromRepo)}`); - if ( - !Array.isArray(manifestFromRepo) || - !manifestFromRepo.every(isValidManifestEntry) - ) { - throw new Error('Invalid response'); - } + validateManifest(manifestFromRepo); return manifestFromRepo; } catch (err) { - core.info('Fetching the manifest via the API failed.'); - if (err instanceof Error) { - core.info(err.message); - } + logError('Fetching the manifest via the API failed.', err); } try { const manifestFromURL = await getManifestFromURL(); @@ -66,10 +48,7 @@ export async function getManifest(): Promise { 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); - } + logError('Fetching the manifest via the URL failed.', err); // Rethrow the error or return a default value throw new Error( 'Failed to fetch the manifest from both the repo and the URL.' @@ -77,6 +56,12 @@ export async function getManifest(): Promise { } } +function validateManifest(manifest: any): void { + if (!Array.isArray(manifest) || !manifest.every(isValidManifestEntry)) { + throw new Error('Invalid manifest response'); + } +} + function isValidManifestEntry(entry: any): boolean { return ( typeof entry.version === 'string' && @@ -139,32 +124,30 @@ async function installPython(workingDirectory: string) { } }; - if (IS_WINDOWS) { - await exec.exec('powershell', ['./setup.ps1'], options); - } else { - await exec.exec('bash', ['./setup.sh'], options); - } + const script = IS_WINDOWS ? 'powershell ./setup.ps1' : 'bash ./setup.sh'; + await exec.exec(script, [], options); } export async function installCpythonFromRelease(release: tc.IToolRelease) { const downloadUrl = release.files[0].download_url; core.info(`Download from "${downloadUrl}"`); - let pythonPath = ''; try { const fileName = getDownloadFileName(downloadUrl); - pythonPath = await tc.downloadTool(downloadUrl, fileName, AUTH); + const pythonPath = await tc.downloadTool(downloadUrl, fileName, AUTH); core.info('Extract downloaded archive'); - let pythonExtractedFolder; - if (IS_WINDOWS) { - pythonExtractedFolder = await tc.extractZip(pythonPath); - } else { - pythonExtractedFolder = await tc.extractTar(pythonPath); - } + const pythonExtractedFolder = IS_WINDOWS + ? await tc.extractZip(pythonPath) + : await tc.extractTar(pythonPath); core.info('Execute installation script'); await installPython(pythonExtractedFolder); } catch (err) { + handleDownloadError(err); + throw err; + } + + function handleDownloadError(err: any): void { if (err instanceof tc.HTTPError) { // Rate limit? if (err.httpStatusCode === 403 || err.httpStatusCode === 429) { @@ -178,6 +161,12 @@ export async function installCpythonFromRelease(release: tc.IToolRelease) { core.debug(err.stack); } } - throw err; + } +} + +function logError(message: string, err: any): void { + core.info(message); + if (err instanceof Error) { + core.info(err.message); } } From ba50e5ed8e378cb404d8e353781670475936689f Mon Sep 17 00:00:00 2001 From: mahabaleshwars <147705296+mahabaleshwars@users.noreply.github.com> Date: Wed, 25 Sep 2024 17:31:29 +0530 Subject: [PATCH 7/7] removed some debugging --- dist/setup/index.js | 3 --- src/install-python.ts | 3 --- 2 files changed, 6 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 4ec6e453..35524b27 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -91639,7 +91639,6 @@ function findReleaseFromManifest(semanticVersionSpec, architecture, manifest) { manifest = yield getManifest(); } const foundRelease = yield tc.findFromManifest(semanticVersionSpec, false, manifest, architecture); - core.info(`Found release: ${JSON.stringify(foundRelease)}`); return foundRelease; }); } @@ -91649,7 +91648,6 @@ function getManifest() { try { const manifestFromRepo = yield getManifestFromRepo(); core.info('Successfully fetched the manifest from the repo.'); - core.info(`Manifest from repo: ${JSON.stringify(manifestFromRepo)}`); validateManifest(manifestFromRepo); return manifestFromRepo; } @@ -91659,7 +91657,6 @@ function getManifest() { try { const manifestFromURL = yield getManifestFromURL(); core.info('Successfully fetched the manifest from the URL.'); - core.info(`Manifest from URL: ${JSON.stringify(manifestFromURL)}`); return manifestFromURL; } catch (err) { diff --git a/src/install-python.ts b/src/install-python.ts index ff8493dd..c40604f8 100644 --- a/src/install-python.ts +++ b/src/install-python.ts @@ -28,7 +28,6 @@ export async function findReleaseFromManifest( manifest, architecture ); - core.info(`Found release: ${JSON.stringify(foundRelease)}`); return foundRelease; } @@ -36,7 +35,6 @@ export async function getManifest(): Promise { try { const manifestFromRepo = await getManifestFromRepo(); core.info('Successfully fetched the manifest from the repo.'); - core.info(`Manifest from repo: ${JSON.stringify(manifestFromRepo)}`); validateManifest(manifestFromRepo); return manifestFromRepo; } catch (err) { @@ -45,7 +43,6 @@ export async function getManifest(): Promise { try { const manifestFromURL = await getManifestFromURL(); core.info('Successfully fetched the manifest from the URL.'); - core.info(`Manifest from URL: ${JSON.stringify(manifestFromURL)}`); return manifestFromURL; } catch (err) { logError('Fetching the manifest via the URL failed.', err);