Compare commits

...

10 Commits

Author SHA1 Message Date
mahabaleshwars fd1585c47a
Merge ba50e5ed8e into 9c76e71650 2024-10-22 13:55:09 +05:45
aparnajyothi-y 9c76e71650
Bump pillow from 7.2 to 10.2.0 in /__tests__/data (#956)
* Update e2e-cache.yml

* Update basic-validation.yml

* Pyinstaller upgrade to 5.13.1

* pyinstaller-update

* Update basic-validation.yml

* Update e2e-cache.yml

* fix-db-alert-164-165-166

* upgrade pillow
2024-10-21 15:39:11 -05:00
John Wesley Walker III f4c5a1183d
Revise `isGhes` logic (#963)
* Revise `isGhes` logic

* ran `npm run format`

* add unit test

* ran `npm run format`
2024-10-21 11:42:17 -05:00
mahabaleshwars ba50e5ed8e removed some debugging 2024-09-25 17:31:29 +05:30
mahabaleshwars d148396753 final test commit 2024-09-25 14:32:22 +05:30
mahabaleshwars da830ea0e9 testing with different input 2024-09-24 15:56:55 +05:30
mahabaleshwars 658d90b402 testing for getting from url 2024-09-24 15:19:18 +05:30
mahabaleshwars 6aeae83a71 testing with conditions 2024-09-24 15:05:25 +05:30
mahabaleshwars 996d9604f2 updated error debugging 2024-09-23 16:20:29 +05:30
mahabaleshwars c4b81dc3e7 intial commit 2024-09-23 16:09:10 +05:30
6 changed files with 185 additions and 49 deletions

View File

@ -30,7 +30,7 @@ pdf2image==1.12.1
pefile==2021.9.3; python_full_version >= '3.6.0'
pillow==7.2
pillow>=10.2.0
pygments==2.6.1

View File

@ -9,7 +9,25 @@ 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.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 () => {

View File

@ -13,6 +13,7 @@ import {
getVersionInputFromPlainFile,
getVersionInputFromTomlFile,
getNextPageUrl,
isGhes,
IS_WINDOWS,
getDownloadFileName
} from '../src/utils';
@ -195,3 +196,41 @@ describe('getDownloadFileName', () => {
}
});
});
describe('isGhes', () => {
const pristineEnv = process.env;
beforeEach(() => {
jest.resetModules();
process.env = {...pristineEnv};
});
afterAll(() => {
process.env = pristineEnv;
});
it('returns false when the GITHUB_SERVER_URL environment variable is not defined', async () => {
delete process.env['GITHUB_SERVER_URL'];
expect(isGhes()).toBeFalsy();
});
it('returns false when the GITHUB_SERVER_URL environment variable is set to github.com', async () => {
process.env['GITHUB_SERVER_URL'] = 'https://github.com';
expect(isGhes()).toBeFalsy();
});
it('returns false when the GITHUB_SERVER_URL environment variable is set to a GitHub Enterprise Cloud-style URL', async () => {
process.env['GITHUB_SERVER_URL'] = 'https://contoso.ghe.com';
expect(isGhes()).toBeFalsy();
});
it('returns false when the GITHUB_SERVER_URL environment variable has a .localhost suffix', async () => {
process.env['GITHUB_SERVER_URL'] = 'https://mock-github.localhost';
expect(isGhes()).toBeFalsy();
});
it('returns true when the GITHUB_SERVER_URL environment variable is set to some other URL', async () => {
process.env['GITHUB_SERVER_URL'] = 'https://src.onpremise.fabrikam.com';
expect(isGhes()).toBeTruthy();
});
});

81
dist/setup/index.js vendored
View File

@ -91646,20 +91646,49 @@ exports.findReleaseFromManifest = findReleaseFromManifest;
function getManifest() {
return __awaiter(this, void 0, void 0, function* () {
try {
return yield getManifestFromRepo();
const manifestFromRepo = yield getManifestFromRepo();
core.info('Successfully fetched the manifest from the repo.');
validateManifest(manifestFromRepo);
return manifestFromRepo;
}
catch (err) {
core.debug('Fetching the manifest via the API failed.');
if (err instanceof Error) {
core.debug(err.message);
}
logError('Fetching the manifest via the API failed.', err);
}
try {
const manifestFromURL = yield getManifestFromURL();
core.info('Successfully fetched the manifest from the URL.');
return manifestFromURL;
}
catch (err) {
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.');
}
return yield getManifestFromURL();
});
}
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' &&
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.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;
@ -91690,34 +91719,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) {
@ -91730,11 +91754,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);
}
}
/***/ }),
@ -92017,7 +92046,11 @@ function validatePythonVersionFormatForPyPy(version) {
exports.validatePythonVersionFormatForPyPy = validatePythonVersionFormatForPyPy;
function isGhes() {
const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
const hostname = ghUrl.hostname.trimEnd().toUpperCase();
const isGitHubHost = hostname === 'GITHUB.COM';
const isGitHubEnterpriseCloudHost = hostname.endsWith('.GHE.COM');
const isLocalHost = hostname.endsWith('.LOCALHOST');
return !isGitHubHost && !isGitHubEnterpriseCloudHost && !isLocalHost;
}
exports.isGhes = isGhes;
function isCacheFeatureAvailable() {

View File

@ -28,24 +28,60 @@ export async function findReleaseFromManifest(
manifest,
architecture
);
return foundRelease;
}
export async function getManifest(): Promise<tc.IToolRelease[]> {
try {
return await getManifestFromRepo();
const manifestFromRepo = await getManifestFromRepo();
core.info('Successfully fetched the manifest from the repo.');
validateManifest(manifestFromRepo);
return manifestFromRepo;
} catch (err) {
core.debug('Fetching the manifest via the API failed.');
if (err instanceof Error) {
core.debug(err.message);
}
logError('Fetching the manifest via the API failed.', err);
}
return await getManifestFromURL();
try {
const manifestFromURL = await getManifestFromURL();
core.info('Successfully fetched the manifest from the URL.');
return manifestFromURL;
} catch (err) {
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.'
);
}
}
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' &&
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[]> {
core.debug(
core.info(
`Getting manifest from ${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}@${MANIFEST_REPO_BRANCH}`
);
return tc.getManifestFromRepo(
@ -85,32 +121,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) {
@ -124,6 +158,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);
}
}

View File

@ -116,7 +116,13 @@ export function isGhes(): boolean {
const ghUrl = new URL(
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
);
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
const hostname = ghUrl.hostname.trimEnd().toUpperCase();
const isGitHubHost = hostname === 'GITHUB.COM';
const isGitHubEnterpriseCloudHost = hostname.endsWith('.GHE.COM');
const isLocalHost = hostname.endsWith('.LOCALHOST');
return !isGitHubHost && !isGitHubEnterpriseCloudHost && !isLocalHost;
}
export function isCacheFeatureAvailable(): boolean {